bin/127331: [patch] top(1) only shows cputime used by one process thread

Pekka Savola pekkas at netcore.fi
Fri Sep 12 17:40:01 UTC 2008


>Number:         127331
>Category:       bin
>Synopsis:       [patch] top(1) only shows cputime used by one process thread
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 12 17:40:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Pekka Savola
>Release:        7.1-PRERELEASE
>Organization:
CSC/FUNET
>Environment:
FreeBSD sixpack.funet.fi 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #11: Wed Sep 10 04:55:20 EEST 2008     root at sixpack.funet.fi:/usr/obj/usr/src/sys/SIXPACK  i386

>Description:
top(1) default view does not seem to show the total cputime used by all the process threads, for example:

  PID USERNAME  THR PRI NICE   SIZE    RES STATE  C   TIME   WCPU COMMAND
16955 nobody      6  20    0 28252K 23032K sigwai 1   0:26 51.46% miredo

if you press 'H', you get to see every thread:

16955 nobody    70    0 28252K 23032K CPU1   1 535:55 28.47% miredo
16955 nobody     4    0 28252K 23032K RUN    1 410:49 22.27% miredo
16955 nobody     8    0 28252K 23032K nanslp 1   0:31  0.00% miredo
16955 nobody    20    0 28252K 23032K sigwai 1   0:26  0.00% miredo
16955 nobody    20    0 28252K 23032K sigwai 1   0:00  0.00% miredo
16955 nobody    20    0 28252K 23032K sigwai 1   0:00  0.00% miredo

ps is using the kvm interface slightly differently, and it's getting the total cputime correctly:

nobody 16955  0.0  1.1 28252 23032  ??  S    Wed11PM 947:38.87 /usr/loca/sbin/miredo -c /usr/local/etc/miredo.conf -p /var/run/mir...

There is already code in top(1) to add together information from all threads.  However, only CPU usage percentage is added, not CPU time.  The following patch fixes this.  Then the output is like follows:

16955 nobody      6  20    0 28252K 23036K sigwai 0 947:55 51.56% miredo


>How-To-Repeat:
Run a multi-threaded app and compare its threads' cpu time.
>Fix:
See the attached one-line patch.

Patch attached with submission follows:

--- usr.bin/top/machine.c.orig	2008-04-11 14:45:27.000000000 +0300
+++ usr.bin/top/machine.c	2008-09-12 20:19:15.000000000 +0300
@@ -725,6 +725,7 @@
 			prev_pp = pp;
 		} else {
 			prev_pp->ki_pctcpu += pp->ki_pctcpu;
+			prev_pp->ki_runtime += pp->ki_runtime;
 		}
 	}
 


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list