Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/vmstat Use kern.clockrate if possible.



details:   https://anonhg.NetBSD.org/src/rev/750ef5b11be7
branches:  trunk
changeset: 329688:750ef5b11be7
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Jun 03 21:45:41 2014 +0000

description:
Use kern.clockrate if possible.

diffstat:

 usr.bin/vmstat/vmstat.c |  23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diffs (51 lines):

diff -r 66f73ca79d95 -r 750ef5b11be7 usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c   Tue Jun 03 21:41:56 2014 +0000
+++ b/usr.bin/vmstat/vmstat.c   Tue Jun 03 21:45:41 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.196 2014/06/03 21:41:56 joerg Exp $ */
+/* $NetBSD: vmstat.c,v 1.197 2014/06/03 21:45:41 joerg Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 3/1/95";
 #else
-__RCSID("$NetBSD: vmstat.c,v 1.196 2014/06/03 21:41:56 joerg Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.197 2014/06/03 21:45:41 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -322,6 +322,7 @@
 /* allow old usage [vmstat 1] */
 #define        BACKWARD_COMPATIBILITY
 
+static const int clockrate_mib[] = { CTL_KERN, KERN_CLOCKRATE };
 static const int vmmeter_mib[] = { CTL_VM, VM_METER };
 static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 };
 static const int boottime_mib[] = { CTL_KERN, KERN_BOOTTIME };
@@ -724,10 +725,20 @@
        halfuptime = uptime / 2;
        (void)signal(SIGCONT, needhdr);
 
-       if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0)
-               kread(namelist, X_STATHZ, &hz, sizeof(hz));
-       if (!hz)
-               kread(namelist, X_HZ, &hz, sizeof(hz));
+       if (memf != NULL) {
+               if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0)
+                       kread(namelist, X_STATHZ, &hz, sizeof(hz));
+               if (!hz)
+                       kread(namelist, X_HZ, &hz, sizeof(hz));
+       } else {
+               struct clockinfo clockinfo;
+               size = sizeof(clockinfo);
+               if (sysctl(clockrate_mib, 2, &clockinfo, &size, NULL, 0) == -1)
+                       err(1, "sysctl kern.clockrate failed");
+               hz = clockinfo.stathz;
+               if (!hz)
+                       hz = clockinfo.hz;
+       }
 
        kread(namelist, X_CPU_INFOS, &cpu_infos, sizeof(cpu_infos));
 



Home | Main Index | Thread Index | Old Index