diff mbox

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

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

Commit Message

hongbo.zhang@freescale.com Sept. 17, 2015, 1:10 p.m. UTC
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 | 25 +++++++++++--------------
 2 files changed, 20 insertions(+), 14 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/cpu.h b/include/odp/api/cpu.h
index 55f5d23..93d3e7f 100644
--- a/include/odp/api/cpu.h
+++ b/include/odp/api/cpu.h
@@ -73,6 +73,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);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index ea1f337..43bfcc0 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -121,35 +121,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;
 }
@@ -379,6 +371,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;