diff options
author | Hongbo Zhang <hongbo.zhang@linaro.org> | 2015-10-13 19:13:12 +0800 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2016-02-08 20:45:22 +0300 |
commit | 5bf33b966032dc59a969c1e936e7389784f0b4bf (patch) | |
tree | a047877ac0add9835ce756a32d0e745d15a087b2 | |
parent | edcadca528154e21b25199c0df6f156471ead7a9 (diff) |
linux-generic: sysinfo: revise odp_cpu_hz() to return current frequency
The odp_cpu_hz_max() is added to returm maximum frequency of CPU,
while the odp_cpu_hz(), as shown by its name, should return current
frequency of CPU, this patch revise odp_cpu_hz() for this purpose.
Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r-- | platform/linux-generic/odp_system_info.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index e9c5898c7..d9e2d6757 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -144,6 +144,42 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_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 -1; +} + #elif defined __arm__ || defined __aarch64__ static int cpuinfo_arm(FILE *file ODP_UNUSED, @@ -152,6 +188,11 @@ odp_system_info_t *sysinfo ODP_UNUSED) return 0; } +static uint64_t arch_cpu_hz_current(int id ODP_UNUSED) +{ + return -1; +} + #elif defined __OCTEON__ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) @@ -193,6 +234,12 @@ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) return 0; } + +static uint64_t arch_cpu_hz_current(int id ODP_UNUSED) +{ + return -1; +} + #elif defined __powerpc__ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) { @@ -234,6 +281,11 @@ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(int id ODP_UNUSED) +{ + return -1; +} + #else #error GCC target not found #endif @@ -374,7 +426,9 @@ int odp_system_info_term(void) */ uint64_t odp_cpu_hz(void) { - return odp_global_data.system_info.cpu_hz[0]; + int id = sched_getcpu(); + + return arch_cpu_hz_current(id); } uint64_t odp_cpu_hz_max(void) |