* [PATCH] perf: Set filters before mmaping events
@ 2011-02-26 4:03 Frederic Weisbecker
2011-03-02 8:49 ` Ingo Molnar
0 siblings, 1 reply; 4+ messages in thread
From: Frederic Weisbecker @ 2011-02-26 4:03 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Stephane Eranian, Tom Zanussi, Arnaldo Carvalho de Melo,
Steven Rostedt
We currently set the filters after we mmap the events, this is a
race that let undesired events record themselves in the buffer before
we had the time to set the filters.
So set the filters before they can be recorded. That also librarizes
the filters setting so that filtering can be done more easily
from other tools than perf record later.
(PS: This should fix most of the bugs Ingo has reported
about filters that weren't working with perf).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
---
tools/perf/builtin-record.c | 18 ++++++------------
tools/perf/util/evlist.c | 28 ++++++++++++++++++++++++++++
tools/perf/util/evlist.h | 1 +
3 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index db4cd1e..d40a81e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -180,12 +180,10 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
static void create_counter(struct perf_evsel *evsel, int cpu)
{
- char *filter = evsel->filter;
struct perf_event_attr *attr = &evsel->attr;
struct perf_header_attr *h_attr;
struct perf_sample_id *sid;
int thread_index;
- int ret;
for (thread_index = 0; thread_index < evsel_list->threads->nr; thread_index++) {
h_attr = get_header_attr(attr, evsel->idx);
@@ -204,16 +202,6 @@ static void create_counter(struct perf_evsel *evsel, int cpu)
pr_warning("Not enough memory to add id\n");
exit(-1);
}
-
- if (filter != NULL) {
- ret = ioctl(FD(evsel, cpu, thread_index),
- PERF_EVENT_IOC_SET_FILTER, filter);
- if (ret) {
- error("failed to set filter with %d (%s)\n", errno,
- strerror(errno));
- exit(-1);
- }
- }
}
if (!sample_type)
@@ -367,6 +355,12 @@ try_again:
}
}
+ if (perf_evlist__set_filters(evlist)) {
+ error("failed to set filter with %d (%s)\n", errno,
+ strerror(errno));
+ exit(-1);
+ }
+
if (perf_evlist__mmap(evlist, mmap_pages, false) < 0)
die("failed to mmap with %d (%s)\n", errno, strerror(errno));
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 95b21fe..030ae7f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -348,3 +348,31 @@ void perf_evlist__delete_maps(struct perf_evlist *evlist)
evlist->cpus = NULL;
evlist->threads = NULL;
}
+
+int perf_evlist__set_filters(struct perf_evlist *evlist)
+{
+ const struct thread_map *threads = evlist->threads;
+ const struct cpu_map *cpus = evlist->cpus;
+ struct perf_evsel *evsel;
+ char *filter;
+ int thread;
+ int cpu;
+ int err;
+ int fd;
+
+ list_for_each_entry(evsel, &evlist->entries, node) {
+ filter = evsel->filter;
+ if (!filter)
+ continue;
+ for (cpu = 0; cpu < cpus->nr; cpu++) {
+ for (thread = 0; thread < threads->nr; thread++) {
+ fd = FD(evsel, cpu, thread);
+ err = ioctl(fd, PERF_EVENT_IOC_SET_FILTER, filter);
+ if (err)
+ return err;
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index c988405..b75805a 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -60,5 +60,6 @@ static inline void perf_evlist__set_maps(struct perf_evlist *evlist,
int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid,
pid_t target_tid, const char *cpu_list);
void perf_evlist__delete_maps(struct perf_evlist *evlist);
+int perf_evlist__set_filters(struct perf_evlist *evlist);
#endif /* __PERF_EVLIST_H */
--
1.7.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] perf: Set filters before mmaping events
2011-02-26 4:03 [PATCH] perf: Set filters before mmaping events Frederic Weisbecker
@ 2011-03-02 8:49 ` Ingo Molnar
2011-03-03 3:51 ` [GIT PULL] tracepoints filtering updates Frederic Weisbecker
0 siblings, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2011-03-02 8:49 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: Arnaldo Carvalho de Melo, LKML, Peter Zijlstra, Stephane Eranian,
Tom Zanussi, Steven Rostedt
* Frederic Weisbecker <fweisbec@gmail.com> wrote:
> We currently set the filters after we mmap the events, this is a
> race that let undesired events record themselves in the buffer before
> we had the time to set the filters.
>
> So set the filters before they can be recorded. That also librarizes
> the filters setting so that filtering can be done more easily
> from other tools than perf record later.
>
> (PS: This should fix most of the bugs Ingo has reported
> about filters that weren't working with perf).
Nice!
Mind pulling Steve's filter-enhancements branch and sending a pull request for the
whole thing? Steve's branch was:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git tip/perf/filter
( Or your fixes could be applied to Steve's branch as well - whichever direction you
guys prefer - the important thing is to have filtering tested and validated as a
whole. )
Thanks,
Ingo
^ permalink raw reply [flat|nested] 4+ messages in thread
* [GIT PULL] tracepoints filtering updates
2011-03-02 8:49 ` Ingo Molnar
@ 2011-03-03 3:51 ` Frederic Weisbecker
2011-03-03 7:10 ` Ingo Molnar
0 siblings, 1 reply; 4+ messages in thread
From: Frederic Weisbecker @ 2011-03-03 3:51 UTC (permalink / raw)
To: Ingo Molnar
Cc: Arnaldo Carvalho de Melo, LKML, Peter Zijlstra, Stephane Eranian,
Tom Zanussi, Steven Rostedt
On Wed, Mar 02, 2011 at 09:49:25AM +0100, Ingo Molnar wrote:
>
> * Frederic Weisbecker <fweisbec@gmail.com> wrote:
>
> > We currently set the filters after we mmap the events, this is a
> > race that let undesired events record themselves in the buffer before
> > we had the time to set the filters.
> >
> > So set the filters before they can be recorded. That also librarizes
> > the filters setting so that filtering can be done more easily
> > from other tools than perf record later.
> >
> > (PS: This should fix most of the bugs Ingo has reported
> > about filters that weren't working with perf).
>
> Nice!
>
> Mind pulling Steve's filter-enhancements branch and sending a pull request for the
> whole thing? Steve's branch was:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git tip/perf/filter
>
> ( Or your fixes could be applied to Steve's branch as well - whichever direction you
> guys prefer - the important thing is to have filtering tested and validated as a
> whole. )
>
> Thanks,
>
> Ingo
Ok, I've merged Steve's branch and tested a few common filters with perf:
* irq numbers on irq tracepoints
* fd on sys_enter_close
* prev_comm on sched_switch (to test string)
they all work well.
You can pull the branch from:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/core
--
Frederic Weisbecker (2):
perf: Set filters before mmaping events
Merge branch '/tip/perf/filter' of git://git.kernel.org/.../rostedt/linux-2.6-trace.git into perf/core
Steven Rostedt (14):
tracing/filter: Have no filter return a match
tracing/filter: Move OR and AND logic out of fn() method
tracing/filter: Dynamically allocate preds
tracing/filter: Call synchronize_sched() just once for system filters
tracing/filter: Allocate the preds in an array
tracing/filter: Free pred array on disabling of filter
tracing/filter: Use a tree instead of stack for filter_match_preds()
tracing/filter: Optimize short ciruit check
tracing/filter: Check the created pred tree
tracing/filter: Optimize filter by folding the tree
tracing/filter: Move MAX_FILTER_PRED to local tracing directory
tracing/filter: Increase the max preds to 2^14
tracing/filter: Swap entire filter of events
tracing/filter: Remove synchronize_sched() from __alloc_preds()
--
include/linux/ftrace_event.h | 1 -
kernel/trace/trace.h | 38 ++-
kernel/trace/trace_events_filter.c | 885 +++++++++++++++++++++++++++++-------
tools/perf/builtin-record.c | 18 +-
tools/perf/util/evlist.c | 28 ++
tools/perf/util/evlist.h | 1 +
6 files changed, 789 insertions(+), 182 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [GIT PULL] tracepoints filtering updates
2011-03-03 3:51 ` [GIT PULL] tracepoints filtering updates Frederic Weisbecker
@ 2011-03-03 7:10 ` Ingo Molnar
0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2011-03-03 7:10 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: Arnaldo Carvalho de Melo, LKML, Peter Zijlstra, Stephane Eranian,
Tom Zanussi, Steven Rostedt
* Frederic Weisbecker <fweisbec@gmail.com> wrote:
> l (fweisbec[at]gmail.com)
> -2.0 BAYES_00 BODY: Bayes spam probability is 0 to 1%
> [score: 0.0000]
> Content-Length: 3017
> Lines: 76
>
> On Wed, Mar 02, 2011 at 09:49:25AM +0100, Ingo Molnar wrote:
> >
> > * Frederic Weisbecker <fweisbec@gmail.com> wrote:
> >
> > > We currently set the filters after we mmap the events, this is a
> > > race that let undesired events record themselves in the buffer before
> > > we had the time to set the filters.
> > >
> > > So set the filters before they can be recorded. That also librarizes
> > > the filters setting so that filtering can be done more easily
> > > from other tools than perf record later.
> > >
> > > (PS: This should fix most of the bugs Ingo has reported
> > > about filters that weren't working with perf).
> >
> > Nice!
> >
> > Mind pulling Steve's filter-enhancements branch and sending a pull request for the
> > whole thing? Steve's branch was:
> >
> > git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git tip/perf/filter
> >
> > ( Or your fixes could be applied to Steve's branch as well - whichever direction you
> > guys prefer - the important thing is to have filtering tested and validated as a
> > whole. )
> >
> > Thanks,
> >
> > Ingo
>
> Ok, I've merged Steve's branch and tested a few common filters with perf:
>
> * irq numbers on irq tracepoints
> * fd on sys_enter_close
> * prev_comm on sched_switch (to test string)
>
> they all work well.
>
> You can pull the branch from:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
> perf/core
>
> --
> Frederic Weisbecker (2):
> perf: Set filters before mmaping events
> Merge branch '/tip/perf/filter' of git://git.kernel.org/.../rostedt/linux-2.6-trace.git into perf/core
>
> Steven Rostedt (14):
> tracing/filter: Have no filter return a match
> tracing/filter: Move OR and AND logic out of fn() method
> tracing/filter: Dynamically allocate preds
> tracing/filter: Call synchronize_sched() just once for system filters
> tracing/filter: Allocate the preds in an array
> tracing/filter: Free pred array on disabling of filter
> tracing/filter: Use a tree instead of stack for filter_match_preds()
> tracing/filter: Optimize short ciruit check
> tracing/filter: Check the created pred tree
> tracing/filter: Optimize filter by folding the tree
> tracing/filter: Move MAX_FILTER_PRED to local tracing directory
> tracing/filter: Increase the max preds to 2^14
> tracing/filter: Swap entire filter of events
> tracing/filter: Remove synchronize_sched() from __alloc_preds()
> --
> include/linux/ftrace_event.h | 1 -
> kernel/trace/trace.h | 38 ++-
> kernel/trace/trace_events_filter.c | 885 +++++++++++++++++++++++++++++-------
> tools/perf/builtin-record.c | 18 +-
> tools/perf/util/evlist.c | 28 ++
> tools/perf/util/evlist.h | 1 +
> 6 files changed, 789 insertions(+), 182 deletions(-)
Pulled, thanks a lot guys!
Ingo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-03 7:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-26 4:03 [PATCH] perf: Set filters before mmaping events Frederic Weisbecker
2011-03-02 8:49 ` Ingo Molnar
2011-03-03 3:51 ` [GIT PULL] tracepoints filtering updates Frederic Weisbecker
2011-03-03 7:10 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox