From: Oleg Nesterov <oleg@redhat.com>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Steven Rostedt <rostedt@goodmis.org>
Cc: Anton Arapov <anton@redhat.com>, Frank Eigler <fche@redhat.com>,
Jiri Olsa <jolsa@redhat.com>, Josh Stone <jistone@redhat.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
"Suzuki K. Poulose" <suzuki@in.ibm.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] uprobes/perf: Avoid uprobe_apply() whenever possible
Date: Mon, 4 Feb 2013 20:03:05 +0100 [thread overview]
Message-ID: <20130204190305.GA10892@redhat.com> (raw)
In-Reply-To: <20130204190225.GA10840@redhat.com>
uprobe_perf_open/close call the costly uprobe_apply() every time,
we can avoid it if:
- "nr_systemwide != 0" is not changed.
- There is another process/thread with the same ->mm.
- copy_proccess() does inherit_event(). dup_mmap() preserves the
inserted breakpoints.
- event->attr.enable_on_exec == T, we can rely on uprobe_mmap()
called by exec/mmap paths.
- tp_target is exiting. Only _close() checks PF_EXITING, I don't
think TRACE_REG_PERF_OPEN can hit the dying task too often.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/trace/trace_uprobe.c | 42 ++++++++++++++++++++++++++++++++++++------
1 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 1114619..e4aab34 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -677,30 +677,60 @@ __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
return false;
}
+static inline bool
+uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event)
+{
+ return __uprobe_perf_filter(&tu->filter, event->hw.tp_target->mm);
+}
+
static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event)
{
+ bool done;
+
write_lock(&tu->filter.rwlock);
- if (event->hw.tp_target)
+ if (event->hw.tp_target) {
+ /*
+ * event->parent != NULL means copy_process(), we can avoid
+ * uprobe_apply(). current->mm must be probed and we can rely
+ * on dup_mmap() which preserves the already installed bp's.
+ *
+ * attr.enable_on_exec means that exec/mmap will install the
+ * breakpoints we need.
+ */
+ done = tu->filter.nr_systemwide ||
+ event->parent || event->attr.enable_on_exec ||
+ uprobe_filter_event(tu, event);
list_add(&event->hw.tp_list, &tu->filter.perf_events);
- else
+ } else {
+ done = tu->filter.nr_systemwide;
tu->filter.nr_systemwide++;
+ }
write_unlock(&tu->filter.rwlock);
- uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
+ if (!done)
+ uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
return 0;
}
static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event)
{
+ bool done;
+
write_lock(&tu->filter.rwlock);
- if (event->hw.tp_target)
+ if (event->hw.tp_target) {
list_del(&event->hw.tp_list);
- else
+ done = tu->filter.nr_systemwide ||
+ (event->hw.tp_target->flags & PF_EXITING) ||
+ uprobe_filter_event(tu, event);
+ } else {
tu->filter.nr_systemwide--;
+ done = tu->filter.nr_systemwide;
+ }
write_unlock(&tu->filter.rwlock);
- uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
+ if (!done)
+ uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
return 0;
}
--
1.5.5.1
next prev parent reply other threads:[~2013-02-04 19:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-04 19:02 [PATCH 0/7] uprobes/perf: pre-filtering Oleg Nesterov
2013-02-04 19:02 ` [PATCH 1/7] perf: Ensure we do not free event->parent before event Oleg Nesterov
2013-03-20 13:35 ` Jiri Olsa
2013-02-04 19:02 ` [PATCH 2/7] perf: Introduce hw_perf_event->tp_target and ->tp_list Oleg Nesterov
2013-02-11 9:44 ` Srikar Dronamraju
2013-02-04 19:02 ` [PATCH 3/7] uprobes: Introduce uprobe_apply() Oleg Nesterov
2013-02-11 9:43 ` Srikar Dronamraju
2013-02-04 19:02 ` [PATCH 4/7] uprobes/perf: Teach trace_uprobe/perf code to track the active perf_event's Oleg Nesterov
2013-02-11 9:45 ` Srikar Dronamraju
2013-02-04 19:02 ` [PATCH 5/7] uprobes/perf: Teach trace_uprobe/perf code to pre-filter Oleg Nesterov
2013-02-11 9:46 ` Srikar Dronamraju
2013-02-04 19:03 ` [PATCH 6/7] uprobes/perf: Teach trace_uprobe/perf code to use UPROBE_HANDLER_REMOVE Oleg Nesterov
2013-02-11 9:54 ` Srikar Dronamraju
2013-02-04 19:03 ` Oleg Nesterov [this message]
2013-02-11 9:55 ` [PATCH 7/7] uprobes/perf: Avoid uprobe_apply() whenever possible Srikar Dronamraju
2013-02-06 18:10 ` [PATCH 0/7] uprobes/perf: pre-filtering Oleg Nesterov
2013-02-06 19:42 ` [PATCH 0/1] (Was uprobes/perf: pre-filtering) Oleg Nesterov
2013-02-06 19:42 ` [PATCH 1/1] perf/tools: Fix "perf record -C... workload" behaviour Oleg Nesterov
2013-02-25 9:58 ` Jiri Olsa
2013-02-07 6:01 ` [PATCH 0/1] (Was uprobes/perf: pre-filtering) Namhyung Kim
2013-02-07 15:22 ` Oleg Nesterov
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=20130204190305.GA10892@redhat.com \
--to=oleg@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=anton@redhat.com \
--cc=fche@redhat.com \
--cc=jistone@redhat.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=suzuki@in.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;
as well as URLs for NNTP newsgroup(s).