Skip to content

Commit 0c80f9e

Browse files
sudeep-hollagregkh
authored andcommitted
ACPI: PPTT: Leave the table mapped for the runtime usage
Currently, everytime an information needs to be fetched from the PPTT, the table is mapped via acpi_get_table() and unmapped after the use via acpi_put_table() which is fine. However we do this at runtime especially when the CPU is hotplugged out and plugged in back since we re-populate the cache topology and other information. However, with the support to fetch LLC information from the PPTT in the cpuhotplug path which is executed in the atomic context, it is preferred to avoid mapping and unmapping of the PPTT for every single use as the acpi_get_table() might sleep waiting for a mutex. In order to avoid the same, the table is needs to just mapped once on the boot CPU and is never unmapped allowing it to be used at runtime with out the hassle of mapping and unmapping the table. Reported-by: Guenter Roeck <linux@roeck-us.net> Cc: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> -- Hi Rafael, Sorry to bother you again on this PPTT changes. Guenter reported an issue with lockdep enabled in -next that include my cacheinfo/arch_topology changes to utilise LLC from PPTT in the CPU hotplug path. Please ack the change once you are happy so that I can get it merged with other fixes via Greg's tree. Regards, Sudeep Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://lore.kernel.org/r/20220720-arch_topo_fixes-v3-2-43d696288e84@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 11969d6 commit 0c80f9e

File tree

1 file changed

+47
-55
lines changed

1 file changed

+47
-55
lines changed

Diff for: drivers/acpi/pptt.c

+47-55
Original file line numberDiff line numberDiff line change
@@ -533,21 +533,37 @@ static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
533533
return -ENOENT;
534534
}
535535

536+
537+
static struct acpi_table_header *acpi_get_pptt(void)
538+
{
539+
static struct acpi_table_header *pptt;
540+
acpi_status status;
541+
542+
/*
543+
* PPTT will be used at runtime on every CPU hotplug in path, so we
544+
* don't need to call acpi_put_table() to release the table mapping.
545+
*/
546+
if (!pptt) {
547+
status = acpi_get_table(ACPI_SIG_PPTT, 0, &pptt);
548+
if (ACPI_FAILURE(status))
549+
acpi_pptt_warn_missing();
550+
}
551+
552+
return pptt;
553+
}
554+
536555
static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag)
537556
{
538557
struct acpi_table_header *table;
539-
acpi_status status;
540558
int retval;
541559

542-
status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
543-
if (ACPI_FAILURE(status)) {
544-
acpi_pptt_warn_missing();
560+
table = acpi_get_pptt();
561+
if (!table)
545562
return -ENOENT;
546-
}
563+
547564
retval = topology_get_acpi_cpu_tag(table, cpu, level, flag);
548565
pr_debug("Topology Setup ACPI CPU %d, level %d ret = %d\n",
549566
cpu, level, retval);
550-
acpi_put_table(table);
551567

552568
return retval;
553569
}
@@ -568,25 +584,20 @@ static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag)
568584
static int check_acpi_cpu_flag(unsigned int cpu, int rev, u32 flag)
569585
{
570586
struct acpi_table_header *table;
571-
acpi_status status;
572587
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
573588
struct acpi_pptt_processor *cpu_node = NULL;
574589
int ret = -ENOENT;
575590

576-
status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
577-
if (ACPI_FAILURE(status)) {
578-
acpi_pptt_warn_missing();
579-
return ret;
580-
}
591+
table = acpi_get_pptt();
592+
if (!table)
593+
return -ENOENT;
581594

582595
if (table->revision >= rev)
583596
cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
584597

585598
if (cpu_node)
586599
ret = (cpu_node->flags & flag) != 0;
587600

588-
acpi_put_table(table);
589-
590601
return ret;
591602
}
592603

