From 5b8e5932ff9df45201ff1f19c14dfa4061abad61 Mon Sep 17 00:00:00 2001 From: Yassin-pixel-bit Date: Sun, 28 Jun 2026 02:49:04 +0300 Subject: [PATCH] fix: calculate apic_bits using maximum thread index Previously, the bitmask length for SMT cache grouping used the total core count. For a 2-thread cache, bit_length(2) allocated 2 bits, creating a mask that grouped 4 threads together. Changing this to bit_length(cores - 1) allocates exactly 1 bit, correctly masking 2 threads per cache instance. --- src/x86/cache/deterministic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/x86/cache/deterministic.c b/src/x86/cache/deterministic.c index f40ee713..e72cd419 100644 --- a/src/x86/cache/deterministic.c +++ b/src/x86/cache/deterministic.c @@ -151,7 +151,7 @@ bool cpuinfo_x86_decode_cache_properties(struct cpuid_regs regs, struct cpuinfo_ const uint32_t level = (regs.eax >> 5) & UINT32_C(0x7); const uint32_t cores = 1 + ((regs.eax >> 14) & UINT32_C(0x00000FFF)); - const uint32_t apic_bits = bit_length(cores); + const uint32_t apic_bits = bit_length(cores - 1); const uint32_t sets = 1 + regs.ecx; const uint32_t line_size = 1 + (regs.ebx & UINT32_C(0x00000FFF));