[PATCH v4 0/3] tools/accounting: refactor delay fields and share format_timespec()

wang.yaxin@zte.com.cn posted 3 patches 14 hours ago
tools/accounting/Makefile             |  12 +-
tools/accounting/delaytop.c           | 265 ++++++++++----------------
tools/accounting/format_timespec.c    |  37 ++++
tools/accounting/format_timespec.h    |   9 +
tools/accounting/getdelays.c          |  36 +---
tools/include/uapi/linux/time_types.h |  51 +++++
6 files changed, 210 insertions(+), 200 deletions(-)
create mode 100644 tools/accounting/format_timespec.c
create mode 100644 tools/accounting/format_timespec.h
create mode 100644 tools/include/uapi/linux/time_types.h
[PATCH v4 0/3] tools/accounting: refactor delay fields and share format_timespec()
Posted by wang.yaxin@zte.com.cn 14 hours ago
From: Wang Yaxin <wang.yaxin@zte.com.cn>

- Convert per-field delay members in struct task_info to an array indexed
  by enum delay_type, eliminating offsetof() pointer arithmetic.

- Factor out a common format_timespec() implementation shared by getdelays
  and delaytop, using strftime for cleaner timestamp formatting.

- Replace the complex sizeof/ULL/shift Y2038 guard with a direct narrowing
  truncation check ((long long)time_sec != ts->tv_sec).

Change Log
==========
v3->v4:
update patch 2/3 and 3/3 according to the suggestion:
https://sashiko.dev/#/patchset/20260718133420538UvsJFurowueTqxAaZ1cRP@zte.com.cn

1. add #ifndef __kernel_old_timeval guard to
tools/include/uapi/linux/time_types.h to match the kernel header and avoid
redefinition on sparc64.
2. update commit message to document the nla_len < NLA_HDRLEN sanity checks
added to netlink attribute parsing in getdelays.c and delaytop.c.


v2->v3:
update patch 2/3 and 3/3 according to the suggestion:
https://sashiko.dev/#/patchset/20260715124740929HC7tDDb2SK3kRxbuPruHd@zte.com.cn

1. tools/include/uapi/linux/time_types.h: use __kernel_long_t instead of
long to fix ABI mismatch on x32
2. tools/accounting: add nla_len < NLA_HDRLEN checks in netlink attribute
parsing loops to prevent infinite loop on malformed messages

v1->v2:
Only update patch 2/3 according to the suggestion:
https://sashiko.dev/#/patchset/20260711173112482SCQEM08VED2PT1pxUYOXk@zte.com.cn

1. tools/include/uapi/linux/time_types.h: expand stub to full set of
  6 structs from kernel UAPI to avoid shadowing system header
2. tools/accounting/Makefile: add $(LDFLAGS), $(LDLIBS), $(CPPFLAGS)
  to restore compatibility with standard build variables

Wang Yaxin (3):
  delaytop: refactor repetitive delay fields into array with enum
  tools/accounting: factor out shared format_timespec() implementation
  tools/accounting: simplify 32-bit time_t overflow check in
    format_timespec()

 tools/accounting/Makefile             |  12 +-
 tools/accounting/delaytop.c           | 265 ++++++++++----------------
 tools/accounting/format_timespec.c    |  37 ++++
 tools/accounting/format_timespec.h    |   9 +
 tools/accounting/getdelays.c          |  36 +---
 tools/include/uapi/linux/time_types.h |  51 +++++
 6 files changed, 210 insertions(+), 200 deletions(-)
 create mode 100644 tools/accounting/format_timespec.c
 create mode 100644 tools/accounting/format_timespec.h
 create mode 100644 tools/include/uapi/linux/time_types.h

-- 
2.27.0