NetBSD Problem Report #6979
Received: (qmail 20914 invoked from network); 10 Feb 1999 15:10:14 -0000
Message-Id: <199902101509.PAA03638@shark1.cambridge.arm.com>
Date: Wed, 10 Feb 1999 15:09:54 GMT
From: Richard Earnshaw <rearnsha@cambridge.arm.com>
Reply-To: rearnsha@cambridge.arm.com
To: gnats-bugs@gnats.netbsd.org
Subject: Top gives incorrect CPU percentage when HZ!=100
X-Send-Pr-Version: 3.95
>Number: 6979
>Category: pkg
>Synopsis: Top gives incorrect CPU percentage when HZ!=100
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: wiz
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Feb 10 07:20:01 +0000 1999
>Closed-Date: Sat Jan 13 17:42:58 +0000 2001
>Last-Modified: Sat Jan 13 17:42:58 +0000 2001
>Originator: Richard Earnshaw
>Release: NetBSD-current 1999-02-10<NetBSD-current source date>
>Organization:
ARM Ltd
--
>Environment:
System: NetBSD shark1 1.3I NetBSD 1.3I (SHARK) #11: Mon Feb 8 10:11:59 GMT 1999 rearnsha@shark1:/work/rearnsha/netbsd/sys/arch/arm32/compile/SHARK arm32
>Description:
Sharks running arm/32 define HZ=64 in the config file. Top uses this
value to scale the p_pctcpu value returned from the kernel. This
scaling is incorrect, since it has already been done by the kernel
(this is a cpu percentage figure, not a number of ticks). The result
is that percentage cpu utilization can exceed 100% by a large margin.
The relevent bit of the kernel is kern/kern_synch.c near line 205:
#if (FSHIFT >= CCPU_SHIFT)
p->p_pctcpu += (hz == 100)?
((fixpt_t) p->p_cpticks) << (FSHIFT - CCPU_SHIFT):
100 * (((fixpt_t) p->p_cpticks)
<< (FSHIFT - CCPU_SHIFT)) / hz;
#else
p->p_pctcpu += ((FSCALE - ccpu) *
(p->p_cpticks * FSCALE / hz)) >> FSHIFT;
#endif
Where it can be seen that the setting of hz has already been taken
into account.
>How-To-Repeat:
Build and run top on a machine with HZ!=100
>Fix:
Multiply the weighted and unweighted cpu figures by a factor of
100 less, and don't divide by HZ. Patch below. I haven't looked
closely, but the kernel setting of HZ may no-longer be needed by
top.
--- /work/rearnsha/pkgsrc/sysutils/top/work/top-3.5beta7/machine/m_netbsd13.c Wed Feb 10 09:43:46 1999
+++ ./m_netbsd13.c Wed Feb 10 14:12:56 1999
@@ -560,8 +560,8 @@ format_next_process(handle, get_userid)
format_k(pagetok(VP(pp, vm_rssize))),
state_abbrev[(unsigned char) PP(pp, p_stat)],
format_time(cputime),
- 10000.0 * weighted_cpu(pct, pp) / hz,
- 10000.0 * pct / hz,
+ 100.0 * weighted_cpu(pct, pp),
+ 100.0 * pct,
printable(PP(pp, p_comm)));
/* return the result */
>Release-Note:
>Audit-Trail:
From: "R. C. Dowdeswell" <elric@mabelode.imrryr.org>
To: gnats-bugs@gnats.netbsd.org
Cc: Subject: pkg/6979
Date: Thu, 11 Feb 1999 00:38:21 -0800
There are a couple of other changes that would make life a lot better on my
system at least (an alpha). The sorting on CPU does not currently work, so
I changed: (in machine/m_netbsd13.c)
#define ORDERKEY_PCTCPU blah blah blah
to:
#define ORDERKEY_PCTCPU \
if (lresult = pctdouble(PP(p2, p_pctcpu)) - \
pctdouble(PP(p1, p_pctcpu)), \
(result = (lresult > 0 ? 1 : (lresult < 0 ? -1 : 0))) == 0, 1)
And this makes things a lot nicer..
== Roland Dowdeswell
== http://www.imrryr.org/~elric/
Responsible-Changed-From-To: gnats-admin->pkg-manager
Responsible-Changed-By: fair
Responsible-Changed-When: Mon Apr 19 15:06:39 PDT 1999
Responsible-Changed-Why:
This PR is the responsibility of the NetBSD Package System Manager,
not the GNATS database administrator.
Responsible-Changed-From-To: pkg-manager->wiz
Responsible-Changed-By: wiz
Responsible-Changed-When: Fri Dec 8 07:38:55 PST 2000
Responsible-Changed-Why:
I'll handle this.
Committed the first patch (which already is in 1.5 top).
State-Changed-From-To: open->closed
State-Changed-By: wiz
State-Changed-When: Sat Jan 13 09:42:04 PST 2001
State-Changed-Why:
Second part has already been fixed before 1.5 in a different way,
says elric.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.