summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2009-10-22 11:18:51 +0200
committerTobias Klauser <tklauser@distanz.ch>2009-10-22 11:18:51 +0200
commit4506e0cf4e4eba78d7685a4314a6882878cc9b66 (patch)
treef94ca9d2513537799e1241f0262ac347b9e36cfd
parent9f319ae55acb09d066d18639c823d8b9a4c2bff6 (diff)
Support for multiple CPU coresHEADmaster
-rw-r--r--statusbar.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/statusbar.c b/statusbar.c
index ba36dc8..81e37bf 100644
--- a/statusbar.c
+++ b/statusbar.c
@@ -3,19 +3,21 @@
*
* Needs libacpi-dev and libcpufreq-dev
*
- * Copyright (c) 2007 T. Klauser <tklauser@distanz.ch>
+ * Copyright (c) 2007-2009 T. Klauser <tklauser@distanz.ch>
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <time.h>
+
#include <sys/sysinfo.h>
#include <libacpi.h>
#include <cpufreq.h>
-#define DATE_STR "%a %Y-%m-%d %H:%M"
+#define DATE_STR "%Y-%m-%d %H:%M"
#define HOUR 3600 /* sec per hour */
#define MINUTE 60 /* sec per min */
#define LOADS_SCALE 65536.0
@@ -26,8 +28,7 @@ int main(int argc, char **argv)
struct tm tim;
char str[25];
int temp;
- unsigned long freq, tmp_freq;
- long up, uph, upm;
+ long i, n_cpu, up, uph, upm;
struct sysinfo info;
global_t g;
@@ -55,6 +56,7 @@ int main(int argc, char **argv)
else
printf("n/a%% | ");
+ /* TODO: Use sysfs! */
/* 3) Temperature */
temp = g.temperature;
if (temp < 0 || temp == NOT_SUPPORTED)
@@ -62,33 +64,38 @@ int main(int argc, char **argv)
else
printf("%d C | ", temp);
- /* 4) Current CPU frequency */
- freq = cpufreq_get_freq_kernel(0);
- if (freq) {
- /* Taken from cpufrequtils */
- if (freq > 1000000) {
- tmp_freq = freq % 10000;
- if (tmp_freq >= 5000)
- freq += 10000;
- printf("%u.%02u G", ((unsigned int) freq / 1000000),
- ((unsigned int) (freq % 1000000) / 10000));
- } else if (freq > 100000) {
- tmp_freq = freq % 1000;
- if (tmp_freq >= 500)
- freq += 1000;
- printf("%u M", ((unsigned int) freq / 1000));
- } else if (freq > 1000) {
- tmp_freq = freq % 100;
- if (tmp_freq >= 50)
- freq += 100;
- printf("%u.%01u M", ((unsigned int) freq / 1000),
- ((unsigned int) (freq % 1000) / 100));
- } else
- printf("%lu k", freq);
+ /* 4) Current CPU frequency for each core */
+ n_cpu = sysconf(_SC_NPROCESSORS_CONF);
+ for (i = 0; i < n_cpu; i++) {
+ unsigned long freq = cpufreq_get_freq_kernel(i);
- printf("Hz | ");
- } else
- printf("n/a | ");
+ if (freq) {
+ unsigned long tmp_freq;
+ /* Taken from cpufrequtils */
+ if (freq > 1000000) {
+ tmp_freq = freq % 10000;
+ if (tmp_freq >= 5000)
+ freq += 10000;
+ printf("%u.%02u G", ((unsigned int) freq / 1000000),
+ ((unsigned int) (freq % 1000000) / 10000));
+ } else if (freq > 100000) {
+ tmp_freq = freq % 1000;
+ if (tmp_freq >= 500)
+ freq += 1000;
+ printf("%u M", ((unsigned int) freq / 1000));
+ } else if (freq > 1000) {
+ tmp_freq = freq % 100;
+ if (tmp_freq >= 50)
+ freq += 100;
+ printf("%u.%01u M", ((unsigned int) freq / 1000),
+ ((unsigned int) (freq % 1000) / 100));
+ } else
+ printf("%lu k", freq);
+
+ printf("Hz | ");
+ } else
+ printf("n/a | ");
+ }
/* 5) Uptime and load average */
if (sysinfo(&info) == 0) {