Date: Thu, 1 Jun 2000 18:14:56 +0100 (BST) From: dwmalone@maths.tcd.ie To: FreeBSD-gnats-submit@freebsd.org Subject: bin/18951: top sorting error Message-ID: <200006011814.aa18661@gosset.maths.tcd.ie>
next in thread | raw e-mail | index | archive | help
>Number: 18951
>Category: bin
>Synopsis: top sorting error
>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: Thu Jun 01 10:20:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: David Malone
>Release: FreeBSD 3.4-STABLE i386
>Organization:
School of Mathematics, Trinity College, Dublin, Ireland.
>Environment:
3-STABLE
>Description:
Top can incorrectly sort things, as many of it assumes things will
fit into an int. One of these was fixed by bde in -current, but
the fix didn't make it back to stable.
>How-To-Repeat:
Start top and then use "o time". Sometimes the processes will be out
of order.
>Fix:
Either MFC 1.28, or the following patch would future proof top, at
the cost of a few CPU cycles. (for /usr/src/usr.bin/top/machine.h)
--- 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;
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006011814.aa18661>
