[CRIU] [PATCH 13/18] compel: Shrink cpuinfo fetching

Cyrill Gorcunov gorcunov at gmail.com
Thu Jul 19 15:47:41 MSK 2018


Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 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 15a49c420299..cfaab1e65740 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 15a49c420299..cfaab1e65740 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 d0e366e710a8..338ab4891f17 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 98503b191729..5d86bf2395f9 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 d422f91fd41a..9152765bf0ac 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));
 }
-- 
2.14.4



More information about the CRIU mailing list