From 71c4da0af1a353dfcc44085ae5a5ab467b7982eb Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Thu, 22 Oct 2020 14:38:30 +0300 Subject: linux-gen: sysinfo: implement system info call Implement the new odp_system_info() function. Signed-off-by: Petri Savolainen Reviewed-by: Matias Elo Reviewed-by: Govindarajan Mohandoss --- .../linux-generic/arch/aarch64/odp_sysinfo_parse.c | 49 ++++++++++++++++++++++ .../linux-generic/arch/mips64/odp_sysinfo_parse.c | 4 ++ .../linux-generic/arch/powerpc/odp_sysinfo_parse.c | 4 ++ .../linux-generic/arch/x86/odp_sysinfo_parse.c | 10 +++++ platform/linux-generic/include/odp_global_data.h | 4 ++ .../linux-generic/include/odp_sysinfo_internal.h | 2 + platform/linux-generic/odp_system_info.c | 12 ++++++ 7 files changed, 85 insertions(+) (limited to 'platform/linux-generic') diff --git a/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c b/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c index 690fc5ef1..2b397b9c4 100644 --- a/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c @@ -141,6 +141,50 @@ static void aarch64_part_str(char *str, int maxlen, int implementer, part, variant, revision); } +static odp_cpu_arch_arm_t arm_isa_version(void) +{ +#if defined(__ARM_ARCH) + if (__ARM_ARCH == 8) { + #ifdef __ARM_FEATURE_QRDMX + /* v8.1 or higher */ + return ODP_CPU_ARCH_ARMV8_1; + #else + return ODP_CPU_ARCH_ARMV8_0; + #endif + } + + if (__ARM_ARCH >= 800) { + /* ACLE 2018 defines that from v8.1 onwards the value includes + * the minor version number: __ARM_ARCH = X * 100 + Y + * E.g. for Armv8.1 __ARM_ARCH = 801 */ + int major = __ARM_ARCH / 100; + int minor = __ARM_ARCH - (major * 100); + + if (major == 8) { + switch (minor) { + case 0: + return ODP_CPU_ARCH_ARMV8_0; + case 1: + return ODP_CPU_ARCH_ARMV8_1; + case 2: + return ODP_CPU_ARCH_ARMV8_2; + case 3: + return ODP_CPU_ARCH_ARMV8_3; + case 4: + return ODP_CPU_ARCH_ARMV8_4; + case 5: + return ODP_CPU_ARCH_ARMV8_5; + case 6: + return ODP_CPU_ARCH_ARMV8_6; + default: + return ODP_CPU_ARCH_ARM_UNKNOWN; + } + } + } +#endif + return ODP_CPU_ARCH_ARM_UNKNOWN; +} + int cpuinfo_parser(FILE *file, system_info_t *sysinfo) { char str[1024]; @@ -150,6 +194,11 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) long int impl, arch, var, part, rev; int id; + sysinfo->cpu_arch = ODP_CPU_ARCH_ARM; + sysinfo->cpu_isa_sw.arm = arm_isa_version(); + /* Linux cpuinfo does not have detailed ISA version number (CPU architecture: 8) */ + sysinfo->cpu_isa_hw.arm = ODP_CPU_ARCH_ARM_UNKNOWN; + strcpy(sysinfo->cpu_arch_str, "aarch64"); memset(impl_str, 0, sizeof(impl_str)); diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c index 3d6a8aa80..15b2ccc86 100644 --- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c @@ -18,6 +18,10 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) int count = 2; int id = 0; + sysinfo->cpu_arch = ODP_CPU_ARCH_MIPS; + sysinfo->cpu_isa_sw.mips = ODP_CPU_ARCH_MIPS_UNKNOWN; + sysinfo->cpu_isa_hw.mips = ODP_CPU_ARCH_MIPS_UNKNOWN; + strcpy(sysinfo->cpu_arch_str, "mips64"); while (fgets(str, sizeof(str), file) != NULL && id < CONFIG_NUM_CPU_IDS) { if (!mhz) { diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c index dfa4344e9..77b813f99 100644 --- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c @@ -18,6 +18,10 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) int count = 2; int id = 0; + sysinfo->cpu_arch = ODP_CPU_ARCH_PPC; + sysinfo->cpu_isa_sw.ppc = ODP_CPU_ARCH_PPC_UNKNOWN; + sysinfo->cpu_isa_hw.ppc = ODP_CPU_ARCH_PPC_UNKNOWN; + strcpy(sysinfo->cpu_arch_str, "powerpc"); while (fgets(str, sizeof(str), file) != NULL && id < CONFIG_NUM_CPU_IDS) { if (!mhz) { diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c index 3c96a3bfa..d21ccf30c 100644 --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -18,6 +18,16 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) int id = 0; bool freq_set = false; + sysinfo->cpu_arch = ODP_CPU_ARCH_X86; + sysinfo->cpu_isa_sw.x86 = ODP_CPU_ARCH_X86_UNKNOWN; + sysinfo->cpu_isa_hw.x86 = ODP_CPU_ARCH_X86_UNKNOWN; + + #if defined __x86_64 || defined __x86_64__ + sysinfo->cpu_isa_sw.x86 = ODP_CPU_ARCH_X86_64; + #elif defined __i686 || defined __i686__ + sysinfo->cpu_isa_sw.x86 = ODP_CPU_ARCH_X86_I686; + #endif + strcpy(sysinfo->cpu_arch_str, "x86"); while (fgets(str, sizeof(str), file) != NULL && id < CONFIG_NUM_CPU_IDS) { pos = strstr(str, "model name"); diff --git a/platform/linux-generic/include/odp_global_data.h b/platform/linux-generic/include/odp_global_data.h index 7bfb07149..24e0e88ca 100644 --- a/platform/linux-generic/include/odp_global_data.h +++ b/platform/linux-generic/include/odp_global_data.h @@ -14,6 +14,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -30,6 +31,9 @@ typedef struct { uint64_t page_size; int cache_line_size; int cpu_count; + odp_cpu_arch_t cpu_arch; + odp_cpu_arch_isa_t cpu_isa_sw; + odp_cpu_arch_isa_t cpu_isa_hw; char cpu_arch_str[128]; char model_str[CONFIG_NUM_CPU_IDS][MODEL_STR_SIZE]; } system_info_t; diff --git a/platform/linux-generic/include/odp_sysinfo_internal.h b/platform/linux-generic/include/odp_sysinfo_internal.h index 179690f39..2b1f04ca6 100644 --- a/platform/linux-generic/include/odp_sysinfo_internal.h +++ b/platform/linux-generic/include/odp_sysinfo_internal.h @@ -26,6 +26,8 @@ static inline int _odp_dummy_cpuinfo(system_info_t *sysinfo) uint64_t cpu_hz_max = sysinfo->default_cpu_hz_max; int i; + sysinfo->cpu_arch = ODP_CPU_ARCH_UNKNOWN; + ODP_DBG("Warning: use dummy values for freq and model string\n"); for (i = 0; i < CONFIG_NUM_CPU_IDS; i++) { ODP_PRINT("WARN: cpu[%i] uses default max frequency of " diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 33e193d49..bacbe1e25 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -527,6 +527,18 @@ int odp_cpu_count(void) return odp_global_ro.system_info.cpu_count; } +int odp_system_info(odp_system_info_t *info) +{ + system_info_t *sys_info = &odp_global_ro.system_info; + + memset(info, 0, sizeof(odp_system_info_t)); + + info->cpu_arch = sys_info->cpu_arch; + info->cpu_isa_sw = sys_info->cpu_isa_sw; + + return 0; +} + void odp_sys_info_print(void) { int len, num_cpu; -- cgit v1.2.3