Skip to content

Commit

Permalink
trace/hwlat: Support hotplug operations
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Daniel Bristot de Oliveira authored and rostedt committed Jun 25, 2021
1 parent 039a602 commit ba998f7
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions kernel/trace/trace_hwlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ static void stop_cpu_kthread(unsigned int cpu)
kthread = per_cpu(hwlat_per_cpu_data, cpu).kthread;
if (kthread)
kthread_stop(kthread);
per_cpu(hwlat_per_cpu_data, cpu).kthread = NULL;
}

/*
Expand Down Expand Up @@ -506,6 +507,68 @@ static int start_cpu_kthread(unsigned int cpu)
return 0;
}

#ifdef CONFIG_HOTPLUG_CPU
static void hwlat_hotplug_workfn(struct work_struct *dummy)
{
struct trace_array *tr = hwlat_trace;
unsigned int cpu = smp_processor_id();

mutex_lock(&trace_types_lock);
mutex_lock(&hwlat_data.lock);
get_online_cpus();

if (!hwlat_busy || hwlat_data.thread_mode != MODE_PER_CPU)
goto out_unlock;

if (!cpumask_test_cpu(cpu, tr->tracing_cpumask))
goto out_unlock;

start_cpu_kthread(cpu);

out_unlock:
put_online_cpus();
mutex_unlock(&hwlat_data.lock);
mutex_unlock(&trace_types_lock);
}

static DECLARE_WORK(hwlat_hotplug_work, hwlat_hotplug_workfn);

/*
* hwlat_cpu_init - CPU hotplug online callback function
*/
static int hwlat_cpu_init(unsigned int cpu)
{
schedule_work_on(cpu, &hwlat_hotplug_work);
return 0;
}

/*
* hwlat_cpu_die - CPU hotplug offline callback function
*/
static int hwlat_cpu_die(unsigned int cpu)
{
stop_cpu_kthread(cpu);
return 0;
}

static void hwlat_init_hotplug_support(void)
{
int ret;

ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "trace/hwlat:online",
hwlat_cpu_init, hwlat_cpu_die);
if (ret < 0)
pr_warn(BANNER "Error to init cpu hotplug support\n");

return;
}
#else /* CONFIG_HOTPLUG_CPU */
static void hwlat_init_hotplug_support(void)
{
return;
}
#endif /* CONFIG_HOTPLUG_CPU */

/*
* start_per_cpu_kthreads - Kick off the hardware latency sampling/detector kthreads
*
Expand Down Expand Up @@ -822,6 +885,8 @@ __init static int init_hwlat_tracer(void)
if (ret)
return ret;

hwlat_init_hotplug_support();

init_tracefs();

return 0;
Expand Down

0 comments on commit ba998f7

Please sign in to comment.