kern.cp_time - Add convenience defines
authorSamuel J. Greear <sjg@thesjg.com>
Fri, 30 Mar 2012 03:27:09 +0000 (21:27 -0600)
committerSamuel J. Greear <sjg@thesjg.com>
Fri, 30 Mar 2012 03:27:09 +0000 (21:27 -0600)
* Add convenience defines for indexes of the array returned by the kern.cp_time
  sysctl.

* This sync's us with FreeBSD and should un-break and couple of pkgsrc
  packages.

sys/kern/kern_clock.c
sys/sys/resource.h

index 60408ce..a581a49 100644 (file)
@@ -85,6 +85,7 @@
 #include <sys/kinfo.h>
 #include <sys/proc.h>
 #include <sys/malloc.h>
+#include <sys/resource.h>
 #include <sys/resourcevar.h>
 #include <sys/signalvar.h>
 #include <sys/timex.h>
@@ -164,11 +165,11 @@ sysctl_cp_time(SYSCTL_HANDLER_ARGS)
        size_t size = sizeof(cpu_states);
 
        for (cpu = 0; cpu < ncpus; ++cpu) {
-               cpu_states[0] += cputime_percpu[cpu].cp_user;
-               cpu_states[1] += cputime_percpu[cpu].cp_nice;
-               cpu_states[2] += cputime_percpu[cpu].cp_sys;
-               cpu_states[3] += cputime_percpu[cpu].cp_intr;
-               cpu_states[4] += cputime_percpu[cpu].cp_idle;
+               cpu_states[CP_USER] += cputime_percpu[cpu].cp_user;
+               cpu_states[CP_NICE] += cputime_percpu[cpu].cp_nice;
+               cpu_states[CP_SYS] += cputime_percpu[cpu].cp_sys;
+               cpu_states[CP_INTR] += cputime_percpu[cpu].cp_intr;
+               cpu_states[CP_IDLE] += cputime_percpu[cpu].cp_idle;
        }
 
        error = SYSCTL_OUT(req, cpu_states, size);
index f1bc46c..15d9559 100644 (file)
@@ -136,12 +136,21 @@ struct rlimit {
        rlim_t  rlim_max;               /* maximum value for rlim_cur */
 };
 
-/* Load average structure. */
 struct loadavg {
        fixpt_t ldavg[3];
        long    fscale;
 };
 
+/*
+ * CPU state fields as reported by the sysctl kern.cp_time
+ */
+#define CP_USER         0
+#define CP_NICE         1
+#define CP_SYS          2
+#define CP_INTR         3
+#define CP_IDLE         4
+#define CPUSTATES       5
+
 #ifdef _KERNEL
 extern struct loadavg averunnable;