diff options
author | Kelvin Cheung <keguang.zhang@gmail.com> | 2017-08-23 17:00:58 +0800 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2017-09-15 18:31:12 +0300 |
commit | e1c46f8e296a730ed27141a33189185bb7dfd1b1 (patch) | |
tree | 115ae1de9b1c0ae123b1d00326c88b7e497fcda3 /platform | |
parent | 054306373ed6aa7a65a160d11ca339b24cf9c662 (diff) |
linux-gen: system: correctly set CPU frequency
When CPU frequency info under /sys is available,
use the real value instead of default value.
Signed-off-by: Kelvin Cheung <keguang.zhang@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
7 files changed, 38 insertions, 56 deletions
diff --git a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c index 1e9db4189..1e2c729a7 100644 --- a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c @@ -23,11 +23,6 @@ int cpuinfo_parser(FILE *file ODP_UNUSED, system_info_t *sysinfo) return 0; } -uint64_t odp_cpu_hz_current(int id ODP_UNUSED) -{ - return 0; -} - void sys_info_print_arch(void) { } diff --git a/platform/linux-generic/arch/default/odp_sysinfo_parse.c b/platform/linux-generic/arch/default/odp_sysinfo_parse.c index 1e9db4189..1e2c729a7 100644 --- a/platform/linux-generic/arch/default/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/default/odp_sysinfo_parse.c @@ -23,11 +23,6 @@ int cpuinfo_parser(FILE *file ODP_UNUSED, system_info_t *sysinfo) return 0; } -uint64_t odp_cpu_hz_current(int id ODP_UNUSED) -{ - return 0; -} - void sys_info_print_arch(void) { } diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c index 2a37ae70a..5ed7a398e 100644 --- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c @@ -60,11 +60,6 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) return 0; } -uint64_t odp_cpu_hz_current(int id ODP_UNUSED) -{ - return 0; -} - void sys_info_print_arch(void) { } diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c index 29c97613a..02a83e514 100644 --- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c @@ -59,11 +59,6 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) return 0; } -uint64_t odp_cpu_hz_current(int id ODP_UNUSED) -{ - return 0; -} - void sys_info_print_arch(void) { } diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c index f7918d408..55bbda8c4 100644 --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -41,42 +41,6 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) return 0; } -uint64_t odp_cpu_hz_current(int id) -{ - char str[1024]; - FILE *file; - int cpu; - char *pos; - double mhz = 0.0; - - file = fopen("/proc/cpuinfo", "rt"); - - /* find the correct processor instance */ - while (fgets(str, sizeof(str), file) != NULL) { - pos = strstr(str, "processor"); - if (pos) { - if (sscanf(pos, "processor : %d", &cpu) == 1) - if (cpu == id) - break; - } - } - - /* extract the cpu current speed */ - while (fgets(str, sizeof(str), file) != NULL) { - pos = strstr(str, "cpu MHz"); - if (pos) { - if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1) - break; - } - } - - fclose(file); - if (mhz) - return (uint64_t)(mhz * 1000000.0); - - return 0; -} - void sys_info_print_arch(void) { cpu_flags_print_all(); diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 355e25f73..e0cc6dd4a 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -131,6 +131,7 @@ int _odp_ishm_term_global(void); int _odp_ishm_term_local(void); int cpuinfo_parser(FILE *file, system_info_t *sysinfo); +uint64_t odp_cpufreq_id(const char *filename, int id); uint64_t odp_cpu_hz_current(int id); void sys_info_print_arch(void); diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index d6eeb7869..d310d7790 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -261,6 +261,30 @@ static char *get_hugepage_dir(uint64_t hugepage_sz) } /* + * Analysis of /sys/devices/system/cpu/cpu%d/cpufreq/ files + */ +uint64_t odp_cpufreq_id(const char *filename, int id) +{ + char path[256], buffer[256], *endptr = NULL; + FILE *file; + uint64_t ret = 0; + + snprintf(path, sizeof(path), + "/sys/devices/system/cpu/cpu%d/cpufreq/%s", id, filename); + + file = fopen(path, "r"); + if (file == NULL) + return ret; + + if (fgets(buffer, sizeof(buffer), file) != NULL) + ret = strtoull(buffer, &endptr, 0) * 1000; + + fclose(file); + + return ret; +} + +/* * Analysis of /sys/devices/system/cpu/ files */ static int systemcpu(system_info_t *sysinfo) @@ -310,6 +334,7 @@ static int system_hp(hugepage_info_t *hugeinfo) */ int odp_system_info_init(void) { + int i; FILE *file; memset(&odp_global_data.system_info, 0, sizeof(system_info_t)); @@ -326,6 +351,13 @@ int odp_system_info_init(void) fclose(file); + for (i = 0; i < MAX_CPU_NUMBER; i++) { + uint64_t cpu_hz_max = odp_cpufreq_id("cpuinfo_max_freq", i); + + if (cpu_hz_max) + odp_global_data.system_info.cpu_hz_max[i] = cpu_hz_max; + } + if (systemcpu(&odp_global_data.system_info)) { ODP_ERR("systemcpu failed\n"); return -1; @@ -351,6 +383,11 @@ int odp_system_info_term(void) * Public access functions ************************* */ +uint64_t odp_cpu_hz_current(int id) +{ + return odp_cpufreq_id("cpuinfo_cur_freq", id); +} + uint64_t odp_cpu_hz(void) { int id = sched_getcpu(); |