aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/odp_system_info.c
diff options
context:
space:
mode:
Diffstat (limited to 'platform/linux-generic/odp_system_info.c')
-rw-r--r--platform/linux-generic/odp_system_info.c215
1 files changed, 40 insertions, 175 deletions
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index a948fce93..42aef8a11 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -25,13 +25,6 @@
#include <dirent.h>
-
-typedef struct {
- const char *cpu_arch_str;
- int (*cpuinfo_parser)(FILE *file, odp_system_info_t *sysinfo);
-
-} odp_compiler_info_t;
-
#define CACHE_LNSZ_FILE \
"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
@@ -112,166 +105,6 @@ static int huge_page_size(void)
}
-
-/*
- * HW specific /proc/cpuinfo file parsing
- */
-#if defined __x86_64__ || defined __i386__
-
-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, pos+2,
- sizeof(sysinfo->model_str));
- len = strlen(sysinfo->model_str);
- sysinfo->model_str[len - 1] = 0;
- model = 1;
- count--;
- }
- }
- }
-
- sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0);
-
- return 0;
-}
-
-#elif defined __arm__ || defined __aarch64__
-
-static int cpuinfo_arm(FILE *file ODP_UNUSED,
-odp_system_info_t *sysinfo ODP_UNUSED)
-{
- return 0;
-}
-
-#elif defined __OCTEON__
-
-static int cpuinfo_octeon(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, "BogoMIPS");
-
- if (pos) {
- sscanf(pos, "BogoMIPS : %lf", &mhz);
- count--;
- }
- }
-
- if (!model) {
- pos = strstr(str, "cpu model");
-
- 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;
- model = 1;
- count--;
- }
- }
- }
-
- /* bogomips seems to be 2x freq */
- sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0 / 2.0);
-
- return 0;
-}
-#elif defined __powerpc__
-static int cpuinfo_powerpc(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, "clock");
-
- if (pos) {
- sscanf(pos, "clock : %lf", &mhz);
- count--;
- }
- }
-
- if (!model) {
- pos = strstr(str, "cpu");
-
- 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;
- model = 1;
- count--;
- }
- }
-
- sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0);
- }
-
-
- return 0;
-}
-
-#else
- #error GCC target not found
-#endif
-
-static odp_compiler_info_t compiler_info = {
- #if defined __x86_64__ || defined __i386__
- .cpu_arch_str = "x86",
- .cpuinfo_parser = cpuinfo_x86
-
- #elif defined __arm__ || defined __aarch64__
- .cpu_arch_str = "arm",
- .cpuinfo_parser = cpuinfo_arm
-
- #elif defined __OCTEON__
- .cpu_arch_str = "octeon",
- .cpuinfo_parser = cpuinfo_octeon
-
- #elif defined __powerpc__
- .cpu_arch_str = "powerpc",
- .cpuinfo_parser = cpuinfo_powerpc
-
- #else
- #error GCC target not found
- #endif
-};
-
-
#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \
defined __powerpc__
@@ -318,7 +151,7 @@ static int systemcpu(odp_system_info_t *sysinfo)
static int systemcpu(odp_system_info_t *sysinfo)
{
- int ret;
+ int ret, i;
ret = sysconf_cpu_count();
if (ret == 0) {
@@ -331,10 +164,14 @@ static int systemcpu(odp_system_info_t *sysinfo)
sysinfo->huge_page_size = huge_page_size();
/* Dummy values */
- sysinfo->cpu_hz = 1400000000;
sysinfo->cache_line_size = 64;
- strncpy(sysinfo->model_str, "UNKNOWN", sizeof(sysinfo->model_str));
+ ODP_DBG("Warning: use dummy values for freq and model string\n");
+ ODP_DBG("Refer to https://bugs.linaro.org/show_bug.cgi?id=1870\n");
+ for (i = 0; i < MAX_CPU_NUMBER; i++) {
+ sysinfo->cpu_hz_max[i] = 1400000000;
+ strcpy(sysinfo->model_str[i], "UNKNOWN");
+ }
return 0;
}
@@ -358,7 +195,7 @@ int odp_system_info_init(void)
return -1;
}
- compiler_info.cpuinfo_parser(file, &odp_global_data.system_info);
+ odp_cpuinfo_parser(file, &odp_global_data.system_info);
fclose(file);
@@ -383,9 +220,29 @@ int odp_system_info_term(void)
* Public access functions
*************************
*/
-uint64_t odp_sys_cpu_hz(void)
+uint64_t odp_cpu_hz(void)
{
- return odp_global_data.system_info.cpu_hz;
+ int id = sched_getcpu();
+
+ return odp_cpu_hz_current(id);
+}
+
+uint64_t odp_cpu_hz_id(int id)
+{
+ return odp_cpu_hz_current(id);
+}
+
+uint64_t odp_cpu_hz_max(void)
+{
+ return odp_cpu_hz_max_id(0);
+}
+
+uint64_t odp_cpu_hz_max_id(int id)
+{
+ if (id >= 0 && id < MAX_CPU_NUMBER)
+ return odp_global_data.system_info.cpu_hz_max[id];
+ else
+ return 0;
}
uint64_t odp_sys_huge_page_size(void)
@@ -398,9 +255,17 @@ uint64_t odp_sys_page_size(void)
return odp_global_data.system_info.page_size;
}
-const char *odp_sys_cpu_model_str(void)
+const char *odp_cpu_model_str(void)
+{
+ return odp_cpu_model_str_id(0);
+}
+
+const char *odp_cpu_model_str_id(int id)
{
- return odp_global_data.system_info.model_str;
+ if (id >= 0 && id < MAX_CPU_NUMBER)
+ return odp_global_data.system_info.model_str[id];
+ else
+ return NULL;
}
int odp_sys_cache_line_size(void)