From 3d4fc943213cb1b002cd0441e00d129ada476613 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 2 Apr 2024 12:38:04 +0800 Subject: [PATCH] library: address remaining cpu distorrions, api Signed-off-by: Liu Chao (cherry picked from commit 7d779697472a1dc559437c26cdc6915e3b48018c) --- ...s-remaining-cpu-distortions-stat-api.patch | 79 +++++++++++++++++++ procps-ng.spec | 6 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 backport-library-address-remaining-cpu-distortions-stat-api.patch diff --git a/backport-library-address-remaining-cpu-distortions-stat-api.patch b/backport-library-address-remaining-cpu-distortions-stat-api.patch new file mode 100644 index 0000000..6a6d72e --- /dev/null +++ b/backport-library-address-remaining-cpu-distortions-stat-api.patch @@ -0,0 +1,79 @@ +From 6418b8c1fbcfdcda4cad8efacccceb7bcdbb1de9 Mon Sep 17 00:00:00 2001 +From: Jim Warner +Date: Wed, 20 Mar 2024 00:00:00 -0500 +Subject: [PATCH] library: address remaining cpu distortions, api + +When the potential cpu distortion was addressed in the +commit referenced below, the revision did not quite go +far enough. This was revealed in the merge plus issue +posts also shown. Thus a need for this final solution. + +[ and now that all the stat_jifs fields are verified ] +[ that TICsetH macro need not check for distortions. ] + +Reference(s): +https://gitlab.com/procps-ng/procps/-/merge_requests/223 +https://gitlab.com/procps-ng/procps/-/issues/321 + +. Mar, 2017 - cpu distorions relocated/improved +commit 253ac7f709412a8699767bd70faeaf98e19614f0 + +Discovered-by: Chao Liu SuperSix173 +Signed-off-by: Jim Warner +--- + library/stat.c | 24 +++++++++++++++--------- + 1 file changed, 15 insertions(+), 9 deletions(-) + +diff --git a/library/stat.c b/library/stat.c +index c37e9b54..b04fe0a5 100644 +--- a/library/stat.c ++++ b/library/stat.c +@@ -182,9 +182,10 @@ struct stat_info { + #define SYS_set(e,t,x) setDECL(e) { \ + (void)T; R->result. t = S->new. x; } + // delta assignment ++// ( thanks to 'stat_derive_unique', this macro no longer needs to ) ++// ( protect against a negative value when a cpu is brought online ) + #define TICsetH(e,t,x) setDECL(e) { \ +- (void)S; R->result. t = ( T->new. x - T->old. x ); \ +- if (R->result. t < 0) R->result. t = 0; } ++ (void)S; R->result. t = ( T->new. x - T->old. x ); } + #define SYSsetH(e,t,x) setDECL(e) { \ + (void)T; R->result. t = ( S->new. x - S->old. x ); } + +@@ -555,6 +556,9 @@ wrap_up: + static inline void stat_derive_unique ( + struct hist_tic *this) + { ++ unsigned long long *new, *old; ++ int i; ++ + /* note: we calculate these derived values in a manner consistent with + the calculations for cgroup accounting, as nearly as possible + ( see linux sources: ./kernel/cgroup/rstat.c, root_cgroup_cputime ) */ +@@ -576,13 +580,15 @@ static inline void stat_derive_unique ( + this->new.xbsy + = this->new.xtot - this->new.xidl; + +- // don't distort deltas when cpus are taken offline or brought online +- if (this->new.xusr < this->old.xusr +- || (this->new.xsys < this->old.xsys) +- || (this->new.xidl < this->old.xidl) +- || (this->new.xbsy < this->old.xbsy) +- || (this->new.xtot < this->old.xtot)) +- memcpy(&this->old, &this->new, sizeof(struct stat_jifs)); ++ // don't distort results when cpus are brought back online ++ new = (unsigned long long *)&this->new; ++ old = (unsigned long long *)&this->old; ++ for (i = 0; i < sizeof(struct stat_jifs) / sizeof(unsigned long long); i++) { ++ if (*(new++) < *(old++)) { ++ memcpy(&this->old, &this->new, sizeof(struct stat_jifs)); ++ break; ++ } ++ } + } // end: stat_derive_unique + + +-- +2.33.0 + diff --git a/procps-ng.spec b/procps-ng.spec index 4a71947..b922ffa 100644 --- a/procps-ng.spec +++ b/procps-ng.spec @@ -1,6 +1,6 @@ Name: procps-ng Version: 4.0.2 -Release: 11 +Release: 12 Summary: Utilities that provide system information. License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ URL: https://sourceforge.net/projects/procps-ng/ @@ -23,6 +23,7 @@ Patch11: backport-vmstat-Update-memory-statistics.patch Patch12: backport-vmstat-Print-guest-time.patch Patch13: backport-ps-Fix-possible-buffer-overflow-in-C-option.patch Patch14: backport-ps-Correct-BSD-c-option.patch +Patch15: backport-library-address-remaining-cpu-distortions-stat-api.patch BuildRequires: ncurses-devel libtool autoconf automake gcc gettext-devel systemd-devel systemd-pam @@ -105,6 +106,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof %{_mandir}/man* %changelog +* Tue Apr 02 2024 Liu Chao - 4.0.2-12 +- library: address remaining cpu distorrions, api + * Fri Mar 29 2024 Weifeng Su - 4.0.2-11 - backport patch to Correct BSD c option issue -- Gitee