[netperf-talk] FreeBSD sysctl cpu utilization diffs

Andrew Gallatin gallatin at cs.duke.edu
Fri Apr 14 13:21:49 PDT 2006


I use the attached patch to netperf 2.4.1 to measure cpu utilization
on FreeBSD.  The existing method in 2.2.4 and 2.4.1 confused me, and I
did not want to wait for a calibration period.

The FreeBSD kern.cp_time is quite simple.  It returns a copy of an
array of counters maintained by the kernel.  One of these counters is
incremented stathz times per second on each processor.  The choice of
counter (user, nice, sys, intr, idle) depends on the state of the CPU
when the stathz clock tick happens.  This array is global (not
per-CPU) and is protected by a spinlock in SMP versions of the FreeBSD
kernel.  See the statclock() routine in sys/kern/kern_clock.c
(http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_clock.c?rev=1.187&content-type=text/x-cvsweb-markup)

The patch simply takes a snapshot of the counters when the test
starts, another snapshot when the test ends, and caclulates the 
CPU utilization by figuring out how much idle time there was as
compared to the other, non-idle CPU states.

I have tested my patch on FreeBSD 5.4 i386 UP, 6.0 i386 SMP, and
7.0 amd64 SMP and the CPU time reported by netperf agrees with
the CPU time reported by the FreeBSD CPU monitoring tools (vmstat,
systat -vm, iostat).

I was not sure what calibrate_idle_rate() should return.  As a
stopgap, I had it return sysconf(_SC_CLK_TCK); like the linux
procstat code, but I have no idea if that is correct, or if
it even matters.  I suspect that I just need to return a non-zero
value.

Thanks for listening,

Drew

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sysctl.diff
Type: application/octet-stream
Size: 7139 bytes
Desc: freebsd sysctl support for 2.4.1
Url : http://www.netperf.org/pipermail/netperf-talk/attachments/20060414/62f797e3/sysctl.obj


More information about the netperf-talk mailing list