diff mbox

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

Message ID 1435833923-28361-3-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 cpu_hz
for each core may be different too, so this patch changes the cpu_hz to
data array cpu_hz[] to contain data for each different core, while for the
common SMP system, we can simply use the cpu_hz[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.

And the odp_sys_cpu_hz_amp(cpu) is added for AMP system, while the
original version interfaces without any parameter is kept for SMP systems.

Currently, all the platforms implemented are all SMP, so only cpu_hz[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 |  2 +-
 platform/linux-generic/odp_system_info.c      | 18 +++++++++++++-----
 3 files changed, 21 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/system_info.h b/include/odp/api/system_info.h
index 86b4556..8627d97 100644
--- a/include/odp/api/system_info.h
+++ b/include/odp/api/system_info.h
@@ -31,6 +31,13 @@  extern "C" {
 uint64_t odp_sys_cpu_hz(void);
 
 /**
+ * CPU frequency in Hz for AMP system
+ *
+ * @return CPU frequency in Hz
+ */
+uint64_t odp_sys_cpu_hz_amp(int cpu);
+
+/**
  * Huge page size in bytes
  *
  * @return Huge page size in bytes
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index bcf7e63..8df8c23 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -25,7 +25,7 @@  extern __thread int __odp_errno;
 #define MAX_CPU_NUMBER 128
 
 typedef struct {
-	uint64_t cpu_hz;
+	uint64_t cpu_hz[MAX_CPU_NUMBER];
 	uint64_t huge_page_size;
 	uint64_t page_size;
 	int      cache_line_size;
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 181a0c7..8ade5a6 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -148,7 +148,7 @@  static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo)
 		}
 	}
 
-	sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0);
+	sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
 
 	return 0;
 }
@@ -198,7 +198,7 @@  static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo)
 	}
 
 	/* bogomips seems to be 2x freq */
-	sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0 / 2.0);
+	sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0 / 2.0);
 
 	return 0;
 }
@@ -236,7 +236,7 @@  static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo)
 			}
 		}
 
-		sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0);
+		sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
 	}
 
 
@@ -329,7 +329,7 @@  static int systemcpu(odp_system_info_t *sysinfo)
 	sysinfo->huge_page_size = huge_page_size();
 
 	/* Dummy values */
-	sysinfo->cpu_hz          = 1400000000;
+	sysinfo->cpu_hz[0]       = 1400000000;
 	sysinfo->cache_line_size = 64;
 
 	strncpy(sysinfo->model_str[0], "UNKNOWN", sizeof(sysinfo->model_str));
@@ -375,7 +375,15 @@  int odp_system_info_init(void)
  */
 uint64_t odp_sys_cpu_hz(void)
 {
-	return odp_global_data.system_info.cpu_hz;
+	return odp_sys_cpu_hz_amp(0);
+}
+
+uint64_t odp_sys_cpu_hz_amp(int cpu)
+{
+	if (cpu >= 0 && cpu < MAX_CPU_NUMBER)
+		return odp_global_data.system_info.cpu_hz[cpu];
+	else
+		return -1;
 }
 
 uint64_t odp_sys_huge_page_size(void)