Skip to content

Commit 700d098

Browse files
yghannamgregkh
authored andcommitted
x86/CPU/AMD: Save AMD NodeId as cpu_die_id
[ Upstream commit 028c221 ] AMD systems provide a "NodeId" value that represents a global ID indicating to which "Node" a logical CPU belongs. The "Node" is a physical structure equivalent to a Die, and it should not be confused with logical structures like NUMA nodes. Logical nodes can be adjusted based on firmware or other settings whereas the physical nodes/dies are fixed based on hardware topology. The NodeId value can be used when a physical ID is needed by software. Save the AMD NodeId to struct cpuinfo_x86.cpu_die_id. Use the value from CPUID or MSR as appropriate. Default to phys_proc_id otherwise. Do so for both AMD and Hygon systems. Drop the node_id parameter from cacheinfo_*_init_llc_id() as it is no longer needed. Update the x86 topology documentation. Suggested-by: Borislav Petkov <[email protected]> Signed-off-by: Yazen Ghannam <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent bb25fd4 commit 700d098

5 files changed

Lines changed: 24 additions & 17 deletions

File tree

Documentation/x86/topology.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Package
4141
Packages contain a number of cores plus shared resources, e.g. DRAM
4242
controller, shared caches etc.
4343

44+
Modern systems may also use the term 'Die' for package.
45+
4446
AMD nomenclature for package is 'Node'.
4547

4648
Package-related topology information in the kernel:
@@ -53,11 +55,18 @@ Package-related topology information in the kernel:
5355

5456
The number of dies in a package. This information is retrieved via CPUID.
5557

58+
- cpuinfo_x86.cpu_die_id:
59+
60+
The physical ID of the die. This information is retrieved via CPUID.
61+
5662
- cpuinfo_x86.phys_proc_id:
5763

5864
The physical ID of the package. This information is retrieved via CPUID
5965
and deduced from the APIC IDs of the cores in the package.
6066

67+
Modern systems use this value for the socket. There may be multiple
68+
packages within a socket. This value may differ from cpu_die_id.
69+
6170
- cpuinfo_x86.logical_proc_id:
6271

6372
The logical ID of the package. As we do not trust BIOSes to enumerate the

arch/x86/include/asm/cacheinfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef _ASM_X86_CACHEINFO_H
33
#define _ASM_X86_CACHEINFO_H
44

5-
void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id);
6-
void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id);
5+
void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu);
6+
void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu);
77

88
#endif /* _ASM_X86_CACHEINFO_H */

arch/x86/kernel/cpu/amd.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ static void legacy_fixup_core_id(struct cpuinfo_x86 *c)
330330
*/
331331
static void amd_get_topology(struct cpuinfo_x86 *c)
332332
{
333-
u8 node_id;
334333
int cpu = smp_processor_id();
335334

336335
/* get information required for multi-node processors */
@@ -340,7 +339,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
340339

341340
cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
342341

343-
node_id = ecx & 0xff;
342+
c->cpu_die_id = ecx & 0xff;
344343

345344
if (c->x86 == 0x15)
346345
c->cu_id = ebx & 0xff;
@@ -360,15 +359,15 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
360359
if (!err)
361360
c->x86_coreid_bits = get_count_order(c->x86_max_cores);
362361

363-
cacheinfo_amd_init_llc_id(c, cpu, node_id);
362+
cacheinfo_amd_init_llc_id(c, cpu);
364363

365364
} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
366365
u64 value;
367366

368367
rdmsrl(MSR_FAM10H_NODE_ID, value);
369-
node_id = value & 7;
368+
c->cpu_die_id = value & 7;
370369

371-
per_cpu(cpu_llc_id, cpu) = node_id;
370+
per_cpu(cpu_llc_id, cpu) = c->cpu_die_id;
372371
} else
373372
return;
374373

@@ -393,7 +392,7 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)
393392
/* Convert the initial APIC ID into the socket ID */
394393
c->phys_proc_id = c->initial_apicid >> bits;
395394
/* use socket ID also for last level cache */
396-
per_cpu(cpu_llc_id, cpu) = c->phys_proc_id;
395+
per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id;
397396
}
398397

399398
static void amd_detect_ppin(struct cpuinfo_x86 *c)

arch/x86/kernel/cpu/cacheinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *c)
646646
return i;
647647
}
648648

649-
void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
649+
void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)
650650
{
651651
/*
652652
* We may have multiple LLCs if L3 caches exist, so check if we
@@ -657,7 +657,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
657657

658658
if (c->x86 < 0x17) {
659659
/* LLC is at the node level. */
660-
per_cpu(cpu_llc_id, cpu) = node_id;
660+
per_cpu(cpu_llc_id, cpu) = c->cpu_die_id;
661661
} else if (c->x86 == 0x17 && c->x86_model <= 0x1F) {
662662
/*
663663
* LLC is at the core complex level.
@@ -684,7 +684,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
684684
}
685685
}
686686

687-
void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
687+
void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu)
688688
{
689689
/*
690690
* We may have multiple LLCs if L3 caches exist, so check if we

arch/x86/kernel/cpu/hygon.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ static void hygon_get_topology_early(struct cpuinfo_x86 *c)
6565
*/
6666
static void hygon_get_topology(struct cpuinfo_x86 *c)
6767
{
68-
u8 node_id;
6968
int cpu = smp_processor_id();
7069

7170
/* get information required for multi-node processors */
@@ -75,7 +74,7 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)
7574

7675
cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
7776

78-
node_id = ecx & 0xff;
77+
c->cpu_die_id = ecx & 0xff;
7978

8079
c->cpu_core_id = ebx & 0xff;
8180

@@ -93,14 +92,14 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)
9392
/* Socket ID is ApicId[6] for these processors. */
9493
c->phys_proc_id = c->apicid >> APICID_SOCKET_ID_BIT;
9594

96-
cacheinfo_hygon_init_llc_id(c, cpu, node_id);
95+
cacheinfo_hygon_init_llc_id(c, cpu);
9796
} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
9897
u64 value;
9998

10099
rdmsrl(MSR_FAM10H_NODE_ID, value);
101-
node_id = value & 7;
100+
c->cpu_die_id = value & 7;
102101

103-
per_cpu(cpu_llc_id, cpu) = node_id;
102+
per_cpu(cpu_llc_id, cpu) = c->cpu_die_id;
104103
} else
105104
return;
106105

@@ -123,7 +122,7 @@ static void hygon_detect_cmp(struct cpuinfo_x86 *c)
123122
/* Convert the initial APIC ID into the socket ID */
124123
c->phys_proc_id = c->initial_apicid >> bits;
125124
/* use socket ID also for last level cache */
126-
per_cpu(cpu_llc_id, cpu) = c->phys_proc_id;
125+
per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id;
127126
}
128127

129128
static void srat_detect_node(struct cpuinfo_x86 *c)

0 commit comments

Comments
 (0)