projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
00d5fc4
)
Add FreeBSD support for cpufreq
author
Marco van Tol
<marco@tols.org>
Tue, 23 Apr 2019 15:45:54 +0000
(17:45 +0200)
committer
Marco van Tol
<marco@tols.org>
Tue, 23 Apr 2019 15:45:54 +0000
(17:45 +0200)
configure.ac
patch
|
blob
|
history
src/cpufreq.c
patch
|
blob
|
history
diff --git
a/configure.ac
b/configure.ac
index
5df84b6
..
f6f9acb
100644
(file)
--- a/
configure.ac
+++ b/
configure.ac
@@
-6518,6
+6518,7
@@
fi
# FreeBSD
if test "x$ac_system" = "xFreeBSD"; then
# FreeBSD
if test "x$ac_system" = "xFreeBSD"; then
+ plugin_cpufreq="yes"
plugin_disk="yes"
plugin_zfs_arc="yes"
fi
plugin_disk="yes"
plugin_zfs_arc="yes"
fi
diff --git
a/src/cpufreq.c
b/src/cpufreq.c
index
35ec07f
..
0f6cd32
100644
(file)
--- a/
src/cpufreq.c
+++ b/
src/cpufreq.c
@@
-25,6
+25,12
@@
#include "plugin.h"
#include "utils/common/common.h"
#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;
#define MAX_AVAIL_FREQS 20
static int num_cpu;
@@
-71,8
+77,10
@@
static void cpufreq_stats_init(void) {
}
return;
}
}
return;
}
+#endif /* KERNEL_LINUX */
static int cpufreq_init(void) {
static int cpufreq_init(void) {
+#if KERNEL_LINUX
char filename[PATH_MAX];
num_cpu = 0;
char filename[PATH_MAX];
num_cpu = 0;
@@
-96,6
+104,14
@@
static int cpufreq_init(void) {
if (num_cpu == 0)
plugin_unregister_read("cpufreq");
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 */
return 0;
} /* int cpufreq_init */
@@
-116,6
+132,7
@@
static void cpufreq_submit(int cpu_num, const char *type,
plugin_dispatch_values(&vl);
}
plugin_dispatch_values(&vl);
}
+#if KERNEL_LINUX
static void cpufreq_read_stats(int cpu) {
char filename[PATH_MAX];
/* Read total transitions for cpu frequency */
static void cpufreq_read_stats(int cpu) {
char filename[PATH_MAX];
/* Read total transitions for cpu frequency */
@@
-184,8
+201,10
@@
static void cpufreq_read_stats(int cpu) {
}
fclose(fh);
}
}
fclose(fh);
}
+#endif /* KERNEL_LINUX */
static int cpufreq_read(void) {
static int cpufreq_read(void) {
+#if KERNEL_LINUX
for (int cpu = 0; cpu < num_cpu; cpu++) {
char filename[PATH_MAX];
/* Read cpu frequency */
for (int cpu = 0; cpu < num_cpu; cpu++) {
char filename[PATH_MAX];
/* Read cpu frequency */
@@
-206,6
+225,23
@@
static int cpufreq_read(void) {
if (report_p_stats)
cpufreq_read_stats(cpu);
}
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 */
return 0;
} /* int cpufreq_read */