From nobody@FreeBSD.org  Fri Sep 12 17:34:59 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 7B3EE1065671
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 12 Sep 2008 17:34:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 6A8A68FC18
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 12 Sep 2008 17:34:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m8CHYwhG062988
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 12 Sep 2008 17:34:58 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m8CHYwAZ062987;
	Fri, 12 Sep 2008 17:34:58 GMT
	(envelope-from nobody)
Message-Id: <200809121734.m8CHYwAZ062987@www.freebsd.org>
Date: Fri, 12 Sep 2008 17:34:58 GMT
From: Pekka Savola <pekkas@netcore.fi>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] top(1) only shows cputime used by one process thread
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         127331
>Category:       bin
>Synopsis:       [patch] top(1) only shows cputime used by one process thread
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 12 17:40:01 UTC 2008
>Closed-Date:    Tue Jul 12 14:28:51 UTC 2011
>Last-Modified:  Tue Jul 12 14:28:51 UTC 2011
>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@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:
State-Changed-From-To: open->analyzed 
State-Changed-By: edwin 
State-Changed-When: Thu Sep 25 15:38:27 UTC 2008 
State-Changed-Why:  
Will be fixed in the upgrade to 3.8b1 


Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Sep 25 15:38:27 UTC 2008 
Responsible-Changed-Why:  
I'll handle it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127331 
State-Changed-From-To: analyzed->closed 
State-Changed-By: jhb 
State-Changed-When: Tue Jul 12 14:28:15 UTC 2011 
State-Changed-Why:  
Patch was independently committed to HEAD in Sep of 2008 and was just 
merged to 7. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127331 
>Unformatted:
