All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Arjan van de Ven <arjan@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 task struct trace flag to filter on pid
Date: Wed, 03 Dec 2008 14:34:27 -0800	[thread overview]
Message-ID: <m18wqw3n2k.fsf@frodo.ebiederm.org> (raw)
In-Reply-To: <20081203203829.158592001@goodmis.org> (Steven Rostedt's message of "Wed, 03 Dec 2008 15:36:58 -0500")

Steven Rostedt <rostedt@goodmis.org> writes:

> From: Steven Rostedt <srostedt@redhat.com>
>
> Impact: clean up
>
> Use the new task struct trace flags to determine if a process should be
> traced or not.

Looks reasonable.

> Note: this moves the searching of the pid to the slow path of setting
> the pid field. This needs to be converted to the pid name space.
>
> Signed-off-by: Steven Rostedt <srostedt@redhat.com>
> ---
>  kernel/trace/ftrace.c |   28 +++++++++++++++++++++++++---
>  1 files changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index b17a303..c5049f5 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -47,7 +47,7 @@
>  int ftrace_enabled __read_mostly;
>  static int last_ftrace_enabled;
>  
> -/* ftrace_pid_trace >= 0 will only trace threads with this pid */
> +/* set when tracing only a pid */
>  static int ftrace_pid_trace = -1;
>  
>  /* Quick disabling of function tracer. */
> @@ -90,7 +90,7 @@ static void ftrace_list_func(unsigned long ip, unsigned long
> parent_ip)
>  
>  static void ftrace_pid_func(unsigned long ip, unsigned long parent_ip)
>  {
> -	if (current->pid != ftrace_pid_trace)
> +	if (!test_tsk_trace_trace(current))
>  		return;
>  
>  	ftrace_pid_function(ip, parent_ip);
> @@ -1714,11 +1714,33 @@ ftrace_pid_write(struct file *filp, const char __user
> *ubuf,
>  		ftrace_pid_trace = -1;
>  
>  	} else {
> +		struct task_struct *p;
> +		int found = 0;
>  
>  		if (ftrace_pid_trace == val)
>  			goto out;
>  
> -		ftrace_pid_trace = val;
> +		/*
> +		 * 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();

Yes.  This function you have just implemented inline is called find_pid.
It uses a hash lookup instead of an expensive walk trough all of the processes
in the system.  So the code becomes something like:


                do_each_pid_task(ftrace_pid_trace, PIDTYPE_PID, task) {
			clear_tsk_trace_tace(p);
                } while_each_pid_task(pid, PIDTYPE_PID, task);
                put_pid(ftrace_pid_trace);

                ftrace_pid_trace = find_get_vpid(val);
                do_each_pid_task(ftrace_pid_trace, PIDTYPE_PID, task) {
                	set_tsk_trace_tace(p);
                } while_each_pid_task(ftrace_pid_trace, PIDTYPE_PID, task);

                if (!ftrace_pid_trace)
                	goto out;

The loops encompass both the test for validity, and handle the weird exec
case where the pid moves from one task to another.

Eric

  reply	other threads:[~2008-12-03 22:34 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-03 20:36 [PATCH 0/3] ftrace: updates for tip Steven Rostedt
2008-12-03 20:36 ` [PATCH 1/3] ftrace: graph of a single function Steven Rostedt
2008-12-03 20:36   ` Steven Rostedt
     [not found]   ` <20081203203828.920111079-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>
2008-12-03 21:07     ` Andrew Morton
2008-12-03 21:07       ` Andrew Morton
2008-12-03 21:10       ` Steven Rostedt
2008-12-03 21:32         ` Andrew Morton
2008-12-03 21:36           ` Steven Rostedt
2008-12-04  8:39             ` Ingo Molnar
2008-12-03 21:08     ` Andrew Morton
2008-12-03 21:08       ` Andrew Morton
2008-12-03 21:11       ` Steven Rostedt
2008-12-04  8:41         ` Ingo Molnar
2008-12-04  8:43           ` Peter Zijlstra
2008-12-15  9:21           ` Andy Whitcroft
2008-12-04  6:24   ` [PATCH 1/1] ftrace: avoid duplicated function when writing set_graph_function Liming Wang
2008-12-04  8:42     ` Ingo Molnar
2008-12-03 20:36 ` [PATCH 2/3] ftrace: use task struct trace flag to filter on pid Steven Rostedt
2008-12-03 22:34   ` Eric W. Biederman [this message]
2008-12-03 20:36 ` [PATCH 3/3] ftrace: trace single pid for function graph tracer Steven Rostedt
2008-12-03 20:49   ` Andrew Morton
2008-12-03 20:52     ` Steven Rostedt
2008-12-03 23:36       ` Eric W. Biederman
2008-12-04  2:29         ` Steven Rostedt
2008-12-04  4:22           ` Eric W. Biederman
2008-12-04  4:32             ` Steven Rostedt
2008-12-04  8:19 ` [PATCH 0/3] ftrace: updates for tip Ingo Molnar
2008-12-04  8:35 ` Ingo Molnar
2008-12-04 13:30   ` Steven Rostedt

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=m18wqw3n2k.fsf@frodo.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.