Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Sep 1999 02:19:01 -0600 (MDT)
From:      Eric Peters <epeters@207.92.104.97>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/13557: [PATCH] top(1) sorts processes incorrectly
Message-ID:  <199909030819.CAA79205@dualism.torrenal.com>

next in thread | raw e-mail | index | archive | help

>Number:         13557
>Category:       bin
>Synopsis:       [PATCH] top(1) sorts processes incorrectly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep  3 01:30:01 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Eric Peters
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
>Environment:

FreeBSD 3.2-Stable built August 11th, 1999
SMP Pentium II 450x2

>Description:

When running top(1) sorting by 'time' (top -otime)
top(1) fails to sort correctly some processes that have
accumulated excessive runtime.

Turns out top(1) compares the time processes have
run (proc.p_runtime) and stores the result in an interger.
Not bad in itself, but p_runtime is a 64bit value.


>How-To-Repeat:

start a long-running process, such as

#!/usr/bin/perl
do{}while 1

(I am sure more productive examples abound.)
Check 'top -otime' periodiocaly (about 8.5 hours in should work,
but I suspect this may present itself earlier).

>Fix:
	
Apply the following patch.  Although I can verify its sanity,
the code involved has a smell of 'optimized' & I won't pretend
knowing how this mangles it or how best to nudge things into
good order.

*** usr.bin/top/machine.c.orig	Fri Sep  3 00:57:09 1999
--- usr.bin/top/machine.c	Fri Sep  3 01:02:07 1999
***************
*** 743,749 ****
       (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0)
  
  #define ORDERKEY_CPTICKS \
!   if ((result = PP(p2, p_runtime) - PP(p1, p_runtime)) == 0)
  
  #define ORDERKEY_STATE \
    if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - \
--- 743,750 ----
       (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0)
  
  #define ORDERKEY_CPTICKS \
!   if (llresult = (long long) PP(p2, p_runtime) - (long long) PP(p1, p_runtime), \
!      (result = llresult > 0 ? 1 : llresult < 0 ? -1 : 0) == 0)
  
  #define ORDERKEY_STATE \
    if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - \
***************
*** 775,780 ****
--- 776,782 ----
      register struct kinfo_proc *p2;
      register int result;
      register pctcpu lresult;
+     long long llresult;
  
      /* remove one level of indirection */
      p1 = *(struct kinfo_proc **) pp1;
***************
*** 817,822 ****
--- 819,825 ----
      register struct kinfo_proc *p2;
      register int result;
      register pctcpu lresult;
+     long long llresult;
  
      /* remove one level of indirection */
      p1 = *(struct kinfo_proc **) pp1;
***************
*** 846,851 ****
--- 849,855 ----
      register struct kinfo_proc *p2;
      register int result;
      register pctcpu lresult;
+     long long llresult;
  
      /* remove one level of indirection */
      p1 = *(struct kinfo_proc **) pp1;
***************
*** 875,880 ****
--- 879,885 ----
      register struct kinfo_proc *p2;
      register int result;
      register pctcpu lresult;
+     long long llresult;
    
      /* remove one level of indirection */
      p1 = *(struct kinfo_proc **) pp1;
***************
*** 904,909 ****
--- 909,915 ----
      register struct kinfo_proc *p2;
      register int result;
      register pctcpu lresult;
+     long long llresult;
  
      /* 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?199909030819.CAA79205>