From 65e8b46fddab5ef4c253806a134d9c4d06572a99 Mon Sep 17 00:00:00 2001 From: brooks_en_davis Date: Thu, 26 May 2011 15:12:23 +0000 Subject: [PATCH] Catch up with local patches to the FreeBSD port: - Use the hw.freq.cpu sysctl to obtain cpu frequency where available. - Ignore idle or dying threads when counting running processes. [0] Submitted by: KOIE Hidetaka [0] --- libmetrics/freebsd/metrics.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libmetrics/freebsd/metrics.c b/libmetrics/freebsd/metrics.c index b5cf0a5f3..892e8b640 100644 --- a/libmetrics/freebsd/metrics.c +++ b/libmetrics/freebsd/metrics.c @@ -164,9 +164,21 @@ cpu_speed_func ( void ) size_t len; uint32_t freq = 0, tmpfreq; uint64_t tscfreq; + unsigned int cpu_freq; /* - * If the system supports it, the cpufreq driver provides the best + * Try the portable sysctl (introduced on ia64). + */ + cpu_freq = 0; + len = sizeof(cpu_freq); + if (sysctlbyname("hw.freq.cpu", &cpu_freq, &len, NULL, 0) != -1 && + cpu_freq != 0) { + freq = cpu_freq; + goto done; + } + + /* + * If the system supports it, the cpufreq driver provides * access to CPU frequency. Since we want a constant value, we're * looking for the maximum frequency, not the current one. We * don't know what order the driver will report values in so we @@ -523,6 +535,17 @@ proc_run_func( void ) goto output; for (i = 0; i < nentries; kp++, i++) { + /* This is a per-CPU idle thread. */ /* idle thread */ + if ((kp->ki_tdflags & TDF_IDLETD) != 0) + continue; + /* Ignore during load avg calculations. */ /* swi or idle thead */ +#ifdef TDF_NOLOAD + /* Introduced in FreeBSD 8.3 */ + if ((kp->ki_tdflags & TDF_NOLOAD) != 0) +#else + if ((kp->ki_flag & P_NOLOAD) != 0) +#endif + continue; #ifdef KINFO_PROC_SIZE state = kp->ki_stat; #else