Re: Patch for really fixing bsnmpd hrProcessorLoad values

From: Ulrich Spörlein <uqs_at_spoerlein.net>
Date: Wed, 9 Jun 2010 18:09:25 +0200
On Wed, 09.06.2010 at 14:49:10 +0200, Gustau Pérez wrote:
> En/na Ulrich Spörlein ha escrit:
> > Hi guys,
> >
> > I finally got fed up with bsnmpd no longer returning the right CPU load
> > values when running under ULE. After taking a look at how top(1) does
> > it, I came up with the following initial patch to bsnmpd, that seems to
> > DTRT.
> >
> > A few technical questions remain:
> >
> > - Is the idle state guaranteed to always be in the last cp_time column?
> > - Is handling overflow of kern.cp_times worth it? There's only a 60s
> >   window of reporting wrong stats, better than what we have now anyway.
> > - Why is kern.cp_times often times *way* longer than hw.ncpu *
> >   CPUSTATES? Is it guaranteed that the first n entries correspond to the
> >   first n*CPUSTATES values in kern.cp_times? Can there be holes?
> >
> > Patch has been tested on 8-STABLE, 4xCPUs and SCHED_ULE. Other reports
> > would be very much appreciated.
> >
> > Regards,
> > Uli
> >
>   Hi Uli,
> 
>   I've just recompiled a RELENG_8_0 kernel, with SCHED_ULE, 2xQuad
> Core and your patch applied to /usr/src. I get 0 values for all
> processors :
> 
> *****************************************************************************
> 
> [root_at_host ~]# snmpwalk -v 2c -c host IP_HOST | grep hrProcessor
> HOST-RESOURCES-MIB::hrProcessorFrwID.6 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.10 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.14 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.18 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.22 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.26 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.30 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorFrwID.34 = OID: SNMPv2-SMI::zeroDotZero
> HOST-RESOURCES-MIB::hrProcessorLoad.6 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.10 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.14 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.18 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.22 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.26 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.30 = INTEGER: 0
> HOST-RESOURCES-MIB::hrProcessorLoad.34 = INTEGER: 0
> HOST-RESOURCES-MIB::hrSWRunParameters.3655 = STRING: "hrProcessor"
> [root_at_host ~]# uname -arn
> FreeBSD host 8.0-RELEASE-p3 FreeBSD 8.0-RELEASE-p3 #2: Wed Jun  9
> 14:23:16 CEST 2010     root_at_host:/usr/obj/usr/src/sys/CUSTOM  i386
> 
> *****************************************************************************
> 
>    If time permits I may try it in CURRENT. But I don't know when I'll
> be able ...
>  
>    Did I do anything wrong ? I applied the patch, recompiled and
> reinstalled $SRC/usr.sbin/bsnmpd, recompiled $PORTS/net-mngt/bsnmp-ucd
> (just in case) and then recompiled and reinstalled the kernel with ULE
> (I was keeping 4BSD, because hrProcessorLoad used to work only with
> 4BSD).

Hello Gustau,

thanks for testing this. I should have mentioned, that bsnmpd needs at
least 30s to gather enough samples for the CPU load. If you still don't
see anything after that, then that's my fault.

Please also make sure you have some load going on. I recommend running

# cpuset -c -l 0 /bin/sh
# while :; do:; done

which will spin while being stuck to CPU 0. If you still don't see
anything, please run bsnmpd in the foreground like this:

# bsnmpd -d -Devents

and you should see debugging output like that:

HRDEBUG: processor_refill_tbl: hw_ncpu=4 detected_processor_count=4
HRDEBUG: save_sample: CPU no. 0 state 0 value 752372
HRDEBUG: save_sample: CPU no. 0 state 1 value 1188915
HRDEBUG: save_sample: CPU no. 0 state 2 value 469569
HRDEBUG: save_sample: CPU no. 0 state 3 value 3115
HRDEBUG: save_sample: CPU no. 0 state 4 value 81501078
HRDEBUG: get_avg_usage: CPU no. 0 delta ticks 6003 pct usage 0.18

Please also provide me with the output of:

# sysctl kern.boottime kern.cp_times hw.ncpu

Thanks!
Uli
Received on Wed Jun 09 2010 - 14:09:29 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:04 UTC