From b3a1f52679f843d5f732d6c400a84e8932aed32a Mon Sep 17 00:00:00 2001 From: zhoujie Date: Tue, 11 Jul 2023 20:41:32 +0800 Subject: [PATCH] library: restore the proper main thread tics valuation --- ...he-proper-main-thread-tics-valuation.patch | 94 +++++++++++++++++++ procps-ng.spec | 6 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 backport-library-restore-the-proper-main-thread-tics-valuation.patch diff --git a/backport-library-restore-the-proper-main-thread-tics-valuation.patch b/backport-library-restore-the-proper-main-thread-tics-valuation.patch new file mode 100644 index 0000000..fdb9e2f --- /dev/null +++ b/backport-library-restore-the-proper-main-thread-tics-valuation.patch @@ -0,0 +1,94 @@ +From bc688d630aeeeda5e003d35bbcfcdba08f21b399 Mon Sep 17 00:00:00 2001 +From: Jim Warner +Date: Wed, 31 May 2023 00:00:00 -0500 +Subject: [PATCH] library: restore the proper main thread tics valuation + +The issue cited below revealed an earlier commit, also +shown below, resulted in an incorrect tics value for a +thread group leader. That change was made so the group +leader would have a proper autogroup id, not a -1 that +was shown with sibling threads which lacked that file. + +So this patch will just restore pre version 4 behavior +while not upsetting LIBPROC_HIDE_KERNEL functionality. + +[ this change means that when THREAD mode is active, ] +[ the autogroup id & nice values won't be available. ] +[ they were only shown for the group leaders anyway. ] + +Reference(s): +https://gitlab.com/procps-ng/procps/-/issues/280 +. Aug, 2021 - thread group leader change +commit a37526260917bac624ae6b75fd9f4ea7287d81ad + +Signed-off-by: Jim Warner +--- + library/readproc.c | 23 ++++++++++++----------- + 1 files changed, 12 insertions(+), 11 deletions(-) + +diff --git a/library/readproc.c b/library/readproc.c +index 94030e94..2dfe4c9e 100644 +--- a/library/readproc.c ++++ b/library/readproc.c +@@ -1361,7 +1361,14 @@ static proc_t *simple_readtask(PROCTAB *restrict const PT, proc_t *restrict cons + if (flags & PROC_FILLAUTOGRP) // value the 2 autogroup fields + autogroup_fill(path, t); + +- if (rc == 0) return t; ++ // openproc() ensured that a ppid will be present when needed ... ++ if (rc == 0) { ++ if (PT->hide_kernel && (t->ppid == 2 || t->tid == 2)) { ++ free_acquired(t); ++ return NULL; ++ } ++ return t; ++ } + errno = ENOMEM; + next_task: + return NULL; +@@ -1463,7 +1470,6 @@ proc_t *readproc(PROCTAB *restrict const PT, proc_t *restrict p) { + free_acquired(p); + + for(;;){ +- if (errno == ENOMEM) goto out; + // fills in the path, plus p->tid and p->tgid + if (!PT->finder(PT,p)) goto out; + +@@ -1484,7 +1490,7 @@ out: + proc_t *readeither (PROCTAB *restrict const PT, proc_t *restrict x) { + static __thread proc_t skel_p; // skeleton proc_t, only uses tid + tgid + static __thread proc_t *new_p; // for process/task transitions +- static __thread int canary, leader; ++ static __thread int canary; + char path[PROCPATHLEN]; + proc_t *ret; + +@@ -1498,23 +1504,18 @@ proc_t *readeither (PROCTAB *restrict const PT, proc_t *restrict x) { + next_proc: + new_p = NULL; + for (;;) { +- if (errno == ENOMEM) goto end_procs; + // fills in the PT->path, plus skel_p.tid and skel_p.tgid + if (!PT->finder(PT,&skel_p)) goto end_procs; // simple_nextpid +- leader = skel_p.tid; + if (!task_dir_missing) break; + if ((ret = PT->reader(PT,x))) return ret; // simple_readproc + } + + next_task: + // fills in our path, plus x->tid and x->tgid +- if (!(PT->taskfinder(PT,&skel_p,x,path))) // simple_nexttid ++ if ((!(PT->taskfinder(PT,&skel_p,x,path))) // simple_nexttid ++ || (!(ret = PT->taskreader(PT,x,path)))) { // simple_readtask + goto next_proc; +- /* to avoid loss of some thread group leader data, +- we must check its base dir, not its 'task' dir! */ +- if (x->tid == leader) ret = PT->reader(PT,x); // simple_readproc +- else ret = PT->taskreader(PT,x,path); // simple_readtask +- if (!ret) goto next_proc; ++ } + if (!new_p) { + new_p = ret; + canary = new_p->tid; +-- +GitLab diff --git a/procps-ng.spec b/procps-ng.spec index a528643..377a680 100644 --- a/procps-ng.spec +++ b/procps-ng.spec @@ -1,6 +1,6 @@ Name: procps-ng Version: 4.0.2 -Release: 6 +Release: 7 Summary: Utilities that provide system information. License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ URL: https://sourceforge.net/projects/procps-ng/ @@ -18,6 +18,7 @@ Patch6: backport-0002-ps-trade-previous-fix-for-final-solution-to-m-option.patc Patch7: backport-top-lessen-summary-cpu-distortions-with-first-displa.patch Patch8: backport-pmap-Increase-memory-allocation-failure-judgment.patch Patch9: backport-top-added-guest-tics-when-multiple-cpus-were-merged.patch +Patch10: backport-library-restore-the-proper-main-thread-tics-valuation.patch BuildRequires: ncurses-devel libtool autoconf automake gcc gettext-devel systemd-devel systemd-pam @@ -100,6 +101,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof %{_mandir}/man* %changelog +* Tue Jul 11 2023 zhoujie - 4.0.2-7 +- library: restore the proper main thread tics valuation + * Wed Jun 28 2023 zhoujie - 4.0.2-6 - top: added guest tics when multiple cpus were merged -- Gitee