From nobody@FreeBSD.org  Sat Mar 28 21:43:26 2009
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 5B8B0106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 28 Mar 2009 21:43:26 +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 4980D8FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 28 Mar 2009 21:43:26 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n2SLhPG0035204
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 28 Mar 2009 21:43:25 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n2SLhP4V035203;
	Sat, 28 Mar 2009 21:43:25 GMT
	(envelope-from nobody)
Message-Id: <200903282143.n2SLhP4V035203@www.freebsd.org>
Date: Sat, 28 Mar 2009 21:43:25 GMT
From: Alexander Zagrebin <alexz@visp.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: top without -H switch reports incorrect time for multithreaded processes
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         133168
>Category:       bin
>Synopsis:       [patch] top(1) without -H switch reports incorrect time for multithreaded processes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 28 21:50:01 UTC 2009
>Closed-Date:    Mon Mar 30 00:13:48 UTC 2009
>Last-Modified:  Mon Mar 30 00:13:48 UTC 2009
>Originator:     Alexander Zagrebin
>Release:        7.1-RELEASE
>Organization:
>Environment:
FreeBSD gw.xxxxxxxx.xx 7.1-RELEASE FreeBSD 7.1-RELEASE #0: Mon Jan  5 16:27:35 MSK 2009     root@gw.xxxxxxxx.xx:/usr/obj/usr/src/sys/KERNEL  i386
>Description:
When top displays "threads as a count" (without -H switch),
it reports incorrect time for multithreaded processes.
For example:

$ top -H -d1 100 | grep named
  844 bind             44    0 26476K  8168K ucond    2:28  0.00% named
  844 bind             44    0 26476K  8168K select   0:17  0.00% named
  844 bind             44    0 26476K  8168K ucond    0:09  0.00% named
  844 bind             20    0 26476K  8168K sigwai   0:00  0.00% named

So without -H switch top have to report about 2:54 of a time, but...

$ top -d1 100 | grep named
  844 bind               4  44    0 26476K  8168K select   0:17  0.00% named

It seems that in this case top displays time of the first thread only.

>How-To-Repeat:
See full description
>Fix:
After this patch I have the correct result:

--- src/usr.bin/top/machine.c.orig      2009-03-05 20:35:56.000000000 +0300
+++ src/usr.bin/top/machine.c           2009-03-29 00:14:53.000000000 +0300
@@ -724,6 +724,7 @@
                        active_procs++;
                        prev_pp = pp;
                } else {
+                       prev_pp->ki_runtime += pp->ki_runtime;
                        prev_pp->ki_pctcpu += pp->ki_pctcpu;
                }
        }

>Release-Note:
>Audit-Trail:

From: Mikolaj Golub <to.my.trociny@gmail.com>
To: Alexander Zagrebin <alexz@visp.ru>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/133168: top without -H switch reports incorrect time for multithreaded processes
Date: Sun, 29 Mar 2009 09:58:43 +0300

 This pr is a duplicate of bin/127331
 
 -- 
 Mikolaj Golub
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Mon Mar 30 00:12:54 UTC 2009 
State-Changed-Why:  
Duplicate of bin/127331, but thanks for the submission. 

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