diff mbox

[API-NEXT,4/7] linux-generic: sysinfo: move x86 system info codes to its plarform file

Message ID 1451032201-19954-5-git-send-email-hongbo.zhang@linaro.org
State Superseded
Headers show

Commit Message

Hongbo Zhang Dec. 25, 2015, 8:29 a.m. UTC
From: Hongbo Zhang <hongbo.zhang@linaro.org>

This patch moves the x86 system info codes into the newly added x86
specific platform file.

Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
---
 platform/linux-generic/Makefile.am                 |  6 +-
 .../linux-generic/arch/x86/odp_sysinfo_parse.c     | 71 ++++++++++++++++++++++
 platform/linux-generic/include/odp_cpu_internal.h  |  4 ++
 platform/linux-generic/odp_system_info.c           | 69 +--------------------
 4 files changed, 81 insertions(+), 69 deletions(-)
 create mode 100644 platform/linux-generic/arch/x86/odp_sysinfo_parse.c
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 75ca703..f19a858 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -158,12 +158,14 @@  __LIB__libodp_la_SOURCES = \
 			   odp_traffic_mngr.c \
 			   odp_version.c \
 			   odp_weak.c \
-			   arch/@ARCH@/odp_cpu_cycles.c
+			   arch/@ARCH@/odp_cpu_cycles.c \
+			   arch/@ARCH@/odp_sysinfo_parse.c
 
 EXTRA_DIST = \
 	     arch/linux/odp_cpu_cycles.c \
 	     arch/mips64/odp_cpu_cycles.c \
-	     arch/x86/odp_cpu_cycles.c
+	     arch/x86/odp_cpu_cycles.c \
+	     arch/x86/odp_sysinfo_parse.c
 
 if HAVE_PCAP
 __LIB__libodp_la_SOURCES += pktio/pcap.c
diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
new file mode 100644
index 0000000..2da0b1b
--- /dev/null
+++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
@@ -0,0 +1,71 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <odp_internal.h>
+#include <odp_cpu_internal.h>
+#include <string.h>
+
+int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo)
+{
+	char str[1024];
+	char *pos;
+	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++;
+		}
+	}
+
+	return 0;
+}
+
+uint64_t odp_cpu_hz_current(int id)
+{
+	char str[1024];
+	FILE *file;
+	int cpu;
+	char *pos;
+	double mhz = 0.0;
+
+	file = fopen("/proc/cpuinfo", "rt");
+
+	/* find the correct processor instance */
+	while (fgets(str, sizeof(str), file) != NULL) {
+		pos = strstr(str, "processor");
+		if (pos) {
+			if (sscanf(pos, "processor : %d", &cpu) == 1)
+				if (cpu == id)
+					break;
+		}
+	}
+
+	/* extract the cpu current speed */
+	while (fgets(str, sizeof(str), file) != NULL) {
+		pos = strstr(str, "cpu MHz");
+		if (pos) {
+			if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1)
+				break;
+		}
+	}
+
+	fclose(file);
+	if (mhz)
+		return (uint64_t)(mhz * 1000000.0);
+
+	return -1;
+}
diff --git a/platform/linux-generic/include/odp_cpu_internal.h b/platform/linux-generic/include/odp_cpu_internal.h
index 664e2df..38b1a3a 100644
--- a/platform/linux-generic/include/odp_cpu_internal.h
+++ b/platform/linux-generic/include/odp_cpu_internal.h
@@ -12,6 +12,7 @@  extern "C" {
 #endif
 
 #include <odp/cpu.h>
+#include <stdio.h>
 
 static inline
 uint64_t _odp_cpu_cycles_diff(uint64_t c2, uint64_t c1)
@@ -22,6 +23,9 @@  uint64_t _odp_cpu_cycles_diff(uint64_t c2, uint64_t c1)
 	return c2 + (odp_cpu_cycles_max() - c1) + 1;
 }
 
+int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo);
+uint64_t odp_cpu_hz_current(int id);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 449e500..fc5ee3b 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -7,6 +7,7 @@ 
 #define _GNU_SOURCE
 #include <odp/system_info.h>
 #include <odp_internal.h>
+#include <odp_cpu_internal.h>
 #include <odp_debug_internal.h>
 #include <odp/align.h>
 #include <odp/cpu.h>
@@ -108,71 +109,7 @@  static int huge_page_size(void)
 /*
  * HW specific /proc/cpuinfo file parsing
  */
-#if defined __x86_64__ || defined __i386__
-
-static int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo)
-{
-	char str[1024];
-	char *pos;
-	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++;
-		}
-	}
-
-	return 0;
-}
-
-static uint64_t odp_cpu_hz_current(int id)
-{
-	char str[1024];
-	FILE *file;
-	int cpu;
-	char *pos;
-	double mhz = 0.0;
-
-	file = fopen("/proc/cpuinfo", "rt");
-
-	/* find the correct processor instance */
-	while (fgets(str, sizeof(str), file) != NULL) {
-		pos = strstr(str, "processor");
-		if (pos) {
-			if (sscanf(pos, "processor : %d", &cpu) == 1)
-				if (cpu == id)
-					break;
-		}
-	}
-
-	/* extract the cpu current speed */
-	while (fgets(str, sizeof(str), file) != NULL) {
-		pos = strstr(str, "cpu MHz");
-		if (pos) {
-			if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1)
-				break;
-		}
-	}
-
-	fclose(file);
-	if (mhz)
-		return (uint64_t)(mhz * 1000000.0);
-
-	return -1;
-}
-
-#elif defined __arm__ || defined __aarch64__
+#if defined __arm__ || defined __aarch64__
 
 static int odp_cpuinfo_parser(FILE *file ODP_UNUSED,
 odp_system_info_t *sysinfo ODP_UNUSED)
@@ -278,8 +215,6 @@  static uint64_t odp_cpu_hz_current(int id ODP_UNUSED)
 	return -1;
 }
 
-#else
-	#error GCC target not found
 #endif