@@ -605,18 +616,15 @@ int acpi_find_last_cache_level(unsigned int cpu)
605616
u32 acpi_cpu_id;
606617
struct acpi_table_header *table;
607618
int number_of_levels = 0;
608-
acpi_status status;
619+
620+
table = acpi_get_pptt();
621+
if (!table)
622+
return -ENOENT;
609623

610624
pr_debug("Cache Setup find last level CPU=%d\n", cpu);
611625

612626
acpi_cpu_id = get_acpi_id_for_cpu(cpu);
613-
status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
614-
if (ACPI_FAILURE(status)) {
615-
acpi_pptt_warn_missing();
616-
} else {
617-
number_of_levels = acpi_find_cache_levels(table, acpi_cpu_id);
618-
acpi_put_table(table);
619-
}
627+
number_of_levels = acpi_find_cache_levels(table, acpi_cpu_id);
620628
pr_debug("Cache Setup find last level level=%d\n", number_of_levels);
621629

622630
return number_of_levels;
@@ -638,20 +646,16 @@ int acpi_find_last_cache_level(unsigned int cpu)
638646
int cache_setup_acpi(unsigned int cpu)
639647
{
640648
struct acpi_table_header *table;
641-
acpi_status status;
642-
643-
pr_debug("Cache Setup ACPI CPU %d\n", cpu);
644649

645-
status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
646-
if (ACPI_FAILURE(status)) {
647-
acpi_pptt_warn_missing();
650+
table = acpi_get_pptt();
651+
if (!table)
648652
return -ENOENT;
649-
}
653+
654+
pr_debug("Cache Setup ACPI CPU %d\n", cpu);
650655

651656
cache_setup_acpi_cpu(table, cpu);
652-
acpi_put_table(table);
653657

654-
return status;
658+
return 0;
655659
}
656660

657661
/**
@@ -730,50 +734,38 @@ int find_acpi_cpu_topology_package(unsigned int cpu)
730734
int find_acpi_cpu_topology_cluster(unsigned int cpu)
731735
{
732736
struct acpi_table_header *table;
733-
acpi_status status;
734737
struct acpi_pptt_processor *cpu_node, *cluster_node;
735738
u32 acpi_cpu_id;
736739
int retval;
737740
int is_thread;
738741

739-
status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
740-
if (ACPI_FAILURE(status)) {
741-
acpi_pptt_warn_missing();
742+
table = acpi_get_pptt();
743+
if (!table)
742744
return -ENOENT;
743-
}
744745

745746
acpi_cpu_id = get_acpi_id_for_cpu(cpu);
746747
cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
747-
if (cpu_node == NULL || !cpu_node->parent) {
748-
retval = -ENOENT;
749-
goto put_table;
750-
}
748+
if (!cpu_node || !cpu_node->parent)
749+
return -ENOENT;
751750

752751
is_thread = cpu_node->flags & ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD;
753752
cluster_node = fetch_pptt_node(table, cpu_node->parent);
754-
if (cluster_node == NULL) {
755-
retval = -ENOENT;
756-
goto put_table;
757-
}
753+
if (!cluster_node)
754+
return -ENOENT;
755+
758756
if (is_thread) {
759-
if (!cluster_node->parent) {
760-
retval = -ENOENT;
761-
goto put_table;
762-
}
757+
if (!cluster_node->parent)
758+
return -ENOENT;
759+
763760
cluster_node = fetch_pptt_node(table, cluster_node->parent);
764-
if (cluster_node == NULL) {
765-
retval = -ENOENT;
766-
goto put_table;
767-
}
761+
if (!cluster_node)
762+
return -ENOENT;
768763
}
769764
if (cluster_node->flags & ACPI_PPTT_ACPI_PROCESSOR_ID_VALID)
770765
retval = cluster_node->acpi_processor_id;
771766
else
772767
retval = ACPI_PTR_DIFF(cluster_node, table);
773768

774-
put_table:
775-
acpi_put_table(table);
776-
777769
return retval;
778770
}
779771

0 commit comments

Comments
 (0)