Skip to content

Commit

Permalink
Catch up with local patches to the FreeBSD port:
Browse files Browse the repository at this point in the history
 - 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 <koie at suri.co.jp> [0]
  • Loading branch information
brooks_en_davis committed May 26, 2011
1 parent 8b32041 commit 65e8b46
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion libmetrics/freebsd/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 65e8b46

Please sign in to comment.