[netperf-talk] FreeBSD sysctl cpu utilization diffs

Andrew Gallatin gallatin at cs.duke.edu
Fri Apr 14 14:05:51 PDT 2006


Rick Jones writes:
 > Andrew Gallatin wrote:
 > > 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.
 > 
 > If the mechanism is what I think it was, basically, the idea was to 
 > compare how fast something increments when the system is "idle" vs when 
 > the system is running netperf.  Hence the calibration period.

The clock will always tick at stathz, so the calibration is not needed.
The FreeBSD people are very picky about accurate timekeeping and
accounting.

 > > 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.
 > 
 > That just shows they haven't gotten to very high CPU counts yet :)

Yeah, I imagine they'll keep it per-cpu and add it at sysctl
time eventually.  They've apparently ported to ontario/niagara,
so that's 32 CPUs.


 > >  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).
 > 
 > Since they are likely using the same mechanism I would hope so :)

Just wanted to show that I've tested on 64/32 bit and SMP/up..
 
 > What does it look like compared to the looper method?  One of the 
 > concerns I have about all these "statistical" sampling methods is 
 > whether or not they remain accurate under a very high interrupt load 
 > such as that produced by netperf.

Looper does not seem to compile in 2.4.1, so it is hard to say. :(


 > Not that some of the non-statistical mechanisms upon which netperf 
 > relies are golden either.

:)

 > > 
 > > 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.
 > 
 > For a CPU method that requires no calibration, it doesn't really matter 
 > what is returned.

Cool.  That's what I thought.

BTW, should I be using netperf4 from svn and submitting patches against
that?  Or is there still life in the 2.x series?

BTW, I *love* the CPU binding for linux in 2.4!

Drew


More information about the netperf-talk mailing list