From d98a1eee6ee9f47a439224f836ddf540975ae949 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 19 Jul 2018 15:47:41 +0300 Subject: [PATCH] compel: Shrink cpuinfo fetching Signed-off-by: Cyrill Gorcunov Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com> Signed-off-by: Andrei Vagin --- compel/arch/aarch64/src/lib/cpu.c | 41 ++++++++++++------------------- compel/arch/arm/src/lib/cpu.c | 41 ++++++++++++------------------- compel/arch/ppc64/src/lib/cpu.c | 41 ++++++++++++------------------- compel/arch/s390/src/lib/cpu.c | 38 +++++++++++----------------- compel/arch/x86/src/lib/cpu.c | 41 ++++++++++++------------------- 5 files changed, 78 insertions(+), 124 deletions(-) diff --git a/compel/arch/aarch64/src/lib/cpu.c b/compel/arch/aarch64/src/lib/cpu.c index 15a49c420..cfaab1e65 100644 --- a/compel/arch/aarch64/src/lib/cpu.c +++ b/compel/arch/aarch64/src/lib/cpu.c @@ -11,7 +11,16 @@ #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; -static bool rt_info_done = false; + +static void fetch_rt_cpuinfo(void) +{ + static bool rt_info_done = false; + + if (!rt_info_done) { + compel_cpuid(&rt_info); + rt_info_done = true; + } +} void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } @@ -21,54 +30,36 @@ int compel_cpuid(compel_cpuinfo_t *info) { return 0; } bool compel_cpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_cpu_cap(&rt_info, feature); } bool compel_fpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_fpu_cap(&rt_info, feature); } uint32_t compel_fpu_feature_size(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } uint32_t compel_fpu_feature_offset(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } void compel_cpu_clear_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_clear_cpu_cap(&rt_info, feature); } void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); memcpy(c, &rt_info, sizeof(rt_info)); } diff --git a/compel/arch/arm/src/lib/cpu.c b/compel/arch/arm/src/lib/cpu.c index 15a49c420..cfaab1e65 100644 --- a/compel/arch/arm/src/lib/cpu.c +++ b/compel/arch/arm/src/lib/cpu.c @@ -11,7 +11,16 @@ #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; -static bool rt_info_done = false; + +static void fetch_rt_cpuinfo(void) +{ + static bool rt_info_done = false; + + if (!rt_info_done) { + compel_cpuid(&rt_info); + rt_info_done = true; + } +} void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } @@ -21,54 +30,36 @@ int compel_cpuid(compel_cpuinfo_t *info) { return 0; } bool compel_cpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_cpu_cap(&rt_info, feature); } bool compel_fpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_fpu_cap(&rt_info, feature); } uint32_t compel_fpu_feature_size(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } uint32_t compel_fpu_feature_offset(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } void compel_cpu_clear_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_clear_cpu_cap(&rt_info, feature); } void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); memcpy(c, &rt_info, sizeof(rt_info)); } diff --git a/compel/arch/ppc64/src/lib/cpu.c b/compel/arch/ppc64/src/lib/cpu.c index d0e366e71..338ab4891 100644 --- a/compel/arch/ppc64/src/lib/cpu.c +++ b/compel/arch/ppc64/src/lib/cpu.c @@ -13,7 +13,16 @@ #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; -static bool rt_info_done = false; + +static void fetch_rt_cpuinfo(void) +{ + static bool rt_info_done = false; + + if (!rt_info_done) { + compel_cpuid(&rt_info); + rt_info_done = true; + } +} void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } @@ -35,54 +44,36 @@ int compel_cpuid(compel_cpuinfo_t *info) bool compel_cpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_cpu_cap(&rt_info, feature); } bool compel_fpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_fpu_cap(&rt_info, feature); } uint32_t compel_fpu_feature_size(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } uint32_t compel_fpu_feature_offset(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } void compel_cpu_clear_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_clear_cpu_cap(&rt_info, feature); } void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); memcpy(c, &rt_info, sizeof(rt_info)); } diff --git a/compel/arch/s390/src/lib/cpu.c b/compel/arch/s390/src/lib/cpu.c index 98503b191..5d86bf239 100644 --- a/compel/arch/s390/src/lib/cpu.c +++ b/compel/arch/s390/src/lib/cpu.c @@ -15,6 +15,14 @@ static compel_cpuinfo_t rt_info; static bool rt_info_done = false; +static void fetch_rt_cpuinfo(void) +{ + if (!rt_info_done) { + compel_cpuid(&rt_info); + rt_info_done = true; + } +} + void compel_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { } void compel_clear_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { } int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) { return 0; } @@ -35,54 +43,36 @@ int compel_cpuid(compel_cpuinfo_t *info) bool compel_cpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_cpu_cap(&rt_info, feature); } bool compel_fpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_fpu_cap(&rt_info, feature); } uint32_t compel_fpu_feature_offset(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } uint32_t compel_fpu_feature_size(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return 0; } void compel_cpu_clear_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_clear_cpu_cap(&rt_info, feature); } void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); memcpy(c, &rt_info, sizeof(rt_info)); } diff --git a/compel/arch/x86/src/lib/cpu.c b/compel/arch/x86/src/lib/cpu.c index d422f91fd..9152765bf 100644 --- a/compel/arch/x86/src/lib/cpu.c +++ b/compel/arch/x86/src/lib/cpu.c @@ -12,7 +12,16 @@ #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; -static bool rt_info_done = false; + +static void fetch_rt_cpuinfo(void) +{ + static bool rt_info_done = false; + + if (!rt_info_done) { + compel_cpuid(&rt_info); + rt_info_done = true; + } +} /* * Although we spell it out in here, the Processor Trace @@ -438,28 +447,19 @@ int compel_cpuid(compel_cpuinfo_t *c) bool compel_cpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_cpu_cap(&rt_info, feature); } bool compel_fpu_has_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_test_fpu_cap(&rt_info, feature); } uint32_t compel_fpu_feature_size(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); if (feature >= FIRST_EXTENDED_XFEATURE && feature < XFEATURE_MAX) return rt_info.xstate_sizes[feature]; @@ -468,10 +468,7 @@ uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_offset(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); if (feature >= FIRST_EXTENDED_XFEATURE && feature < XFEATURE_MAX) return rt_info.xstate_offsets[feature]; @@ -480,18 +477,12 @@ uint32_t compel_fpu_feature_offset(unsigned int feature) void compel_cpu_clear_feature(unsigned int feature) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); return compel_clear_cpu_cap(&rt_info, feature); } void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) { - if (!rt_info_done) { - compel_cpuid(&rt_info); - rt_info_done = true; - } + fetch_rt_cpuinfo(); memcpy(c, &rt_info, sizeof(rt_info)); }