perf/x86/amd/power: Convert the hotplug notifier to state machine
Install the callbacks via the state machine. Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de> Cc: Borislav Petkov <bp@suse.de> Cc: Huang Rui <ray.huang@amd.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: rt@linutronix.de Link: http://lkml.kernel.org/r/20160713153335.027571056@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Родитель
89ab9cb169
Коммит
c6a84daa34
|
@ -228,12 +228,12 @@ static struct pmu pmu_class = {
|
||||||
.read = pmu_event_read,
|
.read = pmu_event_read,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void power_cpu_exit(int cpu)
|
static int power_cpu_exit(unsigned int cpu)
|
||||||
{
|
{
|
||||||
int target;
|
int target;
|
||||||
|
|
||||||
if (!cpumask_test_and_clear_cpu(cpu, &cpu_mask))
|
if (!cpumask_test_and_clear_cpu(cpu, &cpu_mask))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find a new CPU on the same compute unit, if was set in cpumask
|
* Find a new CPU on the same compute unit, if was set in cpumask
|
||||||
|
@ -245,9 +245,10 @@ static void power_cpu_exit(int cpu)
|
||||||
cpumask_set_cpu(target, &cpu_mask);
|
cpumask_set_cpu(target, &cpu_mask);
|
||||||
perf_pmu_migrate_context(&pmu_class, cpu, target);
|
perf_pmu_migrate_context(&pmu_class, cpu, target);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void power_cpu_init(int cpu)
|
static int power_cpu_init(unsigned int cpu)
|
||||||
{
|
{
|
||||||
int target;
|
int target;
|
||||||
|
|
||||||
|
@ -263,33 +264,9 @@ static void power_cpu_init(int cpu)
|
||||||
target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
|
target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
|
||||||
if (target >= nr_cpumask_bits)
|
if (target >= nr_cpumask_bits)
|
||||||
cpumask_set_cpu(cpu, &cpu_mask);
|
cpumask_set_cpu(cpu, &cpu_mask);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
power_cpu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
|
|
||||||
{
|
|
||||||
unsigned int cpu = (long)hcpu;
|
|
||||||
|
|
||||||
switch (action & ~CPU_TASKS_FROZEN) {
|
|
||||||
case CPU_DOWN_FAILED:
|
|
||||||
case CPU_ONLINE:
|
|
||||||
power_cpu_init(cpu);
|
|
||||||
break;
|
|
||||||
case CPU_DOWN_PREPARE:
|
|
||||||
power_cpu_exit(cpu);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NOTIFY_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct notifier_block power_cpu_notifier_nb = {
|
|
||||||
.notifier_call = power_cpu_notifier,
|
|
||||||
.priority = CPU_PRI_PERF,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct x86_cpu_id cpu_match[] = {
|
static const struct x86_cpu_id cpu_match[] = {
|
||||||
{ .vendor = X86_VENDOR_AMD, .family = 0x15 },
|
{ .vendor = X86_VENDOR_AMD, .family = 0x15 },
|
||||||
{},
|
{},
|
||||||
|
@ -297,7 +274,7 @@ static const struct x86_cpu_id cpu_match[] = {
|
||||||
|
|
||||||
static int __init amd_power_pmu_init(void)
|
static int __init amd_power_pmu_init(void)
|
||||||
{
|
{
|
||||||
int cpu, target, ret;
|
int ret;
|
||||||
|
|
||||||
if (!x86_match_cpu(cpu_match))
|
if (!x86_match_cpu(cpu_match))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -312,38 +289,25 @@ static int __init amd_power_pmu_init(void)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpu_notifier_register_begin();
|
|
||||||
|
|
||||||
/* Choose one online core of each compute unit. */
|
cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
|
||||||
for_each_online_cpu(cpu) {
|
"AP_PERF_X86_AMD_POWER_ONLINE",
|
||||||
target = cpumask_first(topology_sibling_cpumask(cpu));
|
power_cpu_init, power_cpu_exit);
|
||||||
if (!cpumask_test_cpu(target, &cpu_mask))
|
|
||||||
cpumask_set_cpu(target, &cpu_mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = perf_pmu_register(&pmu_class, "power", -1);
|
ret = perf_pmu_register(&pmu_class, "power", -1);
|
||||||
if (WARN_ON(ret)) {
|
if (WARN_ON(ret)) {
|
||||||
pr_warn("AMD Power PMU registration failed\n");
|
pr_warn("AMD Power PMU registration failed\n");
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
__register_cpu_notifier(&power_cpu_notifier_nb);
|
|
||||||
|
|
||||||
pr_info("AMD Power PMU detected\n");
|
pr_info("AMD Power PMU detected\n");
|
||||||
|
|
||||||
out:
|
|
||||||
cpu_notifier_register_done();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
module_init(amd_power_pmu_init);
|
module_init(amd_power_pmu_init);
|
||||||
|
|
||||||
static void __exit amd_power_pmu_exit(void)
|
static void __exit amd_power_pmu_exit(void)
|
||||||
{
|
{
|
||||||
cpu_notifier_register_begin();
|
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE);
|
||||||
__unregister_cpu_notifier(&power_cpu_notifier_nb);
|
|
||||||
cpu_notifier_register_done();
|
|
||||||
|
|
||||||
perf_pmu_unregister(&pmu_class);
|
perf_pmu_unregister(&pmu_class);
|
||||||
}
|
}
|
||||||
module_exit(amd_power_pmu_exit);
|
module_exit(amd_power_pmu_exit);
|
||||||
|
|
|
@ -41,6 +41,7 @@ enum cpuhp_state {
|
||||||
CPUHP_AP_PERF_X86_ONLINE,
|
CPUHP_AP_PERF_X86_ONLINE,
|
||||||
CPUHP_AP_PERF_X86_UNCORE_ONLINE,
|
CPUHP_AP_PERF_X86_UNCORE_ONLINE,
|
||||||
CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
|
CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
|
||||||
|
CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
|
||||||
CPUHP_AP_PERF_X86_RAPL_ONLINE,
|
CPUHP_AP_PERF_X86_RAPL_ONLINE,
|
||||||
CPUHP_AP_PERF_X86_CQM_ONLINE,
|
CPUHP_AP_PERF_X86_CQM_ONLINE,
|
||||||
CPUHP_AP_PERF_X86_CSTATE_ONLINE,
|
CPUHP_AP_PERF_X86_CSTATE_ONLINE,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче