public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: [PATCH 1/2] ftrace: Add separate handler for ftrace:function event
Date: Wed, 25 Nov 2015 16:45:32 +0100	[thread overview]
Message-ID: <1448466333-28102-1-git-send-email-jolsa@kernel.org> (raw)

Having following commands running concurently:

  # perf record -e ftrace:function -a -o krava.data sleep 10
  # perf record -e ftrace:function --filter 'ip == SyS_read' ls

will endup in the latter one failing on the filter
rules and store all functions (in perf.data) as
instructed by the first record instead of just
SyS_read records.

The reason is that we don't check the ftrace_ops that
triggered the event with event's ftrace_ops. Hence
once running together the event from latter perf will
get all the data of the event from the first one.

Fixing this by having separate handler for ftrace:function
event that actualy checks ftrace_ops against event.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/perf_event.h      |  2 ++
 kernel/events/core.c            | 26 ++++++++++++++++++++++++++
 kernel/trace/trace_event_perf.c |  3 +--
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f9828a48f16a..be1ad1ef47f3 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1010,6 +1010,8 @@ extern void perf_tp_event(u64 addr, u64 count, void *record,
 			  struct hlist_head *head, int rctx,
 			  struct task_struct *task);
 extern void perf_bp_event(struct perf_event *event, void *data);
+void perf_ftrace_ops_event(struct ftrace_ops *ops, void *record, int entry_size,
+			   struct pt_regs *regs, struct hlist_head *head, int rctx);
 
 #ifndef perf_misc_flags
 # define perf_misc_flags(regs) \
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5854fcf7f05a..1ec33bebd39a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -44,6 +44,7 @@
 #include <linux/compat.h>
 #include <linux/bpf.h>
 #include <linux/filter.h>
+#include <linux/ftrace.h>
 
 #include "internal.h"
 
@@ -6950,6 +6951,31 @@ static int perf_tp_event_match(struct perf_event *event,
 	return 1;
 }
 
+#ifdef CONFIG_FUNCTION_TRACER
+void perf_ftrace_ops_event(struct ftrace_ops *ops, void *record, int entry_size,
+			   struct pt_regs *regs, struct hlist_head *head, int rctx)
+{
+	struct perf_sample_data data;
+	struct perf_event *event;
+
+	struct perf_raw_record raw = {
+		.size = entry_size,
+		.data = record,
+	};
+
+	perf_sample_data_init(&data, 0, 0);
+	data.raw = &raw;
+
+	hlist_for_each_entry_rcu(event, head, hlist_entry) {
+		if ((&event->ftrace_ops == ops) &&
+		    (perf_tp_event_match(event, &data, regs)))
+			perf_swevent_event(event, 1, &data, regs);
+	}
+
+	perf_swevent_put_recursion_context(rctx);
+}
+#endif
+
 void perf_tp_event(u64 addr, u64 count, void *record, int entry_size,
 		   struct pt_regs *regs, struct hlist_head *head, int rctx,
 		   struct task_struct *task)
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index cc9f7a9319be..fa1f12ef3ba3 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -324,8 +324,7 @@ perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
 
 	entry->ip = ip;
 	entry->parent_ip = parent_ip;
-	perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, 0,
-			      1, &regs, head, NULL);
+	perf_ftrace_ops_event(ops, entry, ENTRY_SIZE, &regs, head, rctx);
 
 #undef ENTRY_SIZE
 }
-- 
2.4.3


             reply	other threads:[~2015-11-25 15:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 15:45 Jiri Olsa [this message]
2015-11-25 15:45 ` [PATCH 2/2] ftrace: Check sample types only for sampling events Jiri Olsa
2015-11-25 16:19 ` [PATCH 1/2] ftrace: Add separate handler for ftrace:function event Steven Rostedt
2015-11-25 16:50   ` Jiri Olsa
2015-11-25 17:02     ` Steven Rostedt
2015-11-25 17:12       ` Jiri Olsa
2015-11-25 17:42         ` 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=1448466333-28102-1-git-send-email-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    /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