[hackers] [slstatus] Implement scaling for cpu_freq || Aaron Marcher

From: <git_AT_suckless.org>
Date: Sat, 19 May 2018 23:58:35 +0200 (CEST)

commit 0bc6855741cc9fbdf5c3ffd0d9cb983b0a66f635
Author: Aaron Marcher <me_AT_drkhsh.at>
AuthorDate: Sat May 19 23:58:14 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Sat May 19 23:58:14 2018 +0200

    Implement scaling for cpu_freq

diff --git a/components/cpu.c b/components/cpu.c
index e333f97..2e910d9 100644
--- a/components/cpu.c
+++ b/components/cpu.c
_AT_@ -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 *
_AT_@ -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 *
Received on Sat May 19 2018 - 23:58:35 CEST

This archive was generated by hypermail 2.3.0 : Sun May 20 2018 - 00:00:29 CEST