2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

compel: Shrink cpuinfo fetching

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Cyrill Gorcunov
2018-07-19 15:47:41 +03:00
committed by Andrei Vagin
parent af96768301
commit d98a1eee6e
5 changed files with 78 additions and 124 deletions

View File

@@ -11,7 +11,16 @@
#define LOG_PREFIX "cpu: " #define LOG_PREFIX "cpu: "
static compel_cpuinfo_t rt_info; 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_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { }
void compel_clear_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) bool compel_cpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_cpu_cap(&rt_info, feature); return compel_test_cpu_cap(&rt_info, feature);
} }
bool compel_fpu_has_feature(unsigned int feature) bool compel_fpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_fpu_cap(&rt_info, feature); return compel_test_fpu_cap(&rt_info, feature);
} }
uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_size(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
uint32_t compel_fpu_feature_offset(unsigned int feature) uint32_t compel_fpu_feature_offset(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
void compel_cpu_clear_feature(unsigned int feature) void compel_cpu_clear_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_clear_cpu_cap(&rt_info, feature); return compel_clear_cpu_cap(&rt_info, feature);
} }
void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
memcpy(c, &rt_info, sizeof(rt_info)); memcpy(c, &rt_info, sizeof(rt_info));
} }

View File

@@ -11,7 +11,16 @@
#define LOG_PREFIX "cpu: " #define LOG_PREFIX "cpu: "
static compel_cpuinfo_t rt_info; 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_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { }
void compel_clear_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) bool compel_cpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_cpu_cap(&rt_info, feature); return compel_test_cpu_cap(&rt_info, feature);
} }
bool compel_fpu_has_feature(unsigned int feature) bool compel_fpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_fpu_cap(&rt_info, feature); return compel_test_fpu_cap(&rt_info, feature);
} }
uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_size(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
uint32_t compel_fpu_feature_offset(unsigned int feature) uint32_t compel_fpu_feature_offset(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
void compel_cpu_clear_feature(unsigned int feature) void compel_cpu_clear_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_clear_cpu_cap(&rt_info, feature); return compel_clear_cpu_cap(&rt_info, feature);
} }
void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
memcpy(c, &rt_info, sizeof(rt_info)); memcpy(c, &rt_info, sizeof(rt_info));
} }

View File

@@ -13,7 +13,16 @@
#define LOG_PREFIX "cpu: " #define LOG_PREFIX "cpu: "
static compel_cpuinfo_t rt_info; 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_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { }
void compel_clear_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) bool compel_cpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_cpu_cap(&rt_info, feature); return compel_test_cpu_cap(&rt_info, feature);
} }
bool compel_fpu_has_feature(unsigned int feature) bool compel_fpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_fpu_cap(&rt_info, feature); return compel_test_fpu_cap(&rt_info, feature);
} }
uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_size(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
uint32_t compel_fpu_feature_offset(unsigned int feature) uint32_t compel_fpu_feature_offset(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
void compel_cpu_clear_feature(unsigned int feature) void compel_cpu_clear_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_clear_cpu_cap(&rt_info, feature); return compel_clear_cpu_cap(&rt_info, feature);
} }
void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
memcpy(c, &rt_info, sizeof(rt_info)); memcpy(c, &rt_info, sizeof(rt_info));
} }

View File

@@ -15,6 +15,14 @@
static compel_cpuinfo_t rt_info; static compel_cpuinfo_t rt_info;
static bool rt_info_done = false; 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_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { }
void compel_clear_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; } 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) bool compel_cpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_cpu_cap(&rt_info, feature); return compel_test_cpu_cap(&rt_info, feature);
} }
bool compel_fpu_has_feature(unsigned int feature) bool compel_fpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_fpu_cap(&rt_info, feature); return compel_test_fpu_cap(&rt_info, feature);
} }
uint32_t compel_fpu_feature_offset(unsigned int feature) uint32_t compel_fpu_feature_offset(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_size(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return 0; return 0;
} }
void compel_cpu_clear_feature(unsigned int feature) void compel_cpu_clear_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_clear_cpu_cap(&rt_info, feature); return compel_clear_cpu_cap(&rt_info, feature);
} }
void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
memcpy(c, &rt_info, sizeof(rt_info)); memcpy(c, &rt_info, sizeof(rt_info));
} }

View File

@@ -12,7 +12,16 @@
#define LOG_PREFIX "cpu: " #define LOG_PREFIX "cpu: "
static compel_cpuinfo_t rt_info; 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 * 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) bool compel_cpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_cpu_cap(&rt_info, feature); return compel_test_cpu_cap(&rt_info, feature);
} }
bool compel_fpu_has_feature(unsigned int feature) bool compel_fpu_has_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_test_fpu_cap(&rt_info, feature); return compel_test_fpu_cap(&rt_info, feature);
} }
uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_size(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
if (feature >= FIRST_EXTENDED_XFEATURE && if (feature >= FIRST_EXTENDED_XFEATURE &&
feature < XFEATURE_MAX) feature < XFEATURE_MAX)
return rt_info.xstate_sizes[feature]; 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) uint32_t compel_fpu_feature_offset(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
if (feature >= FIRST_EXTENDED_XFEATURE && if (feature >= FIRST_EXTENDED_XFEATURE &&
feature < XFEATURE_MAX) feature < XFEATURE_MAX)
return rt_info.xstate_offsets[feature]; 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) void compel_cpu_clear_feature(unsigned int feature)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
return compel_clear_cpu_cap(&rt_info, feature); return compel_clear_cpu_cap(&rt_info, feature);
} }
void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c) void compel_cpu_copy_cpuinfo(compel_cpuinfo_t *c)
{ {
if (!rt_info_done) { fetch_rt_cpuinfo();
compel_cpuid(&rt_info);
rt_info_done = true;
}
memcpy(c, &rt_info, sizeof(rt_info)); memcpy(c, &rt_info, sizeof(rt_info));
} }