Skip to content

Commit ba998f7

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
trace/hwlat: Support hotplug operations
Enable and disable hwlat thread during cpu hotplug online and offline operations, respectivelly. Link: https://lore.kernel.org/linux-doc/[email protected]/ Link: https://lkml.kernel.org/r/52012d25ea35491a0f8088b947864d8df8e25157.1624372313.git.bristot@redhat.com Cc: Phil Auld <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Kate Carcia <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Alexandre Chartre <[email protected]> Cc: Clark Willaims <[email protected]> Cc: John Kacur <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Suggested-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 039a602 commit ba998f7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

kernel/trace/trace_hwlat.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ static void stop_cpu_kthread(unsigned int cpu)
466466
kthread = per_cpu(hwlat_per_cpu_data, cpu).kthread;
467467
if (kthread)
468468
kthread_stop(kthread);
469+
per_cpu(hwlat_per_cpu_data, cpu).kthread = NULL;
469470
}
470471

471472
/*
@@ -506,6 +507,68 @@ static int start_cpu_kthread(unsigned int cpu)
506507
return 0;
507508
}
508509

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+
509572
/*
510573
* start_per_cpu_kthreads - Kick off the hardware latency sampling/detector kthreads
511574
*
@@ -822,6 +885,8 @@ __init static int init_hwlat_tracer(void)
822885
if (ret)
823886
return ret;
824887

888+
hwlat_init_hotplug_support();
889+
825890
init_tracefs();
826891

827892
return 0;

0 commit comments

Comments
 (0)