Skip to content

Commit 37b502f

Browse files
Sebastian Andrzej SiewiorIngo Molnar
authored andcommitted
arm/perf: Fix hotplug state machine conversion
Mark Rutland pointed out that this commit is incomplete: 7d88eb6 ("arm/perf: Convert to hotplug state machine") The problem is that: > We may have multiple PMUs (e.g. two in big.LITTLE systems), and > __oprofile_cpu_pmu only contains one of these. So this conversion is not > correct. > > We were relying on the notifier list implicitly containing a list of > those PMUs. It seems like we need an explicit list here. > > We keep __oprofile_cpu_pmu around for legacy 32-bit users of OProfile > (on non-hetereogeneous systems), and that's all that the variable should > be used for. Introduce arm_pmu_list to correctly handle multiple PMUs in the system. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Acked-by: Mark Rutland <[email protected]> Cc: Anna-Maria Gleixner <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent c76c15e commit 37b502f

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

drivers/perf/arm_pmu.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,9 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
685685
return 0;
686686
}
687687

688+
static DEFINE_MUTEX(arm_pmu_mutex);
689+
static LIST_HEAD(arm_pmu_list);
690+
688691
/*
689692
* PMU hardware loses all context when a CPU goes offline.
690693
* When a CPU is hotplugged back in, since some hardware registers are
@@ -693,12 +696,17 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
693696
*/
694697
static int arm_perf_starting_cpu(unsigned int cpu)
695698
{
696-
if (!__oprofile_cpu_pmu)
697-
return 0;
698-
if (!cpumask_test_cpu(cpu, &__oprofile_cpu_pmu->supported_cpus))
699-
return 0;
700-
if (__oprofile_cpu_pmu->reset)
701-
__oprofile_cpu_pmu->reset(__oprofile_cpu_pmu);
699+
struct arm_pmu *pmu;
700+
701+
mutex_lock(&arm_pmu_mutex);
702+
list_for_each_entry(pmu, &arm_pmu_list, entry) {
703+
704+
if (!cpumask_test_cpu(cpu, &pmu->supported_cpus))
705+
continue;
706+
if (pmu->reset)
707+
pmu->reset(pmu);
708+
}
709+
mutex_unlock(&arm_pmu_mutex);
702710
return 0;
703711
}
704712

@@ -810,11 +818,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
810818
if (!cpu_hw_events)
811819
return -ENOMEM;
812820

813-
err = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_STARTING,
814-
"AP_PERF_ARM_STARTING",
815-
arm_perf_starting_cpu, NULL);
816-
if (err)
817-
goto out_hw_events;
821+
mutex_lock(&arm_pmu_mutex);
822+
list_add_tail(&cpu_pmu->entry, &arm_pmu_list);
823+
mutex_unlock(&arm_pmu_mutex);
818824

819825
err = cpu_pm_pmu_register(cpu_pmu);
820826
if (err)
@@ -850,16 +856,19 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
850856
return 0;
851857

852858
out_unregister:
853-
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_STARTING);
854-
out_hw_events:
859+
mutex_lock(&arm_pmu_mutex);
860+
list_del(&cpu_pmu->entry);
861+
mutex_unlock(&arm_pmu_mutex);
855862
free_percpu(cpu_hw_events);
856863
return err;
857864
}
858865

859866
static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
860867
{
861868
cpu_pm_pmu_unregister(cpu_pmu);
862-
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_STARTING);
869+
mutex_lock(&arm_pmu_mutex);
870+
list_del(&cpu_pmu->entry);
871+
mutex_unlock(&arm_pmu_mutex);
863872
free_percpu(cpu_pmu->hw_events);
864873
}
865874

@@ -1019,8 +1028,6 @@ int arm_pmu_device_probe(struct platform_device *pdev,
10191028
if (ret)
10201029
goto out_destroy;
10211030

1022-
WARN(__oprofile_cpu_pmu, "%s(): missing PMU strucure for CPU-hotplug\n",
1023-
__func__);
10241031
if (!__oprofile_cpu_pmu)
10251032
__oprofile_cpu_pmu = pmu;
10261033

@@ -1038,3 +1045,17 @@ int arm_pmu_device_probe(struct platform_device *pdev,
10381045
kfree(pmu);
10391046
return ret;
10401047
}
1048+
1049+
static int arm_pmu_hp_init(void)
1050+
{
1051+
int ret;
1052+
1053+
ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_STARTING,
1054+
"AP_PERF_ARM_STARTING",
1055+
arm_perf_starting_cpu, NULL);
1056+
if (ret)
1057+
pr_err("CPU hotplug notifier for ARM PMU could not be registered: %d\n",
1058+
ret);
1059+
return ret;
1060+
}
1061+
subsys_initcall(arm_pmu_hp_init);

include/linux/perf/arm_pmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct arm_pmu {
109109
DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
110110
struct platform_device *plat_device;
111111
struct pmu_hw_events __percpu *hw_events;
112+
struct list_head entry;
112113
struct notifier_block cpu_pm_nb;
113114
};
114115

0 commit comments

Comments
 (0)