@@ -228,12 +228,12 @@ static struct pmu pmu_class = {
228
228
.read = pmu_event_read ,
229
229
};
230
230
231
- static void power_cpu_exit (int cpu )
231
+ static int power_cpu_exit (unsigned int cpu )
232
232
{
233
233
int target ;
234
234
235
235
if (!cpumask_test_and_clear_cpu (cpu , & cpu_mask ))
236
- return ;
236
+ return 0 ;
237
237
238
238
/*
239
239
* 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)
245
245
cpumask_set_cpu (target , & cpu_mask );
246
246
perf_pmu_migrate_context (& pmu_class , cpu , target );
247
247
}
248
+ return 0 ;
248
249
}
249
250
250
- static void power_cpu_init (int cpu )
251
+ static int power_cpu_init (unsigned int cpu )
251
252
{
252
253
int target ;
253
254
@@ -263,41 +264,17 @@ static void power_cpu_init(int cpu)
263
264
target = cpumask_any_but (topology_sibling_cpumask (cpu ), cpu );
264
265
if (target >= nr_cpumask_bits )
265
266
cpumask_set_cpu (cpu , & cpu_mask );
267
+ return 0 ;
266
268
}
267
269
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
-
293
270
static const struct x86_cpu_id cpu_match [] = {
294
271
{ .vendor = X86_VENDOR_AMD , .family = 0x15 },
295
272
{},
296
273
};
297
274
298
275
static int __init amd_power_pmu_init (void )
299
276
{
300
- int cpu , target , ret ;
277
+ int ret ;
301
278
302
279
if (!x86_match_cpu (cpu_match ))
303
280
return 0 ;
@@ -312,38 +289,25 @@ static int __init amd_power_pmu_init(void)
312
289
return - ENODEV ;
313
290
}
314
291
315
- cpu_notifier_register_begin ();
316
292
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 );
323
296
324
297
ret = perf_pmu_register (& pmu_class , "power" , -1 );
325
298
if (WARN_ON (ret )) {
326
299
pr_warn ("AMD Power PMU registration failed\n" );
327
- goto out ;
300
+ return ret ;
328
301
}
329
302
330
- __register_cpu_notifier (& power_cpu_notifier_nb );
331
-
332
303
pr_info ("AMD Power PMU detected\n" );
333
-
334
- out :
335
- cpu_notifier_register_done ();
336
-
337
304
return ret ;
338
305
}
339
306
module_init (amd_power_pmu_init );
340
307
341
308
static void __exit amd_power_pmu_exit (void )
342
309
{
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 );
347
311
perf_pmu_unregister (& pmu_class );
348
312
}
349
313
module_exit (amd_power_pmu_exit );
0 commit comments