coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
hyperthreading.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
4 #include <arch/cpu.h>
5 #include <types.h>
6 
8 {
9  /* Is HyperThreading supported? */
10  return !!(cpuid_edx(1) & CPUID_FEAURE_HTT);
11 }
12 
13 /*
14  * Return true if running thread does not have the smallest lapic ID
15  * within a CPU core.
16  */
17 bool intel_ht_sibling(void)
18 {
19  struct cpuid_result result;
20  unsigned int core_ids, apic_ids;
21  unsigned int max_leaf;
22  uint32_t initial_lapicid, threads;
23 
24  if (!intel_ht_supported())
25  return false;
26 
27  max_leaf = cpuid_get_max_func();
28 
29  /* Detect from 32-bit X2APIC ID. */
30  if (max_leaf >= 0xb) {
31  result = cpuid_ext(0xb, 0);
32  threads = 1 << (result.eax & 0x1f);
33  initial_lapicid = result.edx;
34  return initial_lapicid % threads > 0;
35  }
36 
37  /* Detect from 8-bit XAPIC ID. */
38  result = cpuid_ext(0x1, 0);
39  initial_lapicid = result.ebx >> 24;
40  apic_ids = (result.ebx >> 16) & 0xff;
41  if (apic_ids == 0)
42  apic_ids = 1;
43 
44  core_ids = 1;
45  if (max_leaf >= 4) {
46  result = cpuid_ext(4, 0);
47  core_ids += (result.eax >> 26) & 0x3f;
48  }
49 
50  threads = (apic_ids / core_ids);
51  return initial_lapicid % threads > 0;
52 }
static unsigned int cpuid_edx(unsigned int op)
Definition: cpu.h:119
static unsigned int cpuid_get_max_func(void)
Definition: cpu.h:132
#define CPUID_FEAURE_HTT
Definition: cpu.h:154
static struct cpuid_result cpuid_ext(int op, unsigned int ecx)
Definition: cpu.h:59
bool intel_ht_sibling(void)
bool intel_ht_supported(void)
Definition: hyperthreading.c:7
static __always_inline unsigned int initial_lapicid(void)
Definition: lapic.h:126
result
Definition: mrc_cache.c:35
unsigned int uint32_t
Definition: stdint.h:14