mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
LoongArch: Retrieve CPU package ID from PPTT when available
Currently, the LoongArch CPU topology initialization code calculates
each core's package ID by dividing its physical ID by loongson_sysconf.
cores_per_package. This relies on the assumption that cores_per_package
counts in the same domain as physical IDs.
On Loongson-3B6000 (XB612B0V_1.2), cores_per_package matches the visible
core count -- 24 in this case. However, the physical IDs range from 0 to
31 in a noncontinuous fashion:
$ cat /proc/cpuinfo | grep -i -F 'global_id'
global_id : 0
global_id : 1
global_id : 4
global_id : 5
global_id : 6
global_id : 7
global_id : 8
global_id : 9
global_id : 10
global_id : 11
global_id : 14
global_id : 15
global_id : 16
global_id : 17
global_id : 20
global_id : 21
global_id : 22
global_id : 23
global_id : 26
global_id : 27
global_id : 28
global_id : 29
global_id : 30
global_id : 31
Retrieve the exact package ID from ACPI PPTT when available, in the same
style as retrieving the core ID and thread ID in parse_acpi_topology().
Use this information in loongson_init_secondary() when the PPTT readout
is successful. The original division logic is kept as a fallback.
Meanwhile, since some existing code paths like loongson3_cpufreq expect
a continuous integer sequence of package IDs in [0, MAX_PACKAGES) when
retrieving from cpu_data[], here we also canonicalize the package ID to
be filled in parse_acpi_topology() to meet such an expectation.
Cc: stable@vger.kernel.org
Tested-by: Mingcong Bai <jeffbai@aosc.io>
Co-developed-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Rong Bao <rong.bao@csmantle.top>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
This commit is contained in:
parent
ea68d444a6
commit
4e8f58620f
|
|
@ -201,10 +201,12 @@ static void __init acpi_process_madt(void)
|
|||
}
|
||||
|
||||
int pptt_enabled;
|
||||
static int acpi_nr_packages;
|
||||
static int acpi_package_ids[MAX_PACKAGES];
|
||||
|
||||
int __init parse_acpi_topology(void)
|
||||
{
|
||||
int cpu, topology_id;
|
||||
int i, cpu, topology_id;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
topology_id = find_acpi_cpu_topology(cpu, 0);
|
||||
|
|
@ -222,6 +224,29 @@ int __init parse_acpi_topology(void)
|
|||
|
||||
cpu_data[cpu].core = topology_id;
|
||||
}
|
||||
|
||||
topology_id = find_acpi_cpu_topology_package(cpu);
|
||||
if (topology_id < 0) {
|
||||
pr_warn("Invalid BIOS PPTT\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
for (i = 0; i < acpi_nr_packages; i++)
|
||||
if (acpi_package_ids[i] == topology_id)
|
||||
break;
|
||||
|
||||
if (i == acpi_nr_packages)
|
||||
acpi_package_ids[acpi_nr_packages++] = topology_id;
|
||||
|
||||
cpu_data[cpu].package = topology_id;
|
||||
}
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
for (i = 0; i < acpi_nr_packages; i++)
|
||||
if (cpu_data[cpu].package == acpi_package_ids[i]) {
|
||||
cpu_data[cpu].package = i; /* Canonicalize */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pptt_enabled = 1;
|
||||
|
|
|
|||
|
|
@ -426,10 +426,10 @@ void loongson_init_secondary(void)
|
|||
numa_add_cpu(cpu);
|
||||
#endif
|
||||
per_cpu(cpu_state, cpu) = CPU_ONLINE;
|
||||
cpu_data[cpu].package =
|
||||
cpu_logical_map(cpu) / loongson_sysconf.cores_per_package;
|
||||
cpu_data[cpu].core = pptt_enabled ? cpu_data[cpu].core :
|
||||
cpu_logical_map(cpu) % loongson_sysconf.cores_per_package;
|
||||
cpu_data[cpu].package = pptt_enabled ? cpu_data[cpu].package :
|
||||
cpu_logical_map(cpu) / loongson_sysconf.cores_per_package;
|
||||
cpu_data[cpu].global_id = cpu_logical_map(cpu);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user