#include "plugin.h"
#include "utils/common/common.h"
+#if KERNEL_FREEBSD
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
+#if KERNEL_LINUX
#define MAX_AVAIL_FREQS 20
static int num_cpu;
}
return;
}
+#endif /* KERNEL_LINUX */
static int cpufreq_init(void) {
+#if KERNEL_LINUX
char filename[PATH_MAX];
num_cpu = 0;
if (num_cpu == 0)
plugin_unregister_read("cpufreq");
+#elif KERNEL_FREEBSD
+ char mib[] = "dev.cpu.0.freq";
+ int cpufreq;
+ size_t cf_len = sizeof(cpufreq);
+
+ if(sysctlbyname(mib, &cpufreq, &cf_len, NULL, 0) != 0)
+ plugin_unregister_read("cpufreq");
+#endif
return 0;
} /* int cpufreq_init */
plugin_dispatch_values(&vl);
}
+#if KERNEL_LINUX
static void cpufreq_read_stats(int cpu) {
char filename[PATH_MAX];
/* Read total transitions for cpu frequency */
}
fclose(fh);
}
+#endif /* KERNEL_LINUX */
static int cpufreq_read(void) {
+#if KERNEL_LINUX
for (int cpu = 0; cpu < num_cpu; cpu++) {
char filename[PATH_MAX];
/* Read cpu frequency */
if (report_p_stats)
cpufreq_read_stats(cpu);
}
+#elif KERNEL_FREEBSD
+ /* FreeBSD currently only has 1 freq setting. See BUGS in cpufreq(4) */
+ char mib[] = "dev.cpu.0.freq";
+ int cpufreq;
+ size_t cf_len = sizeof(cpufreq);
+
+ if(sysctlbyname(mib, &cpufreq, &cf_len, NULL, 0) != 0) {
+ WARNING("cpufreq plugin: reading \"%s\" failed.", mib);
+ return 0;
+ }
+
+ value_t v;
+ /* convert Mhz to Hz */
+ v.gauge = cpufreq * 1000000.0;
+
+ cpufreq_submit(0, "cpufreq", NULL, &v);
+#endif
return 0;
} /* int cpufreq_read */