Skip to content

Commit f35c09e

Browse files
committed
Ignore disabled hyperthreads
Only consider processors with an APIC_ID as valid. For processors with Hyperthreads but disabled SMT the APIC_ID will never be set and stays zero for the "disabled" threads. Among other inconsistencies this causes the first active thread/processor to be considered "the same" as all the disabled ones as they share `APIC_ID=0` It also doesn't make sense to make and decisions based on the APIC_ID if we don't have any information on it.
1 parent 39ea79a commit f35c09e

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/x86/linux/cpuinfo.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ struct proc_cpuinfo_parser_state {
8080
* Decode a single line of /proc/cpuinfo information.
8181
* Lines have format <words-with-spaces>[ ]*:[ ]<space-separated words>
8282
*/
83-
static bool parse_line(
84-
const char* line_start,
85-
const char* line_end,
86-
void* context,
87-
uint64_t line_number) {
83+
static bool parse_line(const char* line_start, const char* line_end, void* context, uint64_t line_number) {
8884
struct proc_cpuinfo_parser_state* restrict state = context;
8985
/* Empty line. Skip. */
9086
if (line_start == line_end) {
@@ -215,6 +211,5 @@ bool cpuinfo_x86_linux_parse_proc_cpuinfo(
215211
.max_processors_count = max_processors_count,
216212
.processors = processors,
217213
};
218-
return cpuinfo_linux_parse_multiline_file(
219-
"/proc/cpuinfo", BUFFER_SIZE, parse_line, &state);
214+
return cpuinfo_linux_parse_multiline_file("/proc/cpuinfo", BUFFER_SIZE, parse_line, &state);
220215
}

src/x86/linux/init.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ static void cpuinfo_x86_count_objects(
4747
uint32_t linux_processors_count,
4848
const struct cpuinfo_x86_linux_processor linux_processors[restrict static linux_processors_count],
4949
const struct cpuinfo_x86_processor processor[restrict static 1],
50-
uint32_t valid_processor_mask,
5150
uint32_t llc_apic_bits,
5251
uint32_t cores_count_ptr[restrict static 1],
5352
uint32_t clusters_count_ptr[restrict static 1],
@@ -70,7 +69,7 @@ static void cpuinfo_x86_count_objects(
7069
uint32_t last_l1i_id = UINT32_MAX, last_l1d_id = UINT32_MAX;
7170
uint32_t last_l2_id = UINT32_MAX, last_l3_id = UINT32_MAX, last_l4_id = UINT32_MAX;
7271
for (uint32_t i = 0; i < linux_processors_count; i++) {
73-
if (bitmask_all(linux_processors[i].flags, valid_processor_mask)) {
72+
if (bitmask_all(linux_processors[i].flags, CPUINFO_LINUX_FLAG_VALID)) {
7473
const uint32_t apic_id = linux_processors[i].apic_id;
7574
cpuinfo_log_debug(
7675
"APID ID %" PRIu32 ": system processor %" PRIu32,
@@ -167,13 +166,13 @@ void cpuinfo_x86_linux_init(void) {
167166
const uint32_t max_present_processors_count = 1 + cpuinfo_linux_get_max_present_processor(max_processors_count);
168167
cpuinfo_log_debug("maximum present processors count: %" PRIu32, max_present_processors_count);
169168

170-
uint32_t valid_processor_mask = 0;
169+
uint32_t valid_processor_mask = CPUINFO_LINUX_FLAG_APIC_ID;
171170
uint32_t x86_linux_processors_count = max_processors_count;
172171
if (max_present_processors_count != 0) {
173172
x86_linux_processors_count = min(x86_linux_processors_count, max_present_processors_count);
174-
valid_processor_mask = CPUINFO_LINUX_FLAG_PRESENT;
173+
valid_processor_mask |= CPUINFO_LINUX_FLAG_PRESENT;
175174
} else {
176-
valid_processor_mask = CPUINFO_LINUX_FLAG_PROC_CPUINFO;
175+
valid_processor_mask |= CPUINFO_LINUX_FLAG_PROC_CPUINFO;
177176
}
178177
if (max_possible_processors_count != 0) {
179178
x86_linux_processors_count = min(x86_linux_processors_count, max_possible_processors_count);
@@ -260,7 +259,6 @@ void cpuinfo_x86_linux_init(void) {
260259
x86_linux_processors_count,
261260
x86_linux_processors,
262261
&x86_processor,
263-
valid_processor_mask,
264262
llc_apic_bits,
265263
&cores_count,
266264
&clusters_count,

0 commit comments

Comments
 (0)