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 <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2012-12-18 00:00:00 -06:00
committed by Craig Small
parent 27c2ef1e6d
commit ced5009f75
2 changed files with 12 additions and 3 deletions

View File

@ -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 <jcapik@redhat.com> ) */
if (u > 100.0 * p->nlwp) u = 100.0 * p->nlwp;
if (u > Cpu_pmax) u = Cpu_pmax;
cp = scale_pcnt(u, W, Jn);
}