From owner-freebsd-bugs@FreeBSD.ORG Fri Sep 12 17:40:01 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ABC611065671 for ; Fri, 12 Sep 2008 17:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 8900E8FC27 for ; Fri, 12 Sep 2008 17:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m8CHe1ak091881 for ; Fri, 12 Sep 2008 17:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m8CHe1Go091880; Fri, 12 Sep 2008 17:40:01 GMT (envelope-from gnats) Resent-Date: Fri, 12 Sep 2008 17:40:01 GMT Resent-Message-Id: <200809121740.m8CHe1Go091880@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Pekka Savola Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7B3EE1065671 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/127331: [patch] top(1) only shows cputime used by one process thread X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Sep 2008 17:40:01 -0000 >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@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: