diff mbox

[API-NEXT,v2,3/5] linux-generic: sysinfo: make cpu_hz stand for max CPU frequency

Message ID 1435833923-28361-4-git-send-email-hongbo.zhang@freescale.com
State New
Headers show

Commit Message

hongbo.zhang@freescale.com July 2, 2015, 10:45 a.m. UTC
From: Hongbo Zhang <hongbo.zhang@linaro.org>

In the previous x86 platform code, the variable is acquired from segment
"cpu MHz" of /proc/cpuinfo, this is the current CPU frequency when
acquired, and it may be scaled from time to time. But most of the use
cases when odp_sys_cpu_hz() is called, users just want to show the max
capacity of CPU, so this patch makes it clear that the cpu_hz stand for
max CPU frequency.

While there may still be some use case of acquiring the current CPU
frequency, another new API for this is introduced for this in the next
patch.

As to platforms other than x86, if their cpu_hz's don't stand for max CPU
frequency, they should be changed following up this patch, and then max or
current frequency of CPU should be clear.

Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
---
 platform/linux-generic/odp_system_info.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 8ade5a6..00b8d4d 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -120,35 +120,27 @@  static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo)
 {
 	char str[1024];
 	char *pos;
-	double mhz = 0.0;
+	double ghz = 0.0;
 	int model = 0;
-	int count = 2;
+	int count = 1;
 
 	while (fgets(str, sizeof(str), file) != NULL && count > 0) {
-		if (!mhz) {
-			pos = strstr(str, "cpu MHz");
-			if (pos) {
-				sscanf(pos, "cpu MHz : %lf", &mhz);
-				count--;
-			}
-		}
-
 		if (!model) {
 			pos = strstr(str, "model name");
 			if (pos) {
-				int len;
 				pos = strchr(str, ':');
 				strncpy(sysinfo->model_str[0], pos + 2,
 					sizeof(sysinfo->model_str[0]));
-				len = strlen(sysinfo->model_str[0]);
-				sysinfo->model_str[0][len - 1] = 0;
+				pos = strchr(sysinfo->model_str[0], '@');
+				*(pos - 1) = '\0';
+				sscanf(pos, "@ %lfGHz", &ghz);
 				model = 1;
 				count--;
 			}
 		}
 	}
 
-	sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
+	sysinfo->cpu_hz[0] = (uint64_t)(ghz * 1000000000.0);
 
 	return 0;
 }