summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2012-01-04 00:34:02 +0000
committerRafaël Carré <rafael.carre@gmail.com>2012-01-04 00:34:02 +0000
commit925dacf96dca1ca09c58024df2e41aaea524c722 (patch)
tree361dfcdda7d2b095b70b46401c1d3b507cf93261
parentd07c1d57a4c54c5154036192a563a4a4fcaa6eac (diff)
downloadrockbox-925dacf96dca1ca09c58024df2e41aaea524c722.tar.gz
rockbox-925dacf96dca1ca09c58024df2e41aaea524c722.zip
*frequency_linux(): factorize
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31555 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c4
-rw-r--r--firmware/target/hosted/cpuinfo-linux.c23
-rw-r--r--firmware/target/hosted/cpuinfo-linux.h17
3 files changed, 16 insertions, 28 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 340407176c..d31bf2bf6b 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -285,8 +285,8 @@ static const char* get_cpuinfo(int selected_item, void *data,
285 { 285 {
286 int cpu = (selected_item - 5) / (state_count + 1); 286 int cpu = (selected_item - 5) / (state_count + 1);
287 int cpu_line = (selected_item - 5) % (state_count + 1); 287 int cpu_line = (selected_item - 5) % (state_count + 1);
288 int freq1 = cpufrequency_linux(cpu); 288 int freq1 = frequency_linux(cpu, false);
289 int freq2 = scalingfrequency_linux(cpu); 289 int freq2 = frequency_linux(cpu, true);
290 if (cpu_line == 0) 290 if (cpu_line == 0)
291 { 291 {
292 sprintf(buffer, " CPU%d: Cur/Scal freq: %d/%d MHz", cpu, 292 sprintf(buffer, " CPU%d: Cur/Scal freq: %d/%d MHz", cpu,
diff --git a/firmware/target/hosted/cpuinfo-linux.c b/firmware/target/hosted/cpuinfo-linux.c
index 70d0e25139..e0a6bd76da 100644
--- a/firmware/target/hosted/cpuinfo-linux.c
+++ b/firmware/target/hosted/cpuinfo-linux.c
@@ -3,7 +3,7 @@
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
@@ -137,27 +137,14 @@ int cpucount_linux(void)
137 return get_nprocs(); 137 return get_nprocs();
138} 138}
139 139
140int cpufrequency_linux(int cpu) 140int frequency_linux(int cpu, bool scaling)
141{ 141{
142 char path[64]; 142 char path[64];
143 char temp[10]; 143 char temp[10];
144 int cpu_dev, ret = -1; 144 int cpu_dev, ret = -1;
145 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", cpu); 145 snprintf(path, sizeof(path),
146 cpu_dev = open(path, O_RDONLY); 146 "/sys/devices/system/cpu/cpu%d/cpufreq/%s_cur_freq",
147 if (cpu_dev < 0) 147 cpu, scaling ? "scaling" : "cpuinfo");
148 return -1;
149 if (read(cpu_dev, temp, sizeof(temp)) >= 0)
150 ret = atoi(temp);
151 close(cpu_dev);
152 return ret;
153}
154
155int scalingfrequency_linux(int cpu)
156{
157 char path[64];
158 char temp[10];
159 int cpu_dev, ret = -1;
160 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu);
161 cpu_dev = open(path, O_RDONLY); 148 cpu_dev = open(path, O_RDONLY);
162 if (cpu_dev < 0) 149 if (cpu_dev < 0)
163 return -1; 150 return -1;
diff --git a/firmware/target/hosted/cpuinfo-linux.h b/firmware/target/hosted/cpuinfo-linux.h
index d9ba376f49..ebc05d5c43 100644
--- a/firmware/target/hosted/cpuinfo-linux.h
+++ b/firmware/target/hosted/cpuinfo-linux.h
@@ -1,10 +1,10 @@
1/*************************************************************************** 1/***************************************************************************
2 * __________ __ ___. 2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2011 Thomas Martitz 10 * Copyright (C) 2011 Thomas Martitz
@@ -23,6 +23,8 @@
23#ifndef __CPUINFO_LINUX_H__ 23#ifndef __CPUINFO_LINUX_H__
24#define __CPUINFO_LINUX_H__ 24#define __CPUINFO_LINUX_H__
25 25
26#include <stdbool.h>
27
26struct cpuusage { 28struct cpuusage {
27 long usage; /* in hundredth percent */ 29 long usage; /* in hundredth percent */
28 long utime; /* in clock ticks */ 30 long utime; /* in clock ticks */
@@ -37,8 +39,7 @@ struct time_state {
37}; 39};
38 40
39int cpuusage_linux(struct cpuusage* u); 41int cpuusage_linux(struct cpuusage* u);
40int cpufrequency_linux(int cpu); 42int frequency_linux(int cpu, bool scaling);
41int scalingfrequency_linux(int cpu);
42int cpustatetimes_linux(int cpu, struct time_state* data, int max_elements); 43int cpustatetimes_linux(int cpu, struct time_state* data, int max_elements);
43int cpucount_linux(void); 44int cpucount_linux(void);
44 45