Skip to content

Commit 77c9122

Browse files
committed
read cpu info from cpuid.info file.
Instrumented cpuinfo to read the populated cpu info data from cpuid.info file during initialization. Consumers of the library or OEMs can trigger a oneshot service - cpuinfo-svc - during device boot to link libcpuinfo and dump all cpu info related to processor, model, arch and isa capabilities into cpuid.info file. This arrangement will limit cpuid() intrinsic calls (which causes VM-Exit events) to only once during init of libcpuinfo at boot by cpuinfo-svc. Signed-off-by: Unnithan, Balakrishnan <[email protected]>
1 parent a5ff6df commit 77c9122

File tree

10 files changed

+397
-157
lines changed

10 files changed

+397
-157
lines changed

deps/clog/include/clog.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
#define CLOG_DEBUG 5
1313

1414
#ifndef CLOG_VISIBILITY
15-
#if defined(__ELF__)
15+
#if defined(__GNUC__)
16+
// ld.lld: error: undefined hidden symbol: clog_vlog_error
17+
// referenced by log.h:16 (external/cpuinfo/src/cpuinfo/log.h)
18+
#define CLOG_VISIBILITY
19+
#elif defined(__ELF__)
1620
#define CLOG_VISIBILITY __attribute__((__visibility__("internal")))
1721
#elif defined(__MACH__)
1822
#define CLOG_VISIBILITY __attribute__((__visibility__("hidden")))

include/cpuinfo.h

+27
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,38 @@ struct cpuinfo_x86_isa {
860860
bool phe;
861861
bool pmm;
862862
bool lwp;
863+
bool erms;
864+
bool smap;
865+
bool serialize;
863866
};
864867

865868
extern struct cpuinfo_x86_isa cpuinfo_isa;
866869
#endif
867870

871+
static inline bool cpuinfo_has_x86_erms(void) {
872+
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
873+
return cpuinfo_isa.erms;
874+
#else
875+
return false;
876+
#endif
877+
}
878+
879+
static inline bool cpuinfo_has_x86_smap(void) {
880+
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
881+
return cpuinfo_isa.smap;
882+
#else
883+
return false;
884+
#endif
885+
}
886+
887+
static inline bool cpuinfo_has_x86_serialize(void) {
888+
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
889+
return cpuinfo_isa.serialize;
890+
#else
891+
return false;
892+
#endif
893+
}
894+
868895
static inline bool cpuinfo_has_x86_rdtsc(void) {
869896
#if CPUINFO_ARCH_X86_64
870897
return true;

src/x86/api.h

+20-43
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ struct cpuinfo_x86_caches {
3333
uint32_t prefetch_size;
3434
};
3535

36+
struct cpuinfo_x86_tlbs {
37+
struct cpuinfo_tlb itlb_4KB;
38+
struct cpuinfo_tlb itlb_2MB;
39+
struct cpuinfo_tlb itlb_4MB;
40+
struct cpuinfo_tlb dtlb0_4KB;
41+
struct cpuinfo_tlb dtlb0_2MB;
42+
struct cpuinfo_tlb dtlb0_4MB;
43+
struct cpuinfo_tlb dtlb_4KB;
44+
struct cpuinfo_tlb dtlb_2MB;
45+
struct cpuinfo_tlb dtlb_4MB;
46+
struct cpuinfo_tlb dtlb_1GB;
47+
struct cpuinfo_tlb stlb2_4KB;
48+
struct cpuinfo_tlb stlb2_2MB;
49+
struct cpuinfo_tlb stlb2_1GB;
50+
};
51+
3652
struct cpuinfo_x86_model_info {
3753
uint32_t model;
3854
uint32_t family;
@@ -61,21 +77,7 @@ struct cpuinfo_x86_processor {
6177
int linux_id;
6278
#endif
6379
struct cpuinfo_x86_caches cache;
64-
struct {
65-
struct cpuinfo_tlb itlb_4KB;
66-
struct cpuinfo_tlb itlb_2MB;
67-
struct cpuinfo_tlb itlb_4MB;
68-
struct cpuinfo_tlb dtlb0_4KB;
69-
struct cpuinfo_tlb dtlb0_2MB;
70-
struct cpuinfo_tlb dtlb0_4MB;
71-
struct cpuinfo_tlb dtlb_4KB;
72-
struct cpuinfo_tlb dtlb_2MB;
73-
struct cpuinfo_tlb dtlb_4MB;
74-
struct cpuinfo_tlb dtlb_1GB;
75-
struct cpuinfo_tlb stlb2_4KB;
76-
struct cpuinfo_tlb stlb2_2MB;
77-
struct cpuinfo_tlb stlb2_1GB;
78-
} tlb;
80+
struct cpuinfo_x86_tlbs tlb;
7981
struct cpuinfo_x86_topology topology;
8082
char brand_string[CPUINFO_PACKAGE_NAME_MAX];
8183
};
@@ -109,40 +111,15 @@ CPUINFO_INTERNAL void cpuinfo_x86_detect_cache(
109111
enum cpuinfo_vendor vendor,
110112
const struct cpuinfo_x86_model_info* model_info,
111113
struct cpuinfo_x86_caches* cache,
112-
struct cpuinfo_tlb* itlb_4KB,
113-
struct cpuinfo_tlb* itlb_2MB,
114-
struct cpuinfo_tlb* itlb_4MB,
115-
struct cpuinfo_tlb* dtlb0_4KB,
116-
struct cpuinfo_tlb* dtlb0_2MB,
117-
struct cpuinfo_tlb* dtlb0_4MB,
118-
struct cpuinfo_tlb* dtlb_4KB,
119-
struct cpuinfo_tlb* dtlb_2MB,
120-
struct cpuinfo_tlb* dtlb_4MB,
121-
struct cpuinfo_tlb* dtlb_1GB,
122-
struct cpuinfo_tlb* stlb2_4KB,
123-
struct cpuinfo_tlb* stlb2_2MB,
124-
struct cpuinfo_tlb* stlb2_1GB,
125-
uint32_t* log2_package_cores_max);
114+
struct cpuinfo_x86_tlbs* tlb,
115+
struct cpuinfo_x86_topology* topology);
126116

127117
CPUINFO_INTERNAL void cpuinfo_x86_decode_cache_descriptor(
128118
uint8_t descriptor,
129119
enum cpuinfo_vendor vendor,
130120
const struct cpuinfo_x86_model_info* model_info,
131121
struct cpuinfo_x86_caches* cache,
132-
struct cpuinfo_tlb* itlb_4KB,
133-
struct cpuinfo_tlb* itlb_2MB,
134-
struct cpuinfo_tlb* itlb_4MB,
135-
struct cpuinfo_tlb* dtlb0_4KB,
136-
struct cpuinfo_tlb* dtlb0_2MB,
137-
struct cpuinfo_tlb* dtlb0_4MB,
138-
struct cpuinfo_tlb* dtlb_4KB,
139-
struct cpuinfo_tlb* dtlb_2MB,
140-
struct cpuinfo_tlb* dtlb_4MB,
141-
struct cpuinfo_tlb* dtlb_1GB,
142-
struct cpuinfo_tlb* stlb2_4KB,
143-
struct cpuinfo_tlb* stlb2_2MB,
144-
struct cpuinfo_tlb* stlb2_1GB,
145-
uint32_t* prefetch_size);
122+
struct cpuinfo_x86_tlbs* tlb);
146123

147124
CPUINFO_INTERNAL bool cpuinfo_x86_decode_deterministic_cache_parameters(
148125
struct cpuid_regs regs,

0 commit comments

Comments
 (0)