diff options
Diffstat (limited to 'platform/linux-generic/arch')
-rw-r--r-- | platform/linux-generic/arch/linux/odp/cpu_arch.h | 22 | ||||
-rw-r--r-- | platform/linux-generic/arch/linux/odp_cpu_arch.c (renamed from platform/linux-generic/arch/linux/odp_cpu_cycles.c) | 2 | ||||
-rw-r--r-- | platform/linux-generic/arch/linux/odp_sysinfo_parse.c | 19 | ||||
-rw-r--r-- | platform/linux-generic/arch/mips64/odp/cpu_arch.h | 26 | ||||
-rw-r--r-- | platform/linux-generic/arch/mips64/odp_cpu_arch.c (renamed from platform/linux-generic/arch/mips64/odp_cpu_cycles.c) | 0 | ||||
-rw-r--r-- | platform/linux-generic/arch/mips64/odp_sysinfo_parse.c | 64 | ||||
l--------- | platform/linux-generic/arch/powerpc/odp/cpu_arch.h | 1 | ||||
l--------- | platform/linux-generic/arch/powerpc/odp_cpu_arch.c | 1 | ||||
-rw-r--r-- | platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c | 63 | ||||
-rw-r--r-- | platform/linux-generic/arch/x86/odp/cpu_arch.h | 27 | ||||
-rw-r--r-- | platform/linux-generic/arch/x86/odp_cpu_arch.c (renamed from platform/linux-generic/arch/x86/odp_cpu_cycles.c) | 0 | ||||
-rw-r--r-- | platform/linux-generic/arch/x86/odp_sysinfo_parse.c | 73 |
12 files changed, 297 insertions, 1 deletions
diff --git a/platform/linux-generic/arch/linux/odp/cpu_arch.h b/platform/linux-generic/arch/linux/odp/cpu_arch.h new file mode 100644 index 000000000..1c79f875c --- /dev/null +++ b/platform/linux-generic/arch/linux/odp/cpu_arch.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PLAT_CPU_ARCH_H_ +#define ODP_PLAT_CPU_ARCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void odp_cpu_pause(void) +{ +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/arch/linux/odp_cpu_cycles.c b/platform/linux-generic/arch/linux/odp_cpu_arch.c index 7509bf28b..3112d0cd0 100644 --- a/platform/linux-generic/arch/linux/odp_cpu_cycles.c +++ b/platform/linux-generic/arch/linux/odp_cpu_arch.c @@ -27,7 +27,7 @@ uint64_t odp_cpu_cycles(void) if (ret != 0) ODP_ABORT("clock_gettime failed\n"); - hz = odp_sys_cpu_hz(); + hz = odp_cpu_hz_max(); sec = (uint64_t)time.tv_sec; ns = (uint64_t)time.tv_nsec; diff --git a/platform/linux-generic/arch/linux/odp_sysinfo_parse.c b/platform/linux-generic/arch/linux/odp_sysinfo_parse.c new file mode 100644 index 000000000..8ff6f48d2 --- /dev/null +++ b/platform/linux-generic/arch/linux/odp_sysinfo_parse.c @@ -0,0 +1,19 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp_internal.h> +#include <string.h> + +int odp_cpuinfo_parser(FILE *file ODP_UNUSED, + odp_system_info_t *sysinfo ODP_UNUSED) +{ + return 0; +} + +uint64_t odp_cpu_hz_current(int id ODP_UNUSED) +{ + return 0; +} diff --git a/platform/linux-generic/arch/mips64/odp/cpu_arch.h b/platform/linux-generic/arch/mips64/odp/cpu_arch.h new file mode 100644 index 000000000..3bfa0dcde --- /dev/null +++ b/platform/linux-generic/arch/mips64/odp/cpu_arch.h @@ -0,0 +1,26 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PLAT_CPU_ARCH_H_ +#define ODP_PLAT_CPU_ARCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void odp_cpu_pause(void) +{ + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/arch/mips64/odp_cpu_cycles.c b/platform/linux-generic/arch/mips64/odp_cpu_arch.c index a20a31325..a20a31325 100644 --- a/platform/linux-generic/arch/mips64/odp_cpu_cycles.c +++ b/platform/linux-generic/arch/mips64/odp_cpu_arch.c diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c new file mode 100644 index 000000000..53074f7bd --- /dev/null +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c @@ -0,0 +1,64 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp_internal.h> +#include <string.h> + +int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) +{ + char str[1024]; + char *pos; + double mhz = 0.0; + uint64_t hz; + int model = 0; + int count = 2; + int id = 0; + + strcpy(sysinfo->cpu_arch_str, "mips64"); + while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) { + if (!mhz) { + pos = strstr(str, "BogoMIPS"); + + if (pos) + if (sscanf(pos, "BogoMIPS : %lf", &mhz) == 1) { + /* bogomips seems to be 2x freq */ + hz = (uint64_t)(mhz * 1000000.0 / 2.0); + sysinfo->cpu_hz_max[id] = hz; + count--; + } + } + + if (!model) { + pos = strstr(str, "cpu model"); + + if (pos) { + int len; + + pos = strchr(str, ':'); + strncpy(sysinfo->model_str[id], pos + 2, + sizeof(sysinfo->model_str[id])); + len = strlen(sysinfo->model_str[id]); + sysinfo->model_str[id][len - 1] = 0; + model = 1; + count--; + } + } + + if (count == 0) { + mhz = 0.0; + model = 0; + count = 2; + id++; + } + } + + return 0; +} + +uint64_t odp_cpu_hz_current(int id ODP_UNUSED) +{ + return 0; +} diff --git a/platform/linux-generic/arch/powerpc/odp/cpu_arch.h b/platform/linux-generic/arch/powerpc/odp/cpu_arch.h new file mode 120000 index 000000000..0617d7fa1 --- /dev/null +++ b/platform/linux-generic/arch/powerpc/odp/cpu_arch.h @@ -0,0 +1 @@ +../../linux/odp/cpu_arch.h
\ No newline at end of file diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c new file mode 120000 index 000000000..c5fe40085 --- /dev/null +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c @@ -0,0 +1 @@ +../linux/odp_cpu_arch.c
\ No newline at end of file diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c new file mode 100644 index 000000000..99457cec4 --- /dev/null +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c @@ -0,0 +1,63 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp_internal.h> +#include <string.h> + +int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) +{ + char str[1024]; + char *pos; + double mhz = 0.0; + uint64_t hz; + int model = 0; + int count = 2; + int id = 0; + + strcpy(sysinfo->cpu_arch_str, "powerpc"); + while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) { + if (!mhz) { + pos = strstr(str, "clock"); + + if (pos) + if (sscanf(pos, "clock : %lf", &mhz) == 1) { + hz = (uint64_t)(mhz * 1000000.0); + sysinfo->cpu_hz_max[id] = hz; + count--; + } + } + + if (!model) { + pos = strstr(str, "cpu"); + + if (pos) { + int len; + + pos = strchr(str, ':'); + strncpy(sysinfo->model_str[id], pos + 2, + sizeof(sysinfo->model_str[id])); + len = strlen(sysinfo->model_str[id]); + sysinfo->model_str[id][len - 1] = 0; + model = 1; + count--; + } + } + + if (count == 0) { + mhz = 0.0; + model = 0; + count = 2; + id++; + } + } + + return 0; +} + +uint64_t odp_cpu_hz_current(int id ODP_UNUSED) +{ + return 0; +} diff --git a/platform/linux-generic/arch/x86/odp/cpu_arch.h b/platform/linux-generic/arch/x86/odp/cpu_arch.h new file mode 100644 index 000000000..997a95475 --- /dev/null +++ b/platform/linux-generic/arch/x86/odp/cpu_arch.h @@ -0,0 +1,27 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PLAT_CPU_ARCH_H_ +#define ODP_PLAT_CPU_ARCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void odp_cpu_pause(void) +{ +#ifdef __SSE2__ + __asm__ __volatile__ ("pause"); +#else + __asm__ __volatile__ ("rep; nop"); +#endif +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/arch/x86/odp_cpu_cycles.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c index 1c5c0ec7f..1c5c0ec7f 100644 --- a/platform/linux-generic/arch/x86/odp_cpu_cycles.c +++ b/platform/linux-generic/arch/x86/odp_cpu_arch.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 000000000..816629dfa --- /dev/null +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -0,0 +1,73 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp_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; + uint64_t hz; + int id = 0; + + strcpy(sysinfo->cpu_arch_str, "x86"); + 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) { + hz = (uint64_t)(ghz * 1000000000.0); + sysinfo->cpu_hz_max[id] = hz; + } + 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 0; +} |