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.zip
rockbox-925dacf96dca1ca09c58024df2e41aaea524c722.tar.gz
rockbox-925dacf96dca1ca09c58024df2e41aaea524c722.tar.bz2
rockbox-925dacf96dca1ca09c58024df2e41aaea524c722.tar.xz
*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 3404071..d31bf2b 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,
{
int cpu = (selected_item - 5) / (state_count + 1);
int cpu_line = (selected_item - 5) % (state_count + 1);
- int freq1 = cpufrequency_linux(cpu);
- int freq2 = scalingfrequency_linux(cpu);
+ int freq1 = frequency_linux(cpu, false);
+ int freq2 = frequency_linux(cpu, true);
if (cpu_line == 0)
{
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 70d0e25..e0a6bd7 100644
--- a/firmware/target/hosted/cpuinfo-linux.c
+++ b/firmware/target/hosted/cpuinfo-linux.c
@@ -3,7 +3,7 @@
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
@@ -137,27 +137,14 @@ int cpucount_linux(void)
return get_nprocs();
}
-int cpufrequency_linux(int cpu)
+int frequency_linux(int cpu, bool scaling)
{
char path[64];
char temp[10];
int cpu_dev, ret = -1;
- snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", cpu);
- cpu_dev = open(path, O_RDONLY);
- if (cpu_dev < 0)
- return -1;
- if (read(cpu_dev, temp, sizeof(temp)) >= 0)
- ret = atoi(temp);
- close(cpu_dev);
- return ret;
-}
-
-int scalingfrequency_linux(int cpu)
-{
- char path[64];
- char temp[10];
- int cpu_dev, ret = -1;
- snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu);
+ snprintf(path, sizeof(path),
+ "/sys/devices/system/cpu/cpu%d/cpufreq/%s_cur_freq",
+ cpu, scaling ? "scaling" : "cpuinfo");
cpu_dev = open(path, O_RDONLY);
if (cpu_dev < 0)
return -1;
diff --git a/firmware/target/hosted/cpuinfo-linux.h b/firmware/target/hosted/cpuinfo-linux.h
index d9ba376..ebc05d5 100644
--- a/firmware/target/hosted/cpuinfo-linux.h
+++ b/firmware/target/hosted/cpuinfo-linux.h
@@ -1,10 +1,10 @@
/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2011 Thomas Martitz
@@ -23,6 +23,8 @@
#ifndef __CPUINFO_LINUX_H__
#define __CPUINFO_LINUX_H__
+#include <stdbool.h>
+
struct cpuusage {
long usage; /* in hundredth percent */
long utime; /* in clock ticks */
@@ -37,8 +39,7 @@ struct time_state {
};
int cpuusage_linux(struct cpuusage* u);
-int cpufrequency_linux(int cpu);
-int scalingfrequency_linux(int cpu);
+int frequency_linux(int cpu, bool scaling);
int cpustatetimes_linux(int cpu, struct time_state* data, int max_elements);
int cpucount_linux(void);