Introduction
Introduction Statistics Contact Development Disclaimer Help
Report frequency of CPU0 in Linux - spoon - set dwm status
git clone git://git.codemadness.org/spoon
Log
Files
Refs
LICENSE
---
commit 07f66ef7d3e6f3456bcdf7078e1d1a012c36922a
parent 311f1ed9305fbaadc78ecd85c50e3b2df87e5567
Author: lostd <[email protected]>
Date: Wed, 2 Nov 2016 16:00:54 +0100
Report frequency of CPU0 in Linux
Diffstat:
M Makefile | 3 ++-
M cpu.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/Makefile b/Makefile
@@ -13,7 +13,8 @@ CPPFLAGS_OpenBSD = -I/usr/X11R6/include -I/usr/local/include
LDFLAGS_OpenBSD = -L/usr/X11R6/lib -L/usr/local/lib
CPPFLAGS_Linux = -DPATH_BAT_CAP=\"/sys/class/power_supply/BAT0/capacity\"\
-DPATH_AC_ONLINE=\"/sys/class/power_supply/AC/online\"\
- -DPATH_TEMP=\"/sys/class/hwmon/hwmon0/temp1_input\"
+ -DPATH_TEMP=\"/sys/class/hwmon/hwmon0/temp1_input\"\
+ -DPATH_CPU_FREQ=\"/sys/devices/system/cpu/cpu0/cpufreq/scalin…
CPPFLAGS = $(CPPFLAGS_$(UNAME))
LDFLAGS = $(LDFLAGS_$(UNAME))
LDLIBS = -lX11
diff --git a/cpu.c b/cpu.c
@@ -1,3 +1,4 @@
+#include <err.h>
#include <stdio.h>
#ifdef __OpenBSD__
@@ -17,4 +18,22 @@ cpuread(void *arg, char *buf, size_t len)
snprintf(buf, len, "%4dMHz", cpuspeed);
return 0;
}
+#elif __linux__
+int
+cpuread(void *arg, char *buf, size_t len)
+{
+ FILE *fp;
+ int freq;
+
+ fp = fopen(PATH_CPU_FREQ, "r");
+ if (fp == NULL) {
+ warn("fopen %s", PATH_CPU_FREQ);
+ return -1;
+ }
+ fscanf(fp, "%d", &freq);
+ fclose(fp);
+ freq /= 1000;
+ snprintf(buf, len, "%4dMHz", freq);
+ return 0;
+}
#endif
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.