Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Jun 2018 23:24:08 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334903 - head/usr.bin/top
Message-ID:  <201806092324.w59NO8vl091507@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Sat Jun  9 23:24:08 2018
New Revision: 334903
URL: https://svnweb.freebsd.org/changeset/base/334903

Log:
  top(1): correctly reset per-cpu counters
  
  I had changed this from a for loop to a memset during an earlier
  cleanup. This change was incorrect so revert it.
  
  While here, clean up
  
  Reported by:	flo

Modified:
  head/usr.bin/top/display.c
  head/usr.bin/top/utils.c

Modified: head/usr.bin/top/display.c
==============================================================================
--- head/usr.bin/top/display.c	Sat Jun  9 23:14:59 2018	(r334902)
+++ head/usr.bin/top/display.c	Sat Jun  9 23:24:08 2018	(r334903)
@@ -162,28 +162,23 @@ display_resize(void)
 
 int display_updatecpus(struct statics *statics)
 {
-    int *lp;
     int lines;
     int i;
     
     /* call resize to do the dirty work */
     lines = display_resize();
     if (pcpu_stats)
-	num_cpus = statics->ncpus;
+		num_cpus = statics->ncpus;
     else
-	num_cpus = 1;
+		num_cpus = 1;
     cpustates_column = 5;	/* CPU: */
-    if (num_cpus != 1)
-    cpustates_column += 2;	/* CPU 0: */
-    for (i = num_cpus; i > 9; i /= 10)
-	cpustates_column++;
+    if (num_cpus > 1) {
+		cpustates_column += 1 + digits(num_cpus); /* CPU #: */
+	}
 
     /* fill the "last" array with all -1s, to insure correct updating */
-    lp = lcpustates;
-    i = num_cpustates * num_cpus;
-    while (--i >= 0)
-    {
-	*lp++ = -1;
+	for (i = 0; i < num_cpustates * num_cpus; ++i) {
+		lcpustates[i] = -1;
     }
     
     return(lines);
@@ -541,7 +536,9 @@ z_cpustates(void)
     }
 
     /* fill the "last" array with all -1s, to insure correct updating */
-    memset(lcpustates, -1, num_cpustates * num_cpus);
+	for (i = 0; i < num_cpustates * num_cpus; ++i) {
+		lcpustates[i] = -1;
+    }
 }
 
 /*

Modified: head/usr.bin/top/utils.c
==============================================================================
--- head/usr.bin/top/utils.c	Sat Jun  9 23:14:59 2018	(r334902)
+++ head/usr.bin/top/utils.c	Sat Jun  9 23:24:08 2018	(r334903)
@@ -134,8 +134,8 @@ digits(int val)
 
     while (val > 0)
     {
-	cnt++;
-	val /= 10;
+		cnt++;
+		val /= 10;
     }
     return(cnt);
 }



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