Message ID | 1507017606-31412-2-git-send-email-odpbot@yandex.ru |
---|---|
State | New |
Headers | show |
Series | [v1,1/1] linux-gen: User /proc/cpuinfo, if sysfs is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249 | expand |
> -----Original Message----- > From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of > Github ODP bot > Sent: Tuesday, October 03, 2017 11:00 AM > To: lng-odp@lists.linaro.org > Subject: [lng-odp] [PATCH v1 1/1] linux-gen: User /proc/cpuinfo, if sysfs > is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249 > > From: Ilias Apalodimas <ilias.apalodimas@linaro.org> Git log entry is missing. Re-format commit subject line and body of the text. For example: " linux-gen: system_info: use proc/cpuinfo as backup When sysfs is not available, use /proc/cpuinfo file as a backup for current cpu MHz. This fixes bug: https://bugs.linaro.org/show_bug.cgi?id=3249 Signed-off-by... " -Petri
if you will send v2 please refer to original commit from which you restored that function (or which reverted it.) On 3 October 2017 at 12:37, Savolainen, Petri (Nokia - FI/Espoo) < petri.savolainen@nokia.com> wrote: > > > > -----Original Message----- > > From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of > > Github ODP bot > > Sent: Tuesday, October 03, 2017 11:00 AM > > To: lng-odp@lists.linaro.org > > Subject: [lng-odp] [PATCH v1 1/1] linux-gen: User /proc/cpuinfo, if sysfs > > is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249 > > > > From: Ilias Apalodimas <ilias.apalodimas@linaro.org> > > > Git log entry is missing. Re-format commit subject line and body of the > text. > > For example: > " > linux-gen: system_info: use proc/cpuinfo as backup > > When sysfs is not available, use /proc/cpuinfo file as > a backup for current cpu MHz. > > This fixes bug: https://bugs.linaro.org/show_bug.cgi?id=3249 > > Signed-off-by... > " > > -Petri >
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index d310d7790..790bf68b0 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -378,6 +378,44 @@ int odp_system_info_term(void) return 0; } +static uint64_t get_cpuspeed(int id) +{ + char str[1024]; + char *pos; + FILE *file = NULL; + double mhz = 0.0; + int cur_id = 0; + uint64_t cur_hz = 0; + + if (id + 1 > odp_global_data.num_cpus_installed) { + ODP_ERR("Invalid number of CPUs requested\n"); + return cur_hz; + } + + file = fopen("/proc/cpuinfo", "rt"); + if (file == NULL) { + ODP_ERR("Failed to open /proc/cpuinfo\n"); + return cur_hz; + } + + while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) { + pos = strstr(str, "cpu MHz"); + if (pos) { + if (id != cur_id) { + cur_id++; + continue; + } + if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1) { + cur_hz = (uint64_t)(mhz * 1000000.0); + break; + } + } + } + fclose(file); + + return cur_hz; +} + /* ************************* * Public access functions @@ -385,7 +423,12 @@ int odp_system_info_term(void) */ uint64_t odp_cpu_hz_current(int id) { - return odp_cpufreq_id("cpuinfo_cur_freq", id); + uint64_t cur_hz = odp_cpufreq_id("cpuinfo_cur_freq", id); + + if (!cur_hz) + cur_hz = get_cpuspeed(id); + + return cur_hz; } uint64_t odp_cpu_hz(void)