From nobody@FreeBSD.org  Thu Nov 26 09:46:29 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 692E310656A6
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Nov 2009 09:46:29 +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 4D2B08FC29
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Nov 2009 09:46:29 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id nAQ9kR20035075
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Nov 2009 09:46:27 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id nAQ9kRbZ035072;
	Thu, 26 Nov 2009 09:46:27 GMT
	(envelope-from nobody)
Message-Id: <200911260946.nAQ9kRbZ035072@www.freebsd.org>
Date: Thu, 26 Nov 2009 09:46:27 GMT
From: wang jin <wangjin@myhexin.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Incorrect cpu usage of per process under FreeBSD 8.0
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         140892
>Category:       kern
>Synopsis:       top(1): Incorrect cpu usage of per process under FreeBSD 8.0
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 26 09:50:03 UTC 2009
>Closed-Date:    Wed Oct 12 14:52:09 UTC 2011
>Last-Modified:  Wed Oct 12 14:52:09 UTC 2011
>Originator:     wang jin
>Release:        FreeBSD 8.0
>Organization:
hexin
>Environment:
FreeBSD cachehm1 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Thu Nov 26 00:14:56 CST 2009     root@cachehm1:/usr/src/sys/amd64/compile/GENERIC  amd64
>Description:
Squid is the main service of my box, and consumes most system resource.
I ran top command on my box,the output shows CPU1 has 8.6% user usage,
but cpu usage of each process is 0.00%.
FreeBSD 7.2 has no such problem.

# top -CP
last pid: 68141;  load averages:  0.15,  0.14,  0.10                                                                                 up 0+17:04:07  17:21:00
45 processes:  1 running, 44 sleeping
CPU 0:  0.0% user,  0.0% nice,  3.0% system,  0.0% interrupt, 97.0% idle
CPU 1:  8.6% user,  0.0% nice,  1.1% system,  0.0% interrupt, 90.2% idle
Mem: 4293M Active, 2477M Inact, 791M Wired, 131M Cache, 827M Buf, 228M Free
Swap: 4096M Total, 4096M Free

  PID USERNAME  THR PRI NICE   SIZE    RES STATE   C   TIME    CPU COMMAND
 4608 squid      17  44    0   783M   767M ucond   0 140:34  0.00% squid
 1140 root        1  76    0  7232K  1492K piperd  0   1:31  0.00% sh
 1139 root        1  44    0  8304K  2268K pause   1   0:05  0.00% top
 1709 root        1  44    0 36912K  3820K select  1   0:03  0.00% sshd
  953 bind        5  44    0 21356K 13656K kqread  0   0:02  0.00% named
 1079 root        1  44   r0  7012K  1056K nanslp  0   0:02  0.00% watchdogd
 1714 root        1  44    0  8252K  2456K pause   0   0:00  0.00% csh
 1324 root        1  44    0  7976K  1388K select  0   0:00  0.00% inetd
 1284 root        1  44    0  6920K  1340K nanslp  0   0:00  0.00% cron
  878 root        1  44    0  5864K  1272K select  0   0:00  0.00% syslogd
67786 root        1  44    0  8304K  1872K CPU1    0   0:00  0.00% top
  707 root        1  44    0  2180K   476K select  1   0:00  0.00% devd
 1275 root        1  44    0 24980K  3380K select  1   0:00  0.00% sshd
 1130 root        1  46    0  7232K  1420K wait    1   0:00  0.00% sh
 1131 root        1  76    0  7232K  1452K wait    1   0:00  0.00% sh
 1346 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1347 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1351 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1352 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1353 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1350 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1349 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 1348 root        1  76    0  5860K  1056K ttyin   0   0:00  0.00% getty
 4609 squid       1  46    0  2732K   688K piperd  1   0:00  0.00% unlinkd
  130 root        1  76    0  2736K   852K pause   1   0:00  0.00% adjkerntz

>How-To-Repeat:
run top command.

Note: 
The displayed CPU usage of some programs such as squid is too low, but
this is not true for all types of programs.

I ran "sh test.sh", and the CPU usage of test.sh is nearly 100% which
seems correct.
# cat test.sh
while true
do
done

>Fix:


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: arundel 
State-Changed-When: Fri Jul 8 14:29:36 UTC 2011 
State-Changed-Why:  
If you run top like this 

'top -CPH' 

and sum up the CPU values for each thread, does this produce correct numbers? 

Cheers. 
Alex 

http://www.freebsd.org/cgi/query-pr.cgi?pr=140892 
State-Changed-From-To: feedback->closed 
State-Changed-By: remko 
State-Changed-When: Wed Oct 12 14:52:07 UTC 2011 
State-Changed-Why:  
Feedback timeout 

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