aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2018-09-04 12:56:25 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-09-10 17:43:03 +0300
commit0c20689a6a78818b5cdb97cfa6c23fa7d866a761 (patch)
tree3129dd926cb5905ce7bb6305367826a62fe7f115 /platform/linux-generic/arch/x86/odp_sysinfo_parse.c
parent4646069f0417fc180977100af2bc1f527b2d4f28 (diff)
linux-gen: x86: as a last resort parse max cpu freq from bogomips value
Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic/arch/x86/odp_sysinfo_parse.c')
-rw-r--r--platform/linux-generic/arch/x86/odp_sysinfo_parse.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
index 504aa3efa..5084e6b5f 100644
--- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
@@ -15,34 +15,54 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo)
char str[1024];
char *pos, *pos_end;
double ghz = 0.0;
+ double mhz = 0.0;
uint64_t hz;
int id = 0;
+ bool freq_set = false;
strcpy(sysinfo->cpu_arch_str, "x86");
while (fgets(str, sizeof(str), file) != NULL && id < CONFIG_NUM_CPU) {
pos = strstr(str, "model name");
if (pos) {
+ freq_set = false;
+
/* Copy model name between : and @ characters */
pos = strchr(str, ':');
pos_end = strchr(str, '@');
- if (pos == NULL || pos_end == NULL)
+ if (pos == NULL)
continue;
- *(pos_end - 1) = '\0';
+ if (pos_end != NULL)
+ *(pos_end - 1) = '\0';
+
strncpy(sysinfo->model_str[id], pos + 2,
MODEL_STR_SIZE - 1);
if (sysinfo->cpu_hz_max[id]) {
+ freq_set = true;
id++;
continue;
}
/* max frequency needs to be set */
- if (sscanf(pos_end, "@ %lfGHz", &ghz) == 1) {
+ if (pos_end != NULL &&
+ sscanf(pos_end, "@ %lfGHz", &ghz) == 1) {
hz = (uint64_t)(ghz * 1000000000.0);
- sysinfo->cpu_hz_max[id] = hz;
+ sysinfo->cpu_hz_max[id++] = hz;
+ freq_set = true;
+ }
+ } else if (!freq_set &&
+ strstr(str, "bogomips") != NULL) {
+ pos = strchr(str, ':');
+ if (pos == NULL)
+ continue;
+
+ if (sscanf(pos + 2, "%lf", &mhz) == 1) {
+ /* On typical x86 BogoMIPS is freq * 2 */
+ hz = (uint64_t)(mhz * 1000000.0 / 2);
+ sysinfo->cpu_hz_max[id++] = hz;
+ freq_set = true;
}
- id++;
}
}