diff mbox

[API-NEXT,v2,1/5] linux-generic: sysinfo: make the model_str per-CPU data

Message ID 1435833923-28361-2-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>

For AMP system such as ARM big.LITTLE, cores are heterogeneous, and the
model_str for each core may be different too, so this patch changes the
model_str to data array model_str[] to contain data for each different
core, while for the common SMP system, we can simply use the model_str[0]
to contain data for all cores because they are all same, but if like, we
can fill each item in the data array too.

Accordingly, odp_sys_cpu_model_str_amp(cpu) is introduced for AMP system,
while the original version interfaces without any parameter is kept for
the SMP systems.

Currently, all the platforms implemented are all SMP, so only the
model_str[0] is used, but when cpuinfo_arm() is implemented, this per-CPU
feature should not be missed because of its big.LITTLE.

Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
---
 include/odp/api/system_info.h                 |  7 +++++
 platform/linux-generic/include/odp_internal.h |  4 ++-
 platform/linux-generic/odp_system_info.c      | 37 ++++++++++++++++-----------
 3 files changed, 32 insertions(+), 16 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/system_info.h b/include/odp/api/system_info.h
index 1f3294b..86b4556 100644
--- a/include/odp/api/system_info.h
+++ b/include/odp/api/system_info.h
@@ -52,6 +52,13 @@  uint64_t odp_sys_page_size(void);
 const char *odp_sys_cpu_model_str(void);
 
 /**
+ * CPU model name for AMP system
+ *
+ * @return Pointer to CPU model name string
+ */
+const char *odp_sys_cpu_model_str_amp(int cpu);
+
+/**
  * Cache line size in bytes
  *
  * @return CPU cache line size in bytes
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index 8c5d339..bcf7e63 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -22,13 +22,15 @@  extern "C" {
 
 extern __thread int __odp_errno;
 
+#define MAX_CPU_NUMBER 128
+
 typedef struct {
 	uint64_t cpu_hz;
 	uint64_t huge_page_size;
 	uint64_t page_size;
 	int      cache_line_size;
 	int      cpu_count;
-	char     model_str[128];
+	char     model_str[MAX_CPU_NUMBER][128];
 } odp_system_info_t;
 
 struct odp_global_data_s {
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 31df29e..181a0c7 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -36,7 +36,6 @@  typedef struct {
 
 #define HUGE_PAGE_DIR "/sys/kernel/mm/hugepages"
 
-
 /*
  * Report the number of CPUs in the affinity mask of the main thread
  */
@@ -139,10 +138,10 @@  static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo)
 			if (pos) {
 				int len;
 				pos = strchr(str, ':');
-				strncpy(sysinfo->model_str, pos+2,
-					sizeof(sysinfo->model_str));
-				len = strlen(sysinfo->model_str);
-				sysinfo->model_str[len - 1] = 0;
+				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--;
 			}
@@ -188,10 +187,10 @@  static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo)
 			if (pos) {
 				int len;
 				pos = strchr(str, ':');
-				strncpy(sysinfo->model_str, pos+2,
-					sizeof(sysinfo->model_str));
-				len = strlen(sysinfo->model_str);
-				sysinfo->model_str[len - 1] = 0;
+				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--;
 			}
@@ -228,10 +227,10 @@  static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo)
 			if (pos) {
 				int len;
 				pos = strchr(str, ':');
-				strncpy(sysinfo->model_str, pos+2,
-					sizeof(sysinfo->model_str));
-				len = strlen(sysinfo->model_str);
-				sysinfo->model_str[len - 1] = 0;
+				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--;
 			}
@@ -333,7 +332,7 @@  static int systemcpu(odp_system_info_t *sysinfo)
 	sysinfo->cpu_hz          = 1400000000;
 	sysinfo->cache_line_size = 64;
 
-	strncpy(sysinfo->model_str, "UNKNOWN", sizeof(sysinfo->model_str));
+	strncpy(sysinfo->model_str[0], "UNKNOWN", sizeof(sysinfo->model_str));
 
 	return 0;
 }
@@ -391,7 +390,15 @@  uint64_t odp_sys_page_size(void)
 
 const char *odp_sys_cpu_model_str(void)
 {
-	return odp_global_data.system_info.model_str;
+	return odp_sys_cpu_model_str_amp(0);
+}
+
+const char *odp_sys_cpu_model_str_amp(int cpu)
+{
+	if (cpu >= 0 && cpu < MAX_CPU_NUMBER)
+		return odp_global_data.system_info.model_str[cpu];
+	else
+		return NULL;
 }
 
 int odp_sys_cache_line_size(void)