From 6d3dc8fce0401da24ad45593e4eb9a68e2cde297 Mon Sep 17 00:00:00 2001 From: Udo Schläpfer Date: Sat, 13 Dec 2014 20:45:03 +0100 Subject: iBasso DX50/DX90: CPU info enhancements. System -> Debug (Keep Out) -> View CPU stats Will now show the current cpufreq scaling governor, minimum, current and maximum cpufreq scaling frequency for each CPU. This may be genric for Android kernel based devices but is only enabled for iBasso Devices. Other maintainers may choose do adopt this. Change-Id: I53e212f8707bf2abaa557e297293fb559ac37058 --- firmware/target/hosted/cpuinfo-linux.c | 134 ++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) (limited to 'firmware/target/hosted/cpuinfo-linux.c') diff --git a/firmware/target/hosted/cpuinfo-linux.c b/firmware/target/hosted/cpuinfo-linux.c index e0a6bd76da..8158673349 100644 --- a/firmware/target/hosted/cpuinfo-linux.c +++ b/firmware/target/hosted/cpuinfo-linux.c @@ -35,8 +35,14 @@ #include "cpuinfo-linux.h" #include "gcc_extensions.h" +#if defined(DX50) || defined(DX90) +#include +#include +#include "debug.h" +#endif + #undef open /* want the *real* open here, not sim_open or the like */ -#if (CONFIG_PLATFORM & PLATFORM_ANDROID) +#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(DX50) || defined(DX90) #include "cpu-features.h" #define get_nprocs android_getCpuCount #endif @@ -154,6 +160,132 @@ int frequency_linux(int cpu, bool scaling) return ret; } +#if defined(DX50) || defined(DX90) +bool current_scaling_governor(int cpu, char* governor, int governor_size) +{ + if((cpu < 0) || (governor == NULL) || (governor_size <= 0)) + { + return false; + } + + char path[PATH_MAX]; + snprintf(path, + sizeof(path), + "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", + cpu); + FILE *f = fopen(path, "r"); + if(f == NULL) + { + DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path); + return false; + } + + if(fgets(governor, governor_size, f) == NULL) + { + DEBUGF("ERROR %s: Read failed for %s.", __func__, path); + fclose(f); + return false; + } + + if(strlen(governor) > 0) + { + governor[strlen(governor) - 1] = '\0'; + } + + fclose(f); + return true; +} + + +enum cpu_frequency_options +{ + SCALING_MIN_FREQ = 0, + SCALING_CUR_FREQ, + SCALING_MAX_FREQ +}; + + +static int read_cpu_frequency(int cpu, enum cpu_frequency_options freqOpt) +{ + if(cpu < 0) + { + return -1; + } + + char path[PATH_MAX]; + switch(freqOpt) + { + case SCALING_MIN_FREQ: + { + snprintf(path, + PATH_MAX, + "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", + cpu); + break; + } + + case SCALING_CUR_FREQ: + { + snprintf(path, + PATH_MAX, + "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", + cpu); + break; + } + + case SCALING_MAX_FREQ: + { + snprintf(path, + PATH_MAX, + "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", + cpu); + break; + } + + default: + { + DEBUGF("ERROR %s: Unknown CpuFrequencyOptions: %d.", __func__, freqOpt); + return -1; + } + } + + FILE *f = fopen(path, "r"); + if(f == NULL) + { + DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path); + return -1; + } + + int freq; + if(fscanf(f, "%d", &freq) == EOF) + { + DEBUGF("ERROR %s: Read failed for %s.", __func__, path); + freq = -1; + } + + fclose(f); + return(freq); +} + + +int min_scaling_frequency(int cpu) +{ + return(read_cpu_frequency(cpu, SCALING_MIN_FREQ)); +} + + +int current_scaling_frequency(int cpu) +{ + return(read_cpu_frequency(cpu, SCALING_CUR_FREQ)); +} + + +int max_scaling_frequency(int cpu) +{ + return(read_cpu_frequency(cpu, SCALING_MAX_FREQ)); +} +#endif + int cpustatetimes_linux(int cpu, struct time_state* data, int max_elements) { int elements_left = max_elements, cpu_dev; -- cgit v1.2.3