Source-Changes-HG archive

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

[src/trunk]: src Since the KERN_CP_TIME sysctl reports total clock ticks acro...



details:   https://anonhg.NetBSD.org/src/rev/9d99a00cb067
branches:  trunk
changeset: 533420:9d99a00cb067
user:      sommerfeld <sommerfeld%NetBSD.org@localhost>
date:      Sun Jun 30 00:10:33 2002 +0000

description:
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/systat/iostat.c  |  14 ++++----------
 usr.bin/systat/vmstat.c  |  23 ++++++++---------------
 usr.bin/vmstat/dkstats.c |  22 ++++++++++++++++++++--
 usr.bin/vmstat/dkstats.h |   4 +++-
 usr.bin/vmstat/vmstat.c  |  35 +++++++++++++++--------------------
 usr.sbin/iostat/iostat.c |  22 +++++++---------------
 6 files changed, 57 insertions(+), 63 deletions(-)

diffs (truncated from 386 to 300 lines):

diff -r bd1d3a92ddc4 -r 9d99a00cb067 usr.bin/systat/iostat.c
--- a/usr.bin/systat/iostat.c   Sat Jun 29 23:54:05 2002 +0000
+++ b/usr.bin/systat/iostat.c   Sun Jun 30 00:10:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iostat.c,v 1.20 2002/06/09 07:14:32 itojun Exp $       */
+/*     $NetBSD: iostat.c,v 1.21 2002/06/30 00:10:33 sommerfeld Exp $   */
 
 /*
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)iostat.c   8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: iostat.c,v 1.20 2002/06/09 07:14:32 itojun Exp $");
+__RCSID("$NetBSD: iostat.c,v 1.21 2002/06/30 00:10:33 sommerfeld Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -190,18 +190,12 @@
                return;
        dkswap();
 
-       etime = 0;
-       for(i = 0; i < CPUSTATES; i++) {
-               etime += cur.cp_time[i];
-       }
-       if (etime == 0.0)
-               etime = 1.0;
-       etime /= (float) hz;
+       etime = cur.cp_etime;
        row = 1;
 
        /*
         * Interrupt CPU state not calculated yet.
-        */ 
+        */
        for (i = 0; i < CPUSTATES; i++)
                stat1(row++, i);
        if (!numbers) {
diff -r bd1d3a92ddc4 -r 9d99a00cb067 usr.bin/systat/vmstat.c
--- a/usr.bin/systat/vmstat.c   Sat Jun 29 23:54:05 2002 +0000
+++ b/usr.bin/systat/vmstat.c   Sun Jun 30 00:10:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmstat.c,v 1.38 2002/05/15 06:43:37 kleink Exp $       */
+/*     $NetBSD: vmstat.c,v 1.39 2002/06/30 00:10:34 sommerfeld Exp $   */
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.38 2002/05/15 06:43:37 kleink Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.39 2002/06/30 00:10:34 sommerfeld Exp $");
 #endif /* not lint */
 
 /*
@@ -62,7 +62,6 @@
 #include "dkstats.h"
 
 static struct Info {
-       u_int64_t time[CPUSTATES];
        struct  uvmexp_sysctl uvmexp;
        struct  vmtotal Total;
        struct  nchstats nchstats;
@@ -328,15 +327,11 @@
        int psiz, inttotal;
        int i, l, c;
        static int failcnt = 0;
-       
+
        if (state == TIME)
                dkswap();
-       etime = 0;
-       for(i = 0; i < CPUSTATES; i++) {
-               X(time);
-               etime += s.time[i];
-       }
-       if (etime < 1.0) {      /* < 5 ticks - ignore this trash */
+       etime = cur.cp_etime;
+       if ((etime * hertz) < 1.0) {    /* < 5 ticks - ignore this trash */
                if (failcnt++ >= MAXFAIL) {
                        clear();
                        mvprintw(2, 10, "The alternate system clock has died!");
@@ -350,7 +345,6 @@
                return;
        }
        failcnt = 0;
-       etime /= hertz;
        inttotal = 0;
        for (i = 0; i < nintr; i++) {
                if (s.intrcnt[i] == 0)
@@ -378,7 +372,7 @@
        psiz = 0;
        f2 = 0.0;
 
-       /* 
+       /*
         * Last CPU state not calculated yet.
         */
        for (c = 0; c < CPUSTATES; c++) {
@@ -523,10 +517,10 @@
 
        t = 0;
        for (i = 0; i < CPUSTATES; i++)
-               t += s.time[i];
+               t += cur.cp_time[i];
        if (t == 0.0)
                t = 1.0;
-       return (s.time[indx] * 100.0 / t);
+       return (cur.cp_time[indx] * 100.0 / t);
 }
 
 static void
@@ -572,7 +566,6 @@
        size_t size;
 
        dkreadstats();
-       (void) fetch_cptime(s->time);
        NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
        NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
        size = sizeof(s->uvmexp);
diff -r bd1d3a92ddc4 -r 9d99a00cb067 usr.bin/vmstat/dkstats.c
--- a/usr.bin/vmstat/dkstats.c  Sat Jun 29 23:54:05 2002 +0000
+++ b/usr.bin/vmstat/dkstats.c  Sun Jun 30 00:10:33 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.16 2002/06/30 00:10:34 sommerfeld 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);
diff -r bd1d3a92ddc4 -r 9d99a00cb067 usr.bin/vmstat/dkstats.h
--- a/usr.bin/vmstat/dkstats.h  Sat Jun 29 23:54:05 2002 +0000
+++ b/usr.bin/vmstat/dkstats.h  Sun Jun 30 00:10:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dkstats.h,v 1.4 2002/01/28 02:15:16 simonb Exp $       */
+/*     $NetBSD: dkstats.h,v 1.5 2002/06/30 00:10:34 sommerfeld Exp $   */
 
 /*
  * Copyright (c) 1996 John M. Vinopal
@@ -47,6 +47,8 @@
        u_int64_t         tk_nin;       /* TTY Chars in. */
        u_int64_t         tk_nout;      /* TTY Chars out. */
        u_int64_t         cp_time[CPUSTATES];   /* System timer ticks. */
+       int               cp_ncpu;              /* Number of cpu's */
+       double            cp_etime;             /* Elapsed time */
 };
 
 extern struct _disk    cur;
diff -r bd1d3a92ddc4 -r 9d99a00cb067 usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c   Sat Jun 29 23:54:05 2002 +0000
+++ b/usr.bin/vmstat/vmstat.c   Sun Jun 30 00:10:33 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.100 2002/03/13 11:02:11 simonb Exp $ */
+/* $NetBSD: vmstat.c,v 1.101 2002/06/30 00:10:34 sommerfeld Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 3/1/95";
 #else
-__RCSID("$NetBSD: vmstat.c,v 1.100 2002/03/13 11:02:11 simonb Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.101 2002/06/30 00:10:34 sommerfeld Exp $");
 #endif
 #endif /* not lint */
 
@@ -465,8 +465,8 @@
                                dohashstat(verbose, todo, hashname);
                                putchar('\n');
                        }
