From: ebiederm@xmission.com (Eric W. Biederman)
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Dave Hansen <dave@linux.vnet.ibm.com>,
containers@lists.osdl.org,
Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>,
"Serge E. Hallyn" <serue@us.ibm.com>,
Steven Rostedt <srostedt@redhat.com>
Subject: Re: [PATCH 2/3] ftrace: use struct pid
Date: Thu, 04 Dec 2008 04:42:20 -0800 [thread overview]
Message-ID: <m1d4g8un6b.fsf@frodo.ebiederm.org> (raw)
In-Reply-To: <20081204052735.175697908@goodmis.org> (Steven Rostedt's message of "Thu, 04 Dec 2008 00:26:40 -0500")
Steven Rostedt <rostedt@goodmis.org> writes:
> From: Steven Rostedt <srostedt@redhat.com>
>
> Impact: clean up
>
> Eric Biederman suggested using the struct pid for filtering on
> pids in the kernel. This patch is based off of a demonstration
> of an implementation that Eric sent me in an email.
A little nit. I forgot to mention rcu_read_lock() is still needed in that
email.
> Signed-off-by: Steven Rostedt <srostedt@redhat.com>
> ---
> kernel/trace/ftrace.c | 76 ++++++++++++++++++++++++++++--------------------
> kernel/trace/trace.h | 4 +-
> 2 files changed, 46 insertions(+), 34 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 57592a9..10b1d7c 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -48,7 +48,7 @@ int ftrace_enabled __read_mostly;
> static int last_ftrace_enabled;
>
> /* set when tracing only a pid */
> -int ftrace_pid_trace = -1;
> +struct pid *ftrace_pid_trace;
>
> /* Quick disabling of function tracer. */
> int function_trace_stop;
> @@ -153,7 +153,7 @@ static int __register_ftrace_function(struct ftrace_ops
> *ops)
> else
> func = ftrace_list_func;
>
> - if (ftrace_pid_trace >= 0) {
> + if (ftrace_pid_trace) {
> set_ftrace_pid_function(func);
> func = ftrace_pid_func;
> }
> @@ -209,7 +209,7 @@ static int __unregister_ftrace_function(struct ftrace_ops
> *ops)
> if (ftrace_list->next == &ftrace_list_end) {
> ftrace_func_t func = ftrace_list->func;
>
> - if (ftrace_pid_trace >= 0) {
> + if (ftrace_pid_trace) {
> set_ftrace_pid_function(func);
> func = ftrace_pid_func;
> }
> @@ -239,7 +239,7 @@ static void ftrace_update_pid_func(void)
>
> func = ftrace_trace_function;
>
> - if (ftrace_pid_trace >= 0) {
> + if (ftrace_pid_trace) {
> set_ftrace_pid_function(func);
> func = ftrace_pid_func;
> } else {
> @@ -1678,18 +1678,40 @@ ftrace_pid_read(struct file *file, char __user *ubuf,
> char buf[64];
> int r;
>
> - if (ftrace_pid_trace >= 0)
> - r = sprintf(buf, "%u\n", ftrace_pid_trace);
> + if (ftrace_pid_trace)
> + r = sprintf(buf, "%u\n", pid_nr(ftrace_pid_trace));
> else
> r = sprintf(buf, "no pid\n");
>
> return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
> }
>
> +static void clear_ftrace_pid_task(struct pid **pid)
> +{
> + struct task_struct *p;
> +
rcu_read_lock();
> + do_each_pid_task(*pid, PIDTYPE_PID, p) {
> + clear_tsk_trace_trace(p);
> + } while_each_pid_task(*pid, PIDTYPE_PID, p);
rcu_read_unlock()
> + put_pid(*pid);
> +
> + *pid = NULL;
> +}
> +
> +static void set_ftrace_pid_task(struct pid *pid)
> +{
> + struct task_struct *p;
> +
rcu_read_lock();
> + do_each_pid_task(pid, PIDTYPE_PID, p) {
> + set_tsk_trace_trace(p);
> + } while_each_pid_task(pid, PIDTYPE_PID, p);
rcu_read_unlock();
> +}
> +
> static ssize_t
> ftrace_pid_write(struct file *filp, const char __user *ubuf,
> size_t cnt, loff_t *ppos)
> {
> + struct pid *pid;
> char buf[64];
> long val;
> int ret;
> @@ -1707,40 +1729,30 @@ ftrace_pid_write(struct file *filp, const char __user
> *ubuf,
> return ret;
>
> mutex_lock(&ftrace_start_lock);
> - if (ret < 0) {
> + if (val < 0) {
> /* disable pid tracing */
> - if (ftrace_pid_trace < 0)
> + if (!ftrace_pid_trace)
> goto out;
> - ftrace_pid_trace = -1;
> +
> + clear_ftrace_pid_task(&ftrace_pid_trace);
>
> } else {
> - struct task_struct *p;
> - int found = 0;
> + pid = find_get_pid(val);
>
> - if (ftrace_pid_trace == val)
> + if (pid == ftrace_pid_trace) {
> + put_pid(pid);
> goto out;
> -
> - /*
> - * Find the task that matches this pid.
> - * TODO: use pid namespaces instead.
> - */
> - rcu_read_lock();
> - for_each_process(p) {
> - if (p->pid == val) {
> - found = 1;
> - set_tsk_trace_trace(p);
> - } else if (test_tsk_trace_trace(p))
> - clear_tsk_trace_trace(p);
> }
> - rcu_read_unlock();
>
> - if (found)
> - ftrace_pid_trace = val;
> - else {
> - if (ftrace_pid_trace < 0)
> - goto out;
> - ftrace_pid_trace = -1;
> - }
> + if (ftrace_pid_trace)
> + clear_ftrace_pid_task(&ftrace_pid_trace);
> +
> + if (!pid)
> + goto out;
> +
> + ftrace_pid_trace = pid;
> +
> + set_ftrace_pid_task(ftrace_pid_trace);
> }
>
> /* update the function call */
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index 95fff37..8b81b4d 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -541,11 +541,11 @@ print_graph_function(struct trace_iterator *iter)
> }
> #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
>
> -extern int ftrace_pid_trace;
> +extern struct pid *ftrace_pid_trace;
>
> static inline int ftrace_trace_task(struct task_struct *task)
> {
> - if (ftrace_pid_trace < 0)
> + if (ftrace_pid_trace)
> return 1;
>
> return test_tsk_trace_trace(task);
> --
> 1.5.6.5
>
> --
next prev parent reply other threads:[~2008-12-04 12:46 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-04 5:26 [PATCH 0/3] ftrace: clean ups for tip Steven Rostedt
2008-12-04 5:26 ` [PATCH 1/3] fix the do_each_pid_task macro Steven Rostedt
2008-12-04 5:26 ` [PATCH 2/3] ftrace: use struct pid Steven Rostedt
2008-12-04 12:42 ` Eric W. Biederman [this message]
2008-12-04 12:56 ` Dave Hansen
2008-12-04 13:07 ` Dave Hansen
2008-12-04 13:40 ` Eric W. Biederman
2008-12-04 15:12 ` Dave Hansen
2008-12-04 15:35 ` Steven Rostedt
2008-12-04 15:41 ` Dave Hansen
2008-12-04 15:44 ` Steven Rostedt
2008-12-04 14:29 ` Steven Rostedt
2008-12-05 3:17 ` Dipankar Sarma
2008-12-04 12:55 ` Eric W. Biederman
2008-12-04 14:23 ` Steven Rostedt
2008-12-04 14:32 ` Eric W. Biederman
2008-12-04 16:22 ` Sukadev Bhattiprolu
2008-12-04 5:26 ` [PATCH 3/3] ftrace: add ability to only trace swapper tasks Steven Rostedt
2008-12-04 5:34 ` Wang Liming
2008-12-04 5:50 ` Wang Liming
2008-12-04 8:06 ` Ingo Molnar
2008-12-04 8:18 ` Andrew Morton
2008-12-04 9:10 ` Ingo Molnar
2008-12-04 12:59 ` Eric W. Biederman
2008-12-04 14:46 ` Steven Rostedt
2008-12-04 20:41 ` Eric W. Biederman
2008-12-04 20:57 ` Steven Rostedt
2008-12-04 21:43 ` Eric W. Biederman
2008-12-04 21:56 ` Steven Rostedt
2008-12-05 7:43 ` Eric W. Biederman
2008-12-05 12:23 ` Steven Rostedt
2008-12-05 16:35 ` Eric W. Biederman
2008-12-05 4:30 ` [PATCH] ftrace: use init_struct_pid as swapper pid Steven Rostedt
2008-12-05 13:51 ` Ingo Molnar
2008-12-04 15:36 ` [PATCH 3/3] ftrace: add ability to only trace swapper tasks Ingo Molnar
2008-12-04 15:47 ` Steven Rostedt
2008-12-04 13:12 ` Steven Rostedt
2008-12-04 13:52 ` Eric W. Biederman
2008-12-04 12:54 ` Eric W. Biederman
2008-12-04 14:57 ` Steven Rostedt
2008-12-04 8:10 ` [PATCH 0/3] ftrace: clean ups for tip Ingo Molnar
2008-12-04 8:30 ` [PATCH] tracing: fix typo Ingo Molnar
2008-12-04 8:34 ` [PATCH] tracing: fix typo and missing inline function Ingo Molnar
2008-12-04 13:16 ` Steven Rostedt
2008-12-04 15:35 ` Ingo Molnar
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=m1d4g8un6b.fsf@frodo.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.osdl.org \
--cc=dave@linux.vnet.ibm.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=serue@us.ibm.com \
--cc=srostedt@redhat.com \
--cc=sukadev@linux.vnet.ibm.com \
/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