From ced5009f759327011488d3c5d0bd3192ff8da009 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 18 Dec 2012 00:00:00 -0600 Subject: [PATCH] top: limit task cpu % based on total number of threads Everyone has either accepted this potential distortion or patched top to eliminate it. Now, the time has come to regain some consistency when calculating that %CPU. We'll now limit such values to: 100.0 * total threads. And, it took way too long to address this little flaw. (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Reference(s): http://www.freelists.org/post/procps/top-regression-reports http://www.freelists.org/post/procps/top-regression-reports,1 Signed-off-by: Jim Warner --- top/top.1 | 12 +++++++++--- top/top.c | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/top/top.1 b/top/top.1 index c914e771..fb9d740c 100644 --- a/top/top.1 +++ b/top/top.1 @@ -454,9 +454,15 @@ Such fields can, however, be scaled differently via the 'e' \*(CI. 1.\fB %CPU \*(Em \*(PU Usage \fR The task's share of the elapsed \*(PU time since the last screen update, expressed as a percentage of total \*(PU time. -In a true SMP environment, if 'Irix mode' is \*F, \*(We will operate -in 'Solaris mode' where a task's \*(Pu usage will be divided by the total -number of \*(PUs. + +In a true SMP environment, if a process is multi-threaded and \*(We is +\fInot\fR operating in Threads mode, amounts greater than 100% may be +reported. +You toggle Threads mode with the 'H' \*(CI. + +Also for multi-processor environments, if 'Irix mode' is \*F, \*(We +will operate in 'Solaris mode' where a task's \*(Pu usage will be +divided by the total number of \*(PUs. You toggle 'Irix/Solaris' modes with the 'I' \*(CI. .TP 4 diff --git a/top/top.c b/top/top.c index 3d35ab22..c9678f96 100644 --- a/top/top.c +++ b/top/top.c @@ -4631,6 +4631,9 @@ static const char *task_show (const WIN_t *q, const proc_t *p) { break; case P_CPU: { float u = (float)p->pcpu * Frame_etscale; + /* process can't use more %cpu than number of threads it has + ( thanks Jaromir Capik ) */ + if (u > 100.0 * p->nlwp) u = 100.0 * p->nlwp; if (u > Cpu_pmax) u = Cpu_pmax; cp = scale_pcnt(u, W, Jn); }