Skip to content

Commit 9ff9f51

Browse files
committed
Don't try to count number of logical CPUs from CPUID itself
This topology enumeration process is very complex (https://web.archive.org/web/20160306203252/https://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration) and easy to get wrong. We have to rely on the operating system to allow us to switch CPUs, so we may as well rely on it to *count* CPUs as well.
1 parent 7a23453 commit 9ff9f51

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

tools/cpuid-dump.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,10 @@ int main(int argc, char** argv) {
105105
exit(1);
106106
}
107107
n_log_proc = CPU_COUNT(&mask_default);
108-
#endif
109-
if (max_base_index >= 1) {
110-
// TODO: handle case of >256 logical CPUs, or multiple packages
111-
const struct cpuid_regs regs = cpuid(1);
112-
uint32_t n_apic_id;
113-
if (regs.edx & UINT32_C(0x10000000)) { // Number of logical CPUs field is valid
114-
n_apic_id = ((regs.ebx & UINT32_C(0x00ff0000)) >> 16);
115-
116-
#ifdef __linux__
117-
if (n_apic_id != n_log_proc)
118-
fprintf(stderr,
119-
"WARNING: %d logical CPUs per CPUID.01h.EBX[23:16] != %d per sched_getaffinity()\n",
120-
n_apic_id,
121-
n_log_proc);
122108
#else
123-
if (n_apic_id > 1)
124-
fprintf(stderr,
125-
"WARNING: %d logical CPUs per CPUID.01h.EBX, results may vary by logical CPU\n",
126-
n_apic_id);
109+
fprintf(stderr,
110+
"WARNING: results may vary by CPU, core or thread, but switching CPU is unsupported.\n");
127111
#endif
128-
}
129-
}
130112

131113
for (uint32_t lp = 0; lp < n_log_proc; lp++) {
132114
force_one_cpu(lp, n_log_proc);

0 commit comments

Comments
 (0)