Commit 37b502f1 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Ingo Molnar

arm/perf: Fix hotplug state machine conversion

Mark Rutland pointed out that this commit is incomplete:

  7d88eb69 ("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: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-tip-commits@vger.kernel.org
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20160719111733.GA22911@linutronix.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent c76c15e6
...@@ -685,6 +685,9 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) ...@@ -685,6 +685,9 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
return 0; return 0;
} }
static DEFINE_MUTEX(arm_pmu_mutex);
static LIST_HEAD(arm_pmu_list);
/* /*
* PMU hardware loses all context when a CPU goes offline. * PMU hardware loses all context when a CPU goes offline.
* When a CPU is hotplugged back in, since some hardware registers are * 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) ...@@ -693,12 +696,17 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
*/ */
static int arm_perf_starting_cpu(unsigned int cpu) static int arm_perf_starting_cpu(unsigned int cpu)
{ {
if (!__oprofile_cpu_pmu) struct arm_pmu *pmu;
return 0;
if (!cpumask_test_cpu(cpu, &__oprofile_cpu_pmu->supported_cpus)) mutex_lock(&arm_pmu_mutex);
return 0; list_for_each_entry(pmu, &arm_pmu_list, entry) {
if (__oprofile_cpu_pmu->reset)
__oprofile_cpu_pmu->reset(__oprofile_cpu_pmu); if (!cpumask_test_cpu(cpu, &pmu->supported_cpus))
continue;
if (pmu->reset)
pmu->reset(pmu);
}
mutex_unlock(&arm_pmu_mutex);
return 0; return 0;
} }
...@@ -810,11 +818,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu) ...@@ -810,11 +818,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
if (!cpu_hw_events) if (!cpu_hw_events)
return -ENOMEM; return -ENOMEM;
err = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_STARTING, mutex_lock(&arm_pmu_mutex);
"AP_PERF_ARM_STARTING", list_add_tail(&cpu_pmu->entry, &arm_pmu_list);
arm_perf_starting_cpu, NULL); mutex_unlock(&arm_pmu_mutex);
if (err)
goto out_hw_events;
err = cpu_pm_pmu_register(cpu_pmu); err = cpu_pm_pmu_register(cpu_pmu);
if (err) if (err)
...@@ -850,8 +856,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu) ...@@ -850,8 +856,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
return 0; return 0;
out_unregister: out_unregister:
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_STARTING); mutex_lock(&arm_pmu_mutex);
out_hw_events: list_del(&cpu_pmu->entry);
mutex_unlock(&arm_pmu_mutex);
free_percpu(cpu_hw_events); free_percpu(cpu_hw_events);
return err; return err;
} }
...@@ -859,7 +866,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu) ...@@ -859,7 +866,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu) static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
{ {
cpu_pm_pmu_unregister(cpu_pmu); cpu_pm_pmu_unregister(cpu_pmu);
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_STARTING); mutex_lock(&arm_pmu_mutex);
list_del(&cpu_pmu->entry);
mutex_unlock(&arm_pmu_mutex);
free_percpu(cpu_pmu->hw_events); free_percpu(cpu_pmu->hw_events);
} }
...@@ -1019,8 +1028,6 @@ int arm_pmu_device_probe(struct platform_device *pdev, ...@@ -1019,8 +1028,6 @@ int arm_pmu_device_probe(struct platform_device *pdev,
if (ret) if (ret)
goto out_destroy; goto out_destroy;
WARN(__oprofile_cpu_pmu, "%s(): missing PMU strucure for CPU-hotplug\n",
__func__);
if (!__oprofile_cpu_pmu) if (!__oprofile_cpu_pmu)
__oprofile_cpu_pmu = pmu; __oprofile_cpu_pmu = pmu;
...@@ -1038,3 +1045,17 @@ int arm_pmu_device_probe(struct platform_device *pdev, ...@@ -1038,3 +1045,17 @@ int arm_pmu_device_probe(struct platform_device *pdev,
kfree(pmu); kfree(pmu);
return ret; return ret;
} }
static int arm_pmu_hp_init(void)
{
int ret;
ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_STARTING,
"AP_PERF_ARM_STARTING",
arm_perf_starting_cpu, NULL);
if (ret)
pr_err("CPU hotplug notifier for ARM PMU could not be registered: %d\n",
ret);
return ret;
}
subsys_initcall(arm_pmu_hp_init);
...@@ -109,6 +109,7 @@ struct arm_pmu { ...@@ -109,6 +109,7 @@ struct arm_pmu {
DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
struct platform_device *plat_device; struct platform_device *plat_device;
struct pmu_hw_events __percpu *hw_events; struct pmu_hw_events __percpu *hw_events;
struct list_head entry;
struct notifier_block cpu_pm_nb; struct notifier_block cpu_pm_nb;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment