From dan@dan.emsphone.com  Thu Nov  6 10:16:26 1997
Received: from dan.emsphone.com (dan@dan.emsphone.com [199.67.51.101])
          by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id KAA02832
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 6 Nov 1997 10:16:21 -0800 (PST)
          (envelope-from dan@dan.emsphone.com)
Received: (from dan@localhost)
	by dan.emsphone.com (8.8.6/8.8.6) id MAA14661;
	Thu, 6 Nov 1997 12:16:17 -0600 (CST)
Message-Id: <199711061816.MAA14661@dan.emsphone.com>
Date: Thu, 6 Nov 1997 12:16:17 -0600 (CST)
From: dnelson@emsphone.com
Reply-To: dnelson@emsphone.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: /bin/top doesn't sort idle processes correctly
X-Send-Pr-Version: 3.2

>Number:         4957
>Category:       bin
>Synopsis:       /bin/top doesn't sort idle processes correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov  6 10:20:02 PST 1997
>Closed-Date:    Sat Feb 14 05:37:58 PST 1998
>Last-Modified:  Sat Feb 14 05:39:00 PST 1998
>Originator:     Dan Nelson
>Release:        FreeBSD 2.2-970701-RELENG i386
>Organization:
Executive Marketing Services, Inc.
>Environment:

>Description:

/usr/bin/top doesn't sort idle processes by total CPU usage.  The
current code is sorting by cpticks, which gets zeroed every second;
sort of useless for sorting.

>How-To-Repeat:

Run top; make sure I)dle processes are shown, see that they are not
sorted on CPU usage

>Fix:

Don't sort on cpticks; instead sort on what top actually prints in the
TIME column; rtime.tv_sec.

Index: machine.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.3.2.2
diff -b -u -p -r1.3.2.2 machine.c
--- machine.c	1997/09/27 21:30:16	1.3.2.2
+++ machine.c	1997/11/06 17:45:17
@@ -726,8 +726,8 @@ struct proc **pp2;
     /* compare percent cpu (pctcpu) */
     if ((lresult = PP(p2, p_pctcpu) - PP(p1, p_pctcpu)) == 0)
     {
-	/* use cpticks to break the tie */
-	if ((result = PP(p2, p_cpticks) - PP(p1, p_cpticks)) == 0)
+	/* use CPU usage to break the tie */
+	if ((result = PP(p2, p_rtime).tv_sec - PP(p1, p_rtime).tv_sec) == 0)
 	{
 	    /* use process state to break the tie */
 	    if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] -

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: peter 
State-Changed-When: Sat Feb 14 05:37:58 PST 1998 
State-Changed-Why:  
Suggested fixes applied; src/usr.bin/top/machine.c rev 1.9 and 1.3.2.3 
Thanks! 
>Unformatted:
