Skip to content

Commit c6a84da

Browse files
anna-marialxIngo Molnar
authored andcommitted
perf/x86/amd/power: Convert the hotplug notifier to state machine
Install the callbacks via the state machine. Signed-off-by: Anna-Maria Gleixner <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Huang Rui <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 89ab9cb commit c6a84da

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

arch/x86/events/amd/power.c

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ static struct pmu pmu_class = {
228228
.read = pmu_event_read,
229229
};
230230

231-
static void power_cpu_exit(int cpu)
231+
static int power_cpu_exit(unsigned int cpu)
232232
{
233233
int target;
234234

235235
if (!cpumask_test_and_clear_cpu(cpu, &cpu_mask))
236-
return;
236+
return 0;
237237

238238
/*
239239
* 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)
245245
cpumask_set_cpu(target, &cpu_mask);
246246
perf_pmu_migrate_context(&pmu_class, cpu, target);
247247
}
248+
return 0;
248249
}
249250

250-
static void power_cpu_init(int cpu)
251+
static int power_cpu_init(unsigned int cpu)
251252
{
252253
int target;
253254

@@ -263,41 +264,17 @@ static void power_cpu_init(int cpu)
263264
target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
264265
if (target >= nr_cpumask_bits)
265266
cpumask_set_cpu(cpu, &cpu_mask);
267+
return 0;
266268
}
267269

268-
static int
269-
power_cpu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
270-
{
271-
unsigned int cpu = (long)hcpu;
272-
273-
switch (action & ~CPU_TASKS_FROZEN) {
274-
case CPU_DOWN_FAILED:
275-
case CPU_ONLINE:
276-
power_cpu_init(cpu);
277-
break;
278-
case CPU_DOWN_PREPARE:
279-
power_cpu_exit(cpu);
280-
break;
281-
default:
282-
break;
283-
}
284-
285-
return NOTIFY_OK;
286-
}
287-
288-
static struct notifier_block power_cpu_notifier_nb = {
289-
.notifier_call = power_cpu_notifier,
290-
.priority = CPU_PRI_PERF,
291-
};
292-
293270
static const struct x86_cpu_id cpu_match[] = {
294271
{ .vendor = X86_VENDOR_AMD, .family = 0x15 },
295272
{},
296273
};
297274

298275
static int __init amd_power_pmu_init(void)
299276
{
300-
int cpu, target, ret;
277+
int ret;
301278

302279
if (!x86_match_cpu(cpu_match))
303280
return 0;
@@ -312,38 +289,25 @@ static int __init amd_power_pmu_init(void)
312289
return -ENODEV;
313290
}
314291

315-
cpu_notifier_register_begin();
316292

317-
/* Choose one online core of each compute unit. */
318-
for_each_online_cpu(cpu) {
319-
target = cpumask_first(topology_sibling_cpumask(cpu));
320-
if (!cpumask_test_cpu(target, &cpu_mask))
321-
cpumask_set_cpu(target, &cpu_mask);
322-
}
293+
cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
294+
"AP_PERF_X86_AMD_POWER_ONLINE",
295+
power_cpu_init, power_cpu_exit);
323296

324297
ret = perf_pmu_register(&pmu_class, "power", -1);
325298
if (WARN_ON(ret)) {
326299
pr_warn("AMD Power PMU registration failed\n");
327-
goto out;
300+
return ret;
328301
}
329302

330-
__register_cpu_notifier(&power_cpu_notifier_nb);
331-
332303
pr_info("AMD Power PMU detected\n");
333-
334-
out:
335-
cpu_notifier_register_done();
336-
337304
return ret;
338305
}
339306
module_init(amd_power_pmu_init);
340307

341308
static void __exit amd_power_pmu_exit(void)
342309
{
343-
cpu_notifier_register_begin();
344-
__unregister_cpu_notifier(&power_cpu_notifier_nb);
345-
cpu_notifier_register_done();
346-
310+
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE);
347311
perf_pmu_unregister(&pmu_class);
348312
}
349313
module_exit(amd_power_pmu_exit);

include/linux/cpuhotplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum cpuhp_state {
4141
CPUHP_AP_PERF_X86_ONLINE,
4242
CPUHP_AP_PERF_X86_UNCORE_ONLINE,
4343
CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
44+
CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
4445
CPUHP_AP_PERF_X86_RAPL_ONLINE,
4546
CPUHP_AP_PERF_X86_CQM_ONLINE,
4647
CPUHP_AP_PERF_X86_CSTATE_ONLINE,

0 commit comments

Comments
 (0)