public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jiri Olsa <jolsa@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-trace-users@vger.kernel.org
Subject: Re: [RFC][PATCH 3/4] tracing: Add infrastructure to allow set_event_pid to follow children
Date: Tue, 19 Apr 2016 16:55:11 +0000 (UTC)	[thread overview]
Message-ID: <1887707510.62932.1461084911586.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20160419143725.473997738@goodmis.org>


----- On Apr 19, 2016, at 10:34 AM, rostedt rostedt@goodmis.org wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> Add the infrastructure needed to have the PIDs in set_event_pid to
> automatically add PIDs of the children of the tasks that have their PIDs in
> set_event_pid. This will also remove PIDs from set_event_pid when a task
> exits
> 
> This is implemented by adding hooks into the fork and exit tracepoints. On
> fork, the PIDs are added to the list, and on exit, they are removed.
> 
> Add a new option called event_fork that when set, PIDs in set_event_pid will
> automatically get their children PIDs added when they fork, as well as any
> task that exits will have its PID removed from set_event_pid.

Just out of curiosity: how does it deal with multi-process and multi-thread ?
What events are expected in each case ?

Thanks,

Mathieu

> 
> This works for instances as well.
> 
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
> kernel/trace/trace.c        |  3 ++
> kernel/trace/trace.h        |  2 ++
> kernel/trace/trace_events.c | 84 +++++++++++++++++++++++++++++++++++++++------
> 3 files changed, 79 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index a2f0b9f33e9b..0d12dbde8399 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3571,6 +3571,9 @@ int set_tracer_flag(struct trace_array *tr, unsigned int
> mask, int enabled)
> 	if (mask == TRACE_ITER_RECORD_CMD)
> 		trace_event_enable_cmd_record(enabled);
> 
> +	if (mask == TRACE_ITER_EVENT_FORK)
> +		trace_event_follow_fork(tr, enabled);
> +
> 	if (mask == TRACE_ITER_OVERWRITE) {
> 		ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled);
> #ifdef CONFIG_TRACER_MAX_TRACE
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index 68cbb8e10aea..2525042760e6 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -655,6 +655,7 @@ static inline void __trace_stack(struct trace_array *tr,
> unsigned long flags,
> extern cycle_t ftrace_now(int cpu);
> 
> extern void trace_find_cmdline(int pid, char comm[]);
> +extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
> 
> #ifdef CONFIG_DYNAMIC_FTRACE
> extern unsigned long ftrace_update_tot_cnt;
> @@ -966,6 +967,7 @@ extern int trace_get_user(struct trace_parser *parser, const
> char __user *ubuf,
> 		C(STOP_ON_FREE,		"disable_on_free"),	\
> 		C(IRQ_INFO,		"irq-info"),		\
> 		C(MARKERS,		"markers"),		\
> +		C(EVENT_FORK,		"event-fork"),		\
> 		FUNCTION_FLAGS					\
> 		FGRAPH_FLAGS					\
> 		STACK_FLAGS					\
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 45f7cc72bf25..add81dff7520 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -474,11 +474,23 @@ static void ftrace_clear_events(struct trace_array *tr)
> /* Shouldn't this be in a header? */
> extern int pid_max;
> 
> +/* Returns true if found in filter */
> static bool
> -ignore_this_task(struct trace_pid_list *filtered_pids, struct task_struct
> *task)
> +find_filtered_pid(struct trace_pid_list *filtered_pids, pid_t search_pid)
> {
> -	pid_t pid;
> +	/*
> +	 * If pid_max changed after filtered_pids was created, we
> +	 * by default ignore all pids greater than the previous pid_max.
> +	 */
> +	if (search_pid >= filtered_pids->pid_max)
> +		return false;
> +
> +	return test_bit(search_pid, filtered_pids->pids);
> +}
> 
> +static bool
> +ignore_this_task(struct trace_pid_list *filtered_pids, struct task_struct
> *task)
> +{
> 	/*
> 	 * Return false, because if filtered_pids does not exist,
> 	 * all pids are good to trace.
> @@ -486,16 +498,68 @@ ignore_this_task(struct trace_pid_list *filtered_pids,
> struct task_struct *task)
> 	if (!filtered_pids)
> 		return false;
> 
> -	pid = task->pid;
> +	return !find_filtered_pid(filtered_pids, task->pid);
> +}
> 
> -	/*
> -	 * If pid_max changed after filtered_pids was created, we
> -	 * by default ignore all pids greater than the previous pid_max.
> -	 */
> -	if (task->pid >= filtered_pids->pid_max)
> -		return true;
> +static void filter_add_remove_task(struct trace_pid_list *pid_list,
> +				   struct task_struct *self,
> +				   struct task_struct *task)
> +{
> +	if (!pid_list)
> +		return;
> +
> +	/* For forks, we only add if the forking task is listed */
> +	if (self) {
> +		if (!find_filtered_pid(pid_list, self->pid))
> +			return;
> +	}
> +
> +	/* Sorry, but we don't support pid_max changing after setting */
> +	if (task->pid >= pid_list->pid_max)
> +		return;
> +
> +	/* "self" is set for forks, and NULL for exits */
> +	if (self)
> +		set_bit(task->pid, pid_list->pids);
> +	else
> +		clear_bit(task->pid, pid_list->pids);
> +}
> +
> +static void
> +event_filter_pid_sched_process_exit(void *data, struct task_struct *task)
> +{
> +	struct trace_pid_list *pid_list;
> +	struct trace_array *tr = data;
> +
> +	pid_list = rcu_dereference_sched(tr->filtered_pids);
> +	filter_add_remove_task(pid_list, NULL, task);
> +}
> 
> -	return !test_bit(task->pid, filtered_pids->pids);
> +static void
> +event_filter_pid_sched_process_fork(void *data,
> +				    struct task_struct *self,
> +				    struct task_struct *task)
> +{
> +	struct trace_pid_list *pid_list;
> +	struct trace_array *tr = data;
> +
> +	pid_list = rcu_dereference_sched(tr->filtered_pids);
> +	filter_add_remove_task(pid_list, self, task);
> +}
> +
> +void trace_event_follow_fork(struct trace_array *tr, bool enable)
> +{
> +	if (enable) {
> +		register_trace_prio_sched_process_fork(event_filter_pid_sched_process_fork,
> +						       tr, INT_MIN);
> +		register_trace_prio_sched_process_exit(event_filter_pid_sched_process_exit,
> +						       tr, INT_MAX);
> +	} else {
> +		unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
> +						    tr);
> +		unregister_trace_sched_process_exit(event_filter_pid_sched_process_exit,
> +						    tr);
> +	}
> }
> 
> static void
> --
> 2.8.0.rc3
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-trace-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2016-04-19 16:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19 14:34 [RFC][PATCH 0/4] tracing: Add event-fork to trace tasks children Steven Rostedt
2016-04-19 14:34 ` [RFC][PATCH 1/4] tracing: Rename check_ignore_pid() to ignore_this_task() Steven Rostedt
2016-04-19 14:34 ` [RFC][PATCH 2/4] tracing: Use pid bitmap instead of a pid array for set_event_pid Steven Rostedt
2016-04-19 16:55   ` Mathieu Desnoyers
2016-04-19 17:19     ` Steven Rostedt
2016-04-19 18:57       ` H. Peter Anvin
2016-04-19 19:41         ` Steven Rostedt
2016-04-19 20:17           ` Mathieu Desnoyers
2016-04-19 20:50             ` Steven Rostedt
2016-04-19 21:22               ` Mathieu Desnoyers
2016-04-19 22:49                 ` Steven Rostedt
2016-04-19 22:59                   ` Mathieu Desnoyers
2016-04-19 23:06                     ` Steven Rostedt
2016-04-22  2:45   ` Namhyung Kim
2016-04-22 15:30     ` Steven Rostedt
2016-04-19 14:34 ` [RFC][PATCH 3/4] tracing: Add infrastructure to allow set_event_pid to follow children Steven Rostedt
2016-04-19 16:55   ` Mathieu Desnoyers [this message]
2016-04-19 17:13     ` Steven Rostedt
2016-04-19 20:30       ` Mathieu Desnoyers
2016-04-19 14:34 ` [RFC][PATCH 4/4] tracing: Update the documentation to describe "event-fork" option Steven Rostedt
2016-04-20  2:05 ` [RFC][PATCH 0/4] tracing: Add event-fork to trace tasks children Daniel Bristot de Oliveira
2016-04-20  2: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=1887707510.62932.1461084911586.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-users@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.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