-               
-                       if (reps >= 0 && --reps <=0) 
+
+                       if (reps >= 0 && --reps <=0)
                                break;
                        sleep(interval);
                }
@@ -776,18 +776,13 @@
 void
 dkstats(void)
 {
-       int dn, state;
+       int dn;
        double etime;
 
        /* Calculate disk stat deltas. */
        dkswap();
-       etime = 0;
-       for (state = 0; state < CPUSTATES; ++state) {
-               etime += cur.cp_time[state];
-       }
-       if (etime == 0)
-               etime = 1;
-       etime /= hz;
+       etime = cur.cp_etime;
+
        for (dn = 0; dn < dk_ndrive; ++dn) {
                if (!dk_select[dn])
                        continue;
@@ -1204,7 +1199,7 @@
        int             hashsize;       /* nlist index for hash size */
        int             hashtbl;        /* nlist index for hash table */
        enum hashtype   type;           /* type of hash table */
-       size_t          offset;         /* offset of {LIST,TAILQ}_NEXT */ 
+       size_t          offset;         /* offset of {LIST,TAILQ}_NEXT */
 } khashes[] =
 {
        {
@@ -1250,7 +1245,7 @@
 
 void
 dohashstat(int verbose, int todo, const char *hashname)
-{ 
+{
        LIST_HEAD(, generic)    *hashtbl_list;
        TAILQ_HEAD(, generic)   *hashtbl_tailq;
        struct kernel_hash      *curhash;
@@ -1265,7 +1260,7 @@
        if (todo & HASHLIST) {
                printf("Supported hashes:\n");
                for (curhash = khashes; curhash->description; curhash++) {
-                       if (hashnl[curhash->hashsize].n_value == 0 || 
+                       if (hashnl[curhash->hashsize].n_value == 0 ||
                            hashnl[curhash->hashtbl].n_value == 0)
                                continue;
                        printf("\t%-16s%s\n",
@@ -1279,7 +1274,7 @@
                for (curhash = khashes; curhash->description; curhash++) {
                        if (strcmp(hashnl[curhash->hashsize].n_name + 1,
                            hashname) == 0 &&
-                           hashnl[curhash->hashsize].n_value != 0 && 
+                           hashnl[curhash->hashsize].n_value != 0 &&
                            hashnl[curhash->hashtbl].n_value != 0)
                                break;
                }
@@ -1297,7 +1292,7 @@
            "chain");
 
        for (curhash = khashes; curhash->description; curhash++) {
-               if (hashnl[curhash->hashsize].n_value == 0 || 
+               if (hashnl[curhash->hashsize].n_value == 0 ||
                    hashnl[curhash->hashtbl].n_value == 0)
                        continue;
                if (hashname != NULL &&
@@ -1316,13 +1311,13 @@
                        printf("%s %lu, %s %p, offset %ld, elemsize %llu\n",
                            hashnl[curhash->hashsize].n_name + 1, hashsize,
                            hashnl[curhash->hashtbl].n_name + 1, hashaddr,
-                           (long)curhash->offset, 
+                           (long)curhash->offset,
                            (unsigned long long)elemsize);
                thissize = hashsize * elemsize;
                if (thissize > hashbufsize) {
                        hashbufsize = thissize;
                        if ((hashbuf = realloc(hashbuf, hashbufsize)) == NULL)
-                               errx(1, "malloc hashbuf %llu", 
+                               errx(1, "malloc hashbuf %llu",



Home | Main Index | Thread Index | Old Index