From owner-svn-src-all@freebsd.org Sat Jun 9 23:24:09 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8CEA2101F1A3; Sat, 9 Jun 2018 23:24:09 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 346357E386; Sat, 9 Jun 2018 23:24:09 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1568924902; Sat, 9 Jun 2018 23:24:09 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w59NO8nn091508; Sat, 9 Jun 2018 23:24:08 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w59NO8vl091507; Sat, 9 Jun 2018 23:24:08 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806092324.w59NO8vl091507@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Sat, 9 Jun 2018 23:24:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334903 - head/usr.bin/top X-SVN-Group: head X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: head/usr.bin/top X-SVN-Commit-Revision: 334903 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jun 2018 23:24:09 -0000 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); }