@@ -466,6 +466,7 @@ static void stop_cpu_kthread(unsigned int cpu)
466
466
kthread = per_cpu (hwlat_per_cpu_data , cpu ).kthread ;
467
467
if (kthread )
468
468
kthread_stop (kthread );
469
+ per_cpu (hwlat_per_cpu_data , cpu ).kthread = NULL ;
469
470
}
470
471
471
472
/*
@@ -506,6 +507,68 @@ static int start_cpu_kthread(unsigned int cpu)
506
507
return 0 ;
507
508
}
508
509
510
+ #ifdef CONFIG_HOTPLUG_CPU
511
+ static void hwlat_hotplug_workfn (struct work_struct * dummy )
512
+ {
513
+ struct trace_array * tr = hwlat_trace ;
514
+ unsigned int cpu = smp_processor_id ();
515
+
516
+ mutex_lock (& trace_types_lock );
517
+ mutex_lock (& hwlat_data .lock );
518
+ get_online_cpus ();
519
+
520
+ if (!hwlat_busy || hwlat_data .thread_mode != MODE_PER_CPU )
521
+ goto out_unlock ;
522
+
523
+ if (!cpumask_test_cpu (cpu , tr -> tracing_cpumask ))
524
+ goto out_unlock ;
525
+
526
+ start_cpu_kthread (cpu );
527
+
528
+ out_unlock :
529
+ put_online_cpus ();
530
+ mutex_unlock (& hwlat_data .lock );
531
+ mutex_unlock (& trace_types_lock );
532
+ }
533
+
534
+ static DECLARE_WORK (hwlat_hotplug_work , hwlat_hotplug_workfn ) ;
535
+
536
+ /*
537
+ * hwlat_cpu_init - CPU hotplug online callback function
538
+ */
539
+ static int hwlat_cpu_init (unsigned int cpu )
540
+ {
541
+ schedule_work_on (cpu , & hwlat_hotplug_work );
542
+ return 0 ;
543
+ }
544
+
545
+ /*
546
+ * hwlat_cpu_die - CPU hotplug offline callback function
547
+ */
548
+ static int hwlat_cpu_die (unsigned int cpu )
549
+ {
550
+ stop_cpu_kthread (cpu );
551
+ return 0 ;
552
+ }
553
+
554
+ static void hwlat_init_hotplug_support (void )
555
+ {
556
+ int ret ;
557
+
558
+ ret = cpuhp_setup_state (CPUHP_AP_ONLINE_DYN , "trace/hwlat:online" ,
559
+ hwlat_cpu_init , hwlat_cpu_die );
560
+ if (ret < 0 )
561
+ pr_warn (BANNER "Error to init cpu hotplug support\n" );
562
+
563
+ return ;
564
+ }
565
+ #else /* CONFIG_HOTPLUG_CPU */
566
+ static void hwlat_init_hotplug_support (void )
567
+ {
568
+ return ;
569
+ }
570
+ #endif /* CONFIG_HOTPLUG_CPU */
571
+
509
572
/*
510
573
* start_per_cpu_kthreads - Kick off the hardware latency sampling/detector kthreads
511
574
*
@@ -822,6 +885,8 @@ __init static int init_hwlat_tracer(void)
822
885
if (ret )
823
886
return ret ;
824
887
888
+ hwlat_init_hotplug_support ();
889
+
825
890
init_tracefs ();
826
891
827
892
return 0 ;
0 commit comments