From eafcf6c1bad495fa552915ae2c8087629dbf9fad Mon Sep 17 00:00:00 2001 From: SuperSix173 Date: Tue, 25 Jun 2024 21:50:43 +0800 Subject: [PATCH] top: adapt to guest/total tics chage, api Signed-off-by: SuperSix173 (cherry picked from commit 8e4f72ea351cccd3bc26e54bc5d1c0fc1a42890a) --- ...ent-guest-total-tics-change-stat-api.patch | 75 ++++++++++++++++++ ...hat-guest-total-tics-change-stat-api.patch | 78 +++++++++++++++++++ procps-ng.spec | 7 +- 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 backport-library-implement-guest-total-tics-change-stat-api.patch create mode 100644 backport-top-adapt-to-that-guest-total-tics-change-stat-api.patch diff --git a/backport-library-implement-guest-total-tics-change-stat-api.patch b/backport-library-implement-guest-total-tics-change-stat-api.patch new file mode 100644 index 0000000..af4b8d9 --- /dev/null +++ b/backport-library-implement-guest-total-tics-change-stat-api.patch @@ -0,0 +1,75 @@ +From e1df029e6c8bb166a6cec05dc12f699d84631bc9 Mon Sep 17 00:00:00 2001 +From: Jim Warner +Date: Sat, 22 Jun 2024 00:00:00 -0500 +Subject: [PATCH 1/3] library: implement guest/total tics change, api + +This patch removes guest tics from the total lest they +be counted twice. Such tics have already been included +in user/nice values. For proof, just follow this path: + + fs/proc/stat.c: show_stat() ---> + kernel/sched/cputime.c: kcpustat_cpu_fetch() + +Reference(s): +https://gitlab.com/procps-ng/procps/-/issues/339 + +. Sep, 2020 - where guest distortion occurred +commit ec21588be108d092804eb72edbba2ba214bc6190 + +Signed-off-by: Jim Warner +--- + library/include/stat.h | 6 +++--- + library/stat.c | 12 ++++++++---- + 2 files changed, 11 insertions(+), 7 deletions(-) + +diff --git a/library/include/stat.h b/library/include/stat.h +index ff7c5b17..d8ca2add 100644 +--- a/library/include/stat.h ++++ b/library/include/stat.h +@@ -45,8 +45,8 @@ enum stat_item { + STAT_TIC_IRQ, // ull_int " + STAT_TIC_SOFTIRQ, // ull_int " + STAT_TIC_STOLEN, // ull_int " +- STAT_TIC_GUEST, // ull_int " +- STAT_TIC_GUEST_NICE, // ull_int " ++ STAT_TIC_GUEST, // ull_int " (note: also included in USER) ++ STAT_TIC_GUEST_NICE, // ull_int " (note: also included in NICE) + + STAT_TIC_DELTA_USER, // sl_int derived from above + STAT_TIC_DELTA_NICE, // sl_int " +@@ -63,7 +63,7 @@ enum stat_item { + STAT_TIC_SUM_SYSTEM, // ull_int derived from SYSTEM + IRQ + SOFTIRQ tics + STAT_TIC_SUM_IDLE, // ull_int derived from IDLE + IOWAIT tics + STAT_TIC_SUM_BUSY, // ull_int derived from SUM_TOTAL - SUM_IDLE tics +- STAT_TIC_SUM_TOTAL, // ull_int derived from sum of all 10 tics ++ STAT_TIC_SUM_TOTAL, // ull_int derived from sum of all tics, minus 2 GUEST tics + + STAT_TIC_SUM_DELTA_USER, // sl_int derived from above + STAT_TIC_SUM_DELTA_SYSTEM, // sl_int " +diff --git a/library/stat.c b/library/stat.c +index 202dfa52..96672431 100644 +--- a/library/stat.c ++++ b/library/stat.c +@@ -572,11 +572,15 @@ static inline void stat_derive_unique ( + this->new.xidl + = this->new.idle + + this->new.iowait; ++ /* note: we exclude guest tics from xtot since ... ++ 'user' already includes 'guest' ++ 'nice' already includes 'gnice' ++ ( see linux sources: ./kernel/sched/cputime.c, kcpustat_cpu_fetch ) */ + this->new.xtot +- = this->new.xusr + this->new.xsys + this->new.xidl +- + this->new.stolen +- + this->new.guest +- + this->new.gnice; ++ = this->new.xusr ++ + this->new.xsys ++ + this->new.xidl ++ + this->new.stolen; + this->new.xbsy + = this->new.xtot - this->new.xidl; + +-- +2.33.0 + diff --git a/backport-top-adapt-to-that-guest-total-tics-change-stat-api.patch b/backport-top-adapt-to-that-guest-total-tics-change-stat-api.patch new file mode 100644 index 0000000..51b8582 --- /dev/null +++ b/backport-top-adapt-to-that-guest-total-tics-change-stat-api.patch @@ -0,0 +1,78 @@ +From 3fb34669d3a7e1c0c013a907aeae2c4117ba617e Mon Sep 17 00:00:00 2001 +From: Jim Warner +Date: Sat, 22 Jun 2024 00:00:00 -0500 +Subject: [PATCH 3/3] top: adapt to that guest/total tics change, api + +Signed-off-by: Jim Warner +--- + man/top.1 | 5 +---- + src/top/top.c | 9 --------- + 2 files changed, 1 insertion(+), 13 deletions(-) + +diff --git a/man/top.1 b/man/top.1 +index 2e4f252d..067c2ef7 100644 +--- a/man/top.1 ++++ b/man/top.1 +@@ -59,7 +59,7 @@ memory statistics and data for other users requires root privileges + . + .\" Document ///////////////////////////////////////////////////////////// + .\" ---------------------------------------------------------------------- +-.TH TOP 1 "September 2022" "procps-ng" "User Commands" ++.TH TOP 1 "June 2024" "procps-ng" "User Commands" + .\" ---------------------------------------------------------------------- + .nh + +@@ -542,9 +542,6 @@ Depending on your kernel version, the \fBst\fR field may not be shown. + \fBst\fR : time stolen from this vm by the hypervisor + .fi + +-The `sy' value above also reflects the time running a virtual \*(Pu +-for guest operating systems, including those that have been niced. +- + Beyond the first tasks/threads line, there are alternate \*(PU display + modes available via the 4-way `t' \*(CT. + They show an abbreviated summary consisting of these elements: +diff --git a/src/top/top.c b/src/top/top.c +index 1383a17a..c1a08dc2 100644 +--- a/src/top/top.c ++++ b/src/top/top.c +@@ -286,7 +286,6 @@ static enum stat_item Stat_items[] = { + STAT_TIC_DELTA_NICE, STAT_TIC_DELTA_IDLE, + STAT_TIC_DELTA_IOWAIT, STAT_TIC_DELTA_IRQ, + STAT_TIC_DELTA_SOFTIRQ, STAT_TIC_DELTA_STOLEN, +- STAT_TIC_DELTA_GUEST, STAT_TIC_DELTA_GUEST_NICE, + STAT_TIC_SUM_DELTA_USER, STAT_TIC_SUM_DELTA_SYSTEM, + #ifdef CORE_TYPE_NO + STAT_TIC_SUM_DELTA_TOTAL }; +@@ -299,7 +298,6 @@ enum Rel_statitems { + stat_NI, stat_IL, + stat_IO, stat_IR, + stat_SI, stat_ST, +- stat_GU, stat_GN, + stat_SUM_USR, stat_SUM_SYS, + #ifdef CORE_TYPE_NO + stat_SUM_TOT }; +@@ -6410,11 +6408,6 @@ static int sum_tics (struct stat_stack *this, const char *pfx, int nobuf) { + if (1 > tot_frme) idl_frme = tot_frme = 1; + scale = 100.0 / (float)tot_frme; + +- /* account for VM tics not otherwise provided for ... +- ( with xtra-procps-debug.h, can't use PID_VAL w/ assignment ) */ +- this->head[stat_SY].result.sl_int += rSv(stat_GU) + rSv(stat_GN); +- this->head[stat_SUM_SYS].result.sl_int += rSv(stat_GU) + rSv(stat_GN); +- + /* display some kinda' cpu state percentages + (who or what is explained by the passed prefix) */ + if (Curwin->rc.graph_cpus) { +@@ -6464,8 +6457,6 @@ static int sum_unify (struct stat_stack *this, int nobuf) { + stack[stat_IR].result.sl_int += rSv(stat_IR, sl_int); + stack[stat_SI].result.sl_int += rSv(stat_SI, sl_int); + stack[stat_ST].result.sl_int += rSv(stat_ST, sl_int); +- stack[stat_GU].result.sl_int += rSv(stat_GU, sl_int); +- stack[stat_GN].result.sl_int += rSv(stat_GN, sl_int); + stack[stat_SUM_USR].result.sl_int += rSv(stat_SUM_USR, sl_int); + stack[stat_SUM_SYS].result.sl_int += rSv(stat_SUM_SYS, sl_int); + stack[stat_SUM_TOT].result.sl_int += rSv(stat_SUM_TOT, sl_int); +-- +2.33.0 + diff --git a/procps-ng.spec b/procps-ng.spec index 91b9238..5b6266b 100644 --- a/procps-ng.spec +++ b/procps-ng.spec @@ -1,6 +1,6 @@ Name: procps-ng Version: 4.0.2 -Release: 13 +Release: 14 Summary: Utilities that provide system information. License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ URL: https://sourceforge.net/projects/procps-ng/ @@ -26,6 +26,8 @@ Patch14: backport-ps-Correct-BSD-c-option.patch Patch15: backport-library-address-remaining-cpu-distortions-stat-api.patch Patch16: backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch Patch17: backport-acknowledge-fix-for-the-lost-tasks-ps-issue.patch +Patch18: backport-library-implement-guest-total-tics-change-stat-api.patch +Patch19: backport-top-adapt-to-that-guest-total-tics-change-stat-api.patch BuildRequires: ncurses-devel libtool autoconf automake gcc gettext-devel systemd-devel systemd-pam @@ -108,6 +110,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof %{_mandir}/man* %changelog +* Tue Jun 25 2024 Liu Chao - 4.0.2-14 +- top: adapt to guest/total tics chage, api + * Thu Apr 25 2024 yinyongkang - 4.0.2-13 - ps: don't lose tasks when --sort used with forest mode -- Gitee