Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src/usr.bin/vmstat Pull up revision 1.16 (requested by somm...



details:   https://anonhg.NetBSD.org/src/rev/a3c26872c476
branches:  netbsd-1-6
changeset: 528303:a3c26872c476
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Jun 30 05:47:34 2002 +0000

description:
Pull up revision 1.16 (requested by sommerfeld in ticket #406):
Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.
Fixes I/O rate deflation observed on multiprocessors.

diffstat:

 usr.bin/vmstat/dkstats.c |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (51 lines):

diff -r ca8cbc9adc38 -r a3c26872c476 usr.bin/vmstat/dkstats.c
--- a/usr.bin/vmstat/dkstats.c  Sun Jun 30 05:47:25 2002 +0000
+++ b/usr.bin/vmstat/dkstats.c  Sun Jun 30 05:47:34 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dkstats.c,v 1.15 2002/02/25 00:39:04 enami Exp $       */
+/*     $NetBSD: dkstats.c,v 1.15.2.1 2002/06/30 05:47:34 lukem Exp $   */
 
 /*
  * Copyright (c) 1996 John M. Vinopal
@@ -114,8 +114,9 @@
 void
 dkswap(void)
 {
+       double etime;
        u_int64_t tmp;
-       int     i;
+       int     i, state;
 
 #define        SWAP(fld) do {                                                  \
        tmp = cur.fld;                                                  \
@@ -146,6 +147,17 @@
        SWAP(tk_nin);
        SWAP(tk_nout);
 
+       etime = 0;
+       for (state = 0; state < CPUSTATES; ++state) {
+               etime += cur.cp_time[state];
+       }
+       if (etime == 0)
+               etime = 1;
+       etime /= hz;
+       etime /= cur.cp_ncpu;
+
+       cur.cp_etime = etime;
+
 #undef SWAP
 }
 
@@ -237,6 +249,12 @@
                return (1);
 
        if (memf == NULL) {
+               mib[0] = CTL_HW;
+               mib[1] = HW_NCPU;
+               size = sizeof(cur.cp_ncpu);
+               if (sysctl(mib, 2, &cur.cp_ncpu, &size, NULL, 0) == -1)
+                       err(1, "sysctl hw.ncpu failed");
+
                mib[0] = CTL_KERN;
                mib[1] = KERN_CLOCKRATE;
                size = sizeof(clockinfo);



Home | Main Index | Thread Index | Old Index