summaryrefslogtreecommitdiff
path: root/nacl/cpucycles/osfreq.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/cpucycles/osfreq.c')
-rw-r--r--nacl/cpucycles/osfreq.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/nacl/cpucycles/osfreq.c b/nacl/cpucycles/osfreq.c
new file mode 100644
index 00000000..4e106a23
--- /dev/null
+++ b/nacl/cpucycles/osfreq.c
@@ -0,0 +1,65 @@
1static double osfreq(void)
2{
3 FILE *f;
4 double result;
5 int s;
6
7 f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r");
8 if (f) {
9 s = fscanf(f,"%lf",&result);
10 fclose(f);
11 if (s > 0) return 1000.0 * result;
12 }
13
14 f = fopen("/sys/devices/system/cpu/cpu0/clock_tick", "r");
15 if (f) {
16 s = fscanf(f,"%lf",&result);
17 fclose(f);
18 if (s > 0) return result;
19 }
20
21 f = fopen("/proc/cpuinfo","r");
22 if (f) {
23 for (;;) {
24 s = fscanf(f,"cpu MHz : %lf",&result);
25 if (s > 0) break;
26 if (s == 0) s = fscanf(f,"%*[^\n]\n");
27 if (s < 0) { result = 0; break; }
28 }
29 fclose(f);
30 if (result) return 1000000.0 * result;
31 }
32
33 f = fopen("/proc/cpuinfo","r");
34 if (f) {
35 for (;;) {
36 s = fscanf(f,"clock : %lf",&result);
37 if (s > 0) break;
38 if (s == 0) s = fscanf(f,"%*[^\n]\n");
39 if (s < 0) { result = 0; break; }
40 }
41 fclose(f);
42 if (result) return 1000000.0 * result;
43 }
44
45 f = popen("/usr/sbin/lsattr -E -l proc0 -a frequency 2>/dev/null","r");
46 if (f) {
47 s = fscanf(f,"frequency %lf",&result);
48 pclose(f);
49 if (s > 0) return result;
50 }
51
52 f = popen("/usr/sbin/psrinfo -v 2>/dev/null","r");
53 if (f) {
54 for (;;) {
55 s = fscanf(f," The %*s processor operates at %lf MHz",&result);
56 if (s > 0) break;
57 if (s == 0) s = fscanf(f,"%*[^\n]\n");
58 if (s < 0) { result = 0; break; }
59 }
60 pclose(f);
61 if (result) return 1000000.0 * result;
62 }
63
64 return 0;
65}