summaryrefslogtreecommitdiff
path: root/components/cpu.c
diff options
context:
space:
mode:
authorAaron Marcher <me@drkhsh.at>2018-05-19 23:58:14 +0200
committerAaron Marcher <me@drkhsh.at>2018-05-19 23:58:14 +0200
commit0bc6855741cc9fbdf5c3ffd0d9cb983b0a66f635 (patch)
tree004ad4c757a5160c5f93b5e1c33cb7ed5a78fcda /components/cpu.c
parent46c4540dd2f6181e77b0800a4e007d78d0162487 (diff)
Implement scaling for cpu_freq
Diffstat (limited to 'components/cpu.c')
-rw-r--r--components/cpu.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/components/cpu.c b/components/cpu.c
index e333f97..2e910d9 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -6,14 +6,21 @@
#include "../util.h"
#if defined(__linux__)
+ #include <inttypes.h>
+ #include <stdint.h>
+
const char *
cpu_freq(void)
{
- int freq;
+ uint64_t freq;
+
+ /* in kHz */
+ if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
+ "%"SCNu64, &freq) != 1) {
+ return NULL;
+ }
- return (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
- "%d", &freq) == 1) ?
- bprintf("%d", (freq + 500) / 1000) : NULL;
+ return fmt_human_10(freq * 1000, "Hz");
}
const char *
@@ -56,12 +63,13 @@
size = sizeof(freq);
+ /* in MHz */
if (sysctl(mib, 2, &freq, &size, NULL, 0) < 0) {
warn("sysctl 'HW_CPUSPEED':");
return NULL;
}
- return bprintf("%d", freq);
+ return fmt_human_10((size_t)freq * 1000 * 1000, "Hz");
}
const char *