* [PATCHv2 0/2] trace/hwlat: Prevent startup of multiple per-cpu threads
@ 2023-03-10 10:04 Tero Kristo
2023-03-10 10:04 ` [PATCHv2 1/2] trace/hwlat: Do not wipe the contents of per-cpu thread data Tero Kristo
2023-03-10 10:04 ` [PATCHv2 2/2] trace/hwlat: Do not start per-cpu thread if it is already running Tero Kristo
0 siblings, 2 replies; 5+ messages in thread
From: Tero Kristo @ 2023-03-10 10:04 UTC (permalink / raw)
To: rostedt, bristot, mhiramat; +Cc: linux-kernel, linux-trace-kernel
Hi,
v2 of this series just splits the patch into two, and adds the
reproducer script into the commit of patch #2. Separately, neither of
the patches fix the issue completely, both are needed.
-Tero
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCHv2 1/2] trace/hwlat: Do not wipe the contents of per-cpu thread data
2023-03-10 10:04 [PATCHv2 0/2] trace/hwlat: Prevent startup of multiple per-cpu threads Tero Kristo
@ 2023-03-10 10:04 ` Tero Kristo
2023-03-10 13:52 ` Daniel Bristot de Oliveira
2023-03-10 10:04 ` [PATCHv2 2/2] trace/hwlat: Do not start per-cpu thread if it is already running Tero Kristo
1 sibling, 1 reply; 5+ messages in thread
From: Tero Kristo @ 2023-03-10 10:04 UTC (permalink / raw)
To: rostedt, bristot, mhiramat; +Cc: linux-kernel, linux-trace-kernel
Do not wipe the contents of the per-cpu kthread data when starting the
tracer, as this will completely forget about already running instances
and can later start new additional per-cpu threads.
Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com>
---
v2:
* split into separate patch
kernel/trace/trace_hwlat.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index d440ddd5fd8b..edc26dc22c3f 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -584,9 +584,6 @@ static int start_per_cpu_kthreads(struct trace_array *tr)
*/
cpumask_and(current_mask, cpu_online_mask, tr->tracing_cpumask);
- for_each_online_cpu(cpu)
- per_cpu(hwlat_per_cpu_data, cpu).kthread = NULL;
-
for_each_cpu(cpu, current_mask) {
retval = start_cpu_kthread(cpu);
if (retval)
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCHv2 2/2] trace/hwlat: Do not start per-cpu thread if it is already running
2023-03-10 10:04 [PATCHv2 0/2] trace/hwlat: Prevent startup of multiple per-cpu threads Tero Kristo
2023-03-10 10:04 ` [PATCHv2 1/2] trace/hwlat: Do not wipe the contents of per-cpu thread data Tero Kristo
@ 2023-03-10 10:04 ` Tero Kristo
2023-03-10 13:52 ` Daniel Bristot de Oliveira
1 sibling, 1 reply; 5+ messages in thread
From: Tero Kristo @ 2023-03-10 10:04 UTC (permalink / raw)
To: rostedt, bristot, mhiramat; +Cc: linux-kernel, linux-trace-kernel
The hwlatd tracer will end up starting multiple per-cpu threads with
the following script:
#!/bin/sh
cd /sys/kernel/debug/tracing
echo 0 > tracing_on
echo hwlat > current_tracer
echo per-cpu > hwlat_detector/mode
echo 100000 > hwlat_detector/width
echo 200000 > hwlat_detector/window
echo 1 > tracing_on
To fix the issue, check if the hwlatd thread for the cpu is already
running, before starting a new one. Along with the previous patch, this
avoids running multiple instances of the same CPU thread on the system.
Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com>
---
v2:
* split into separate patch
* added reproducer script into commit log
kernel/trace/trace_hwlat.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index edc26dc22c3f..c4945f8adc11 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -492,6 +492,10 @@ static int start_cpu_kthread(unsigned int cpu)
{
struct task_struct *kthread;
+ /* Do not start a new hwlatd thread if it is already running */
+ if (per_cpu(hwlat_per_cpu_data, cpu).kthread)
+ return 0;
+
kthread = kthread_run_on_cpu(kthread_fn, NULL, cpu, "hwlatd/%u");
if (IS_ERR(kthread)) {
pr_err(BANNER "could not start sampling thread\n");
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCHv2 1/2] trace/hwlat: Do not wipe the contents of per-cpu thread data
2023-03-10 10:04 ` [PATCHv2 1/2] trace/hwlat: Do not wipe the contents of per-cpu thread data Tero Kristo
@ 2023-03-10 13:52 ` Daniel Bristot de Oliveira
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Bristot de Oliveira @ 2023-03-10 13:52 UTC (permalink / raw)
To: Tero Kristo, rostedt, mhiramat; +Cc: linux-kernel, linux-trace-kernel
On 3/10/23 11:04, Tero Kristo wrote:
> Do not wipe the contents of the per-cpu kthread data when starting the
> tracer, as this will completely forget about already running instances
> and can later start new additional per-cpu threads.
>
> Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com>
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
-- Daniel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv2 2/2] trace/hwlat: Do not start per-cpu thread if it is already running
2023-03-10 10:04 ` [PATCHv2 2/2] trace/hwlat: Do not start per-cpu thread if it is already running Tero Kristo
@ 2023-03-10 13:52 ` Daniel Bristot de Oliveira
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Bristot de Oliveira @ 2023-03-10 13:52 UTC (permalink / raw)
To: Tero Kristo, rostedt, mhiramat; +Cc: linux-kernel, linux-trace-kernel
On 3/10/23 11:04, Tero Kristo wrote:
> The hwlatd tracer will end up starting multiple per-cpu threads with
> the following script:
>
> #!/bin/sh
> cd /sys/kernel/debug/tracing
> echo 0 > tracing_on
> echo hwlat > current_tracer
> echo per-cpu > hwlat_detector/mode
> echo 100000 > hwlat_detector/width
> echo 200000 > hwlat_detector/window
> echo 1 > tracing_on
>
> To fix the issue, check if the hwlatd thread for the cpu is already
> running, before starting a new one. Along with the previous patch, this
> avoids running multiple instances of the same CPU thread on the system.
>
> Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com>
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
-- Daniel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-10 13:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-10 10:04 [PATCHv2 0/2] trace/hwlat: Prevent startup of multiple per-cpu threads Tero Kristo
2023-03-10 10:04 ` [PATCHv2 1/2] trace/hwlat: Do not wipe the contents of per-cpu thread data Tero Kristo
2023-03-10 13:52 ` Daniel Bristot de Oliveira
2023-03-10 10:04 ` [PATCHv2 2/2] trace/hwlat: Do not start per-cpu thread if it is already running Tero Kristo
2023-03-10 13:52 ` Daniel Bristot de Oliveira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).