[v5,2/3] linux-gen: x86: as a last resort parse max cpu freq from bogomips value

Message ID 1536156008-9721-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • Two fxes for sysinfo
Related show

Commit Message

Github ODP bot Sept. 5, 2018, 2 p.m.
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 693 (lumag:fix-cpu_max_hz)
 ** https://github.com/Linaro/odp/pull/693
 ** Patch: https://github.com/Linaro/odp/pull/693.patch
 ** Base sha: 0a5d67beda902557056d5b5146d8cbe86e5001b0
 ** Merge commit sha: a057d7593fa6375352a84ec9ce2c997b6581b790
 **/
 .../arch/x86/odp_sysinfo_parse.c              | 30 +++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

Patch

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++;
 		}
 	}