Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Mar 2000 20:04:21 +0000
From:      David Malone <dwmalone@maths.tcd.ie>
To:        Luke Hollins <lwh@pathcom.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: top sorting error
Message-ID:  <20000324200421.A59323@bell.maths.tcd.ie>
In-Reply-To: <Pine.BSF.4.21.0003241256490.99991-100000@PHOENIX.ZER0.NET>; from lwh@pathcom.com on Fri, Mar 24, 2000 at 01:00:54PM -0500
References:  <Pine.BSF.4.21.0003241256490.99991-100000@PHOENIX.ZER0.NET>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Mar 24, 2000 at 01:00:54PM -0500, Luke Hollins wrote:

> I don't know if this is specific to FreeBSD but I just noticed it when i
> picked o time in top:
> 
>   PID USERNAME  PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
> 79364 root        2   0  2696K  1636K select   8:23  0.00%  0.00% apache
>   235 mysql       2   0 13372K  6384K poll   361:14  0.15%  0.15% mysqld

It seems to be an overflow problem - top was reilying on things
fitting into a int, which were 64 bits long. It looks like someone
ran into the problem before for the %cpu field, and fixed it in a
different way. This patch below should fix it regardless of the
type of the variable.

It's for a file in /usr/src/usr.bin/top.

	David.

--- machine.c.orig	Fri Mar 24 19:57:36 2000
+++ machine.c	Fri Mar 24 19:58:17 2000
@@ -737,26 +737,26 @@
     4	/* stop			*/
 };
  
+#define CMP(a,b) ( (a) == (b) ? 0 : (a) < (b) ? -1 : 1 )
 
 #define ORDERKEY_PCTCPU \
-  if (lresult = (long) PP(p2, p_pctcpu) - (long) PP(p1, p_pctcpu), \
-     (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0)
+  if ((result = CMP(PP(p2, p_pctcpu),PP(p1, p_pctcpu))) == 0)
 
 #define ORDERKEY_CPTICKS \
-  if ((result = PP(p2, p_runtime) - PP(p1, p_runtime)) == 0)
+  if ((result = CMP(PP(p2, p_runtime),PP(p1, p_runtime))) == 0)
 
 #define ORDERKEY_STATE \
-  if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - \
-                sorted_state[(unsigned char) PP(p1, p_stat)]) == 0)
+  if ((result = CMP(sorted_state[(unsigned char) PP(p2, p_stat)], \
+                sorted_state[(unsigned char) PP(p1, p_stat)])) == 0)
 
 #define ORDERKEY_PRIO \
-  if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0)
+  if ((result = CMP(PP(p2, p_priority),PP(p1, p_priority))) == 0)
 
 #define ORDERKEY_RSSIZE \
-  if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0) 
+  if ((result = CMP(VP(p2, vm_rssize),VP(p1, vm_rssize))) == 0) 
 
 #define ORDERKEY_MEM \
-  if ( (result = PROCSIZE(p2) - PROCSIZE(p1)) == 0 )
+  if ((result = CMP(PROCSIZE(p2),PROCSIZE(p1))) == 0 )
 
 /* compare_cpu - the comparison function for sorting by cpu percentage */
 
@@ -774,7 +774,6 @@
     register struct kinfo_proc *p1;
     register struct kinfo_proc *p2;
     register int result;
-    register pctcpu lresult;
 
     /* remove one level of indirection */
     p1 = *(struct kinfo_proc **) pp1;
@@ -816,7 +815,6 @@
     register struct kinfo_proc *p1;
     register struct kinfo_proc *p2;
     register int result;
-    register pctcpu lresult;
 
     /* remove one level of indirection */
     p1 = *(struct kinfo_proc **) pp1;
@@ -845,7 +843,6 @@
     register struct kinfo_proc *p1;
     register struct kinfo_proc *p2;
     register int result;
-    register pctcpu lresult;
 
     /* remove one level of indirection */
     p1 = *(struct kinfo_proc **) pp1;
@@ -874,7 +871,6 @@
     register struct kinfo_proc *p1;
     register struct kinfo_proc *p2;
     register int result;
-    register pctcpu lresult;
   
     /* remove one level of indirection */
     p1 = *(struct kinfo_proc **) pp1;
@@ -903,7 +899,6 @@
     register struct kinfo_proc *p1;
     register struct kinfo_proc *p2;
     register int result;
-    register pctcpu lresult;
 
     /* remove one level of indirection */
     p1 = *(struct kinfo_proc **) pp1;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000324200421.A59323>