linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erica Bugden <erica.bugden@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: rostedt@goodmis.org, peterz@infradead.org, tglx@linutronix.de,
	anna-maria@linutronix.de, bigeasy@linutronix.de,
	Erica Bugden <erica.bugden@linutronix.de>
Subject: [PATCH] ftrace: Add missing check for existing hwlat thread
Date: Wed,  1 Aug 2018 12:45:54 +0200	[thread overview]
Message-ID: <1533120354-22923-1-git-send-email-erica.bugden@linutronix.de> (raw)

The hwlat tracer uses a kernel thread to measure latencies. The function
that creates this kernel thread, start_kthread(), can be called when the
tracer is initialized and when the tracer is explicitly enabled.
start_kthread() does not check if there is an existing hwlat kernel
thread and will create a new one each time it is called.

This causes the reference to the previous thread to be lost. Without the
thread reference, the old kernel thread becomes unstoppable and
continues to use CPU time even after the hwlat tracer has been disabled.
This problem can be observed when a system is booted with tracing
enabled and the hwlat tracer is configured like this:

	echo hwlat > current_tracer; echo 1 > tracing_on

Add the missing check for an existing kernel thread in start_kthread()
to prevent this problem. This function and the rest of the hwlat kernel
thread setup and teardown are already serialized because they are called
through the tracer core code with trace_type_lock held.

Signed-off-by: Erica Bugden <erica.bugden@linutronix.de>
---
 kernel/trace/trace_hwlat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index d7c8e4e..2d9d36d 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -354,6 +354,9 @@ static int start_kthread(struct trace_array *tr)
 	struct task_struct *kthread;
 	int next_cpu;
 
+	if (hwlat_kthread)
+		return 0;
+
 	/* Just pick the first CPU on first iteration */
 	current_mask = &save_cpumask;
 	get_online_cpus();
-- 
2.1.4


             reply	other threads:[~2018-08-01 10:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01 10:45 Erica Bugden [this message]
2018-08-01 19:40 ` [PATCH] ftrace: Add missing check for existing hwlat thread Steven Rostedt
2018-08-01 19:59   ` Thomas Gleixner
2018-08-01 20:03     ` Steven Rostedt
2018-08-01 20:07       ` Thomas Gleixner
2018-08-03  8:46   ` Erica Bugden
2018-08-03 13:37     ` Steven Rostedt
2018-08-03 14:57       ` Erica Bugden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1533120354-22923-1-git-send-email-erica.bugden@linutronix.de \
    --to=erica.bugden@linutronix.de \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).