[API,NEXT,v7,06/14] api: cpu: add new API to get CPU max frequency

Message ID 1444734798-29063-7-git-send-email-hongbo.zhang@freescale.com
State New
Headers show

Commit Message

hongbo.zhang@freescale.com Oct. 13, 2015, 11:13 a.m.
From: Hongbo Zhang <hongbo.zhang@linaro.org>

This patch adds a new API odp_cpu_hz_max() to get the max frequency of
the CPU on which the progeress is running.
The previous odp_cpu_hz() should return the current frequency and will
be adapted later.

Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
---
 include/odp/api/cpu.h                    |  9 ++++++
 platform/linux-generic/odp_system_info.c | 48 ++++++++++++++------------------
 2 files changed, 30 insertions(+), 27 deletions(-)

Patch

diff --git a/include/odp/api/cpu.h b/include/odp/api/cpu.h
index f8873dd..96f7d77 100644
--- a/include/odp/api/cpu.h
+++ b/include/odp/api/cpu.h
@@ -75,6 +75,15 @@  const char *odp_cpu_model_str_id(int id);
 uint64_t odp_cpu_hz(void);
 
 /**
+ * Maximum CPU frequency in Hz
+ *
+ * Returns maximum frequency of this CPU
+ *
+ * @return CPU frequency in Hz
+ */
+uint64_t odp_cpu_hz_max(void);
+
+/**
  * Current CPU cycle count
  *
  * Return current CPU cycle count. Cycle count may not be reset at ODP init
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index ea1f337..55f5753 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -121,36 +121,25 @@  static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo)
 {
 	char str[1024];
 	char *pos;
-	double mhz = 0.0;
-	int model = 0;
-	int count = 2;
-
-	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;
-				model = 1;
-				count--;
-			}
+	double ghz = 0.0;
+	int id = 0;
+
+	while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) {
+		pos = strstr(str, "model name");
+		if (pos) {
+			pos = strchr(str, ':');
+			strncpy(sysinfo->model_str[id], pos + 2,
+				sizeof(sysinfo->model_str[id]));
+
+			pos = strchr(sysinfo->model_str[id], '@');
+			*(pos - 1) = '\0';
+			if (sscanf(pos, "@ %lfGHz", &ghz) == 1)
+				sysinfo->cpu_hz[id] = (uint64_t)(ghz * 1000000000.0);
+
+			id++;
 		}
 	}
 
-	sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
-
 	return 0;
 }
 
@@ -379,6 +368,11 @@  uint64_t odp_cpu_hz(void)
 	return odp_global_data.system_info.cpu_hz[0];
 }
 
+uint64_t odp_cpu_hz_max(void)
+{
+	return odp_global_data.system_info.cpu_hz[0];
+}
+
 uint64_t odp_sys_huge_page_size(void)
 {
 	return odp_global_data.system_info.huge_page_size;