perf tools: Pass whole attr to event selectors
PATCH 1/1 perf tools: Pass whole attr to event selectors
Since commit 69aad6f1(perf tools: Introduce event selectors), only perf_event_attr::type and ::config are passed to event selector, which makes perf tool not work correctly.
For example, PEBS does not work because perf_event_attr::precise_ip is not passed to the syscall.
--- tools/perf/builtin-stat.c | 3 +-- tools/perf/builtin-test.c | 6 +++++- tools/perf/util/evsel.c | 5 ++--- tools/perf/util/evsel.h | 2 +- tools/perf/util/parse-events.c | 13 ++++++++++--- 5 files changed, 19 insertions(+), 10 deletions(-)
tools/perf/builtin-stat.c +1 -2
@@ -683,8 +683,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) nr_counters =ARRAY_SIZE (default_attrs);for (c =0 ; c <ARRAY_SIZE (default_attrs); ++c) { - pos =perf_evsel__new (default_attrs[c].type, - default_attrs[c].config, + pos =perf_evsel__new (&default_attrs[c], nr_counters);if (pos ==NULL ) goto out;
tools/perf/builtin-test.c +5 -1
@@ -264,6 +264,7 @@ static int test__open_syscall_event(void)int err =-1 , fd;struct thread_map *threads;struct perf_evsel *evsel; +struct perf_event_attr attr;unsigned int nr_open_calls =111 , i;int id =trace_event__id ("sys_enter_open" );
@@ -278,7 +279,10 @@ static int test__open_syscall_event(void)return -1 ; } - evsel =perf_evsel__new (PERF_TYPE_TRACEPOINT , id,0 ); +memset (&attr,0 ,sizeof (attr)); + attr.type =PERF_TYPE_TRACEPOINT ; + attr.config = id; + evsel =perf_evsel__new (&attr,0 );if (evsel ==NULL ) {pr_debug ("perf_evsel__new\n" ); goto out_thread_map_delete;
tools/perf/util/evsel.c +2 -3
@@ -6,14 +6,13 @@#define FD (e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) -struct perf_evsel *perf_evsel__new (u32 type,u64 config,int idx) +struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr,int idx) {struct perf_evsel *evsel =zalloc (sizeof (*evsel));if (evsel !=NULL ) { evsel->idx = idx; - evsel->attr.type = type; - evsel->attr.config = config; + evsel->attr = *attr;INIT_LIST_HEAD (&evsel->node); }
tools/perf/util/evsel.h +1 -1
@@ -37,7 +37,7 @@ struct perf_evsel {struct cpu_map ;struct thread_map ; -struct perf_evsel *perf_evsel__new (u32 type,u64 config,int idx); +struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr,int idx);void perf_evsel__delete (struct perf_evsel *evsel);int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads);
tools/perf/util/parse-events.c +10 -3
@@ -824,7 +824,7 @@ int parse_events(const struct option *opt __used, const char *str, int unset __uif (ret !=EVT_HANDLED_ALL ) {struct perf_evsel *evsel; - evsel =perf_evsel__new (attr.type, attr.config, + evsel =perf_evsel__new (&attr, nr_counters);if (evsel ==NULL )return -1 ;
@@ -1014,8 +1014,15 @@ void print_events(void)int perf_evsel_list__create_default (void ) { -struct perf_evsel *evsel =perf_evsel__new (PERF_TYPE_HARDWARE , -PERF_COUNT_HW_CPU_CYCLES ,0 ); +struct perf_evsel *evsel; +struct perf_event_attr attr; + +memset (&attr,0 ,sizeof (attr)); + attr.type =PERF_TYPE_HARDWARE ; + attr.config =PERF_COUNT_HW_CPU_CYCLES ; + + evsel =perf_evsel__new (&attr,0 ); +if (evsel ==NULL )return -ENOMEM ;
Em Fri, Jan 07, 2011 at 11:11:09AM +0800, Lin Ming escreveu:
Quoted 6 lines
Since commit 69aad6f1(perf tools: Introduce event selectors), only
perf_event_attr::typeand ::config are passed to event selector, which makes perf tool not work correctly.For example, PEBS does not work because
perf_event_attr::precise_ipis not passed to the syscall.
Right, thanks for the fix, Ingo, I'm adding this to my perf/core tree.
- Arnaldo
Commit-ID: 23a2f3ab46596d9fd0b0e592d2101bea90970594 Gitweb: http://git.kernel.org/tip/23a2f3ab46596d9fd0b0e592d2101bea90970594 Author: Lin Ming <[email protected]> AuthorDate: Fri, 7 Jan 2011 11:11:09 +0800 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 7 Jan 2011 01:44:36 -0200
perf tools: Pass whole attr to event selectors
Since commit 69aad6f1(perf tools: Introduce event selectors), only perf_event_attr::type and ::config are passed to event selector, which makes perf tool not work correctly.
For example, PEBS does not work because perf_event_attr::precise_ip is not passed to the syscall.
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
--- tools/perf/builtin-stat.c | 3 +-- tools/perf/builtin-test.c | 6 +++++- tools/perf/util/evsel.c | 5 ++--- tools/perf/util/evsel.h | 2 +- tools/perf/util/parse-events.c | 13 ++++++++++--- 5 files changed, 19 insertions(+), 10 deletions(-)
tools/perf/builtin-stat.c +1 -2
@@ -683,8 +683,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) nr_counters =ARRAY_SIZE (default_attrs);for (c =0 ; c <ARRAY_SIZE (default_attrs); ++c) { - pos =perf_evsel__new (default_attrs[c].type, - default_attrs[c].config, + pos =perf_evsel__new (&default_attrs[c], nr_counters);if (pos ==NULL ) goto out;
tools/perf/builtin-test.c +5 -1
@@ -264,6 +264,7 @@ static int test__open_syscall_event(void)int err =-1 , fd;struct thread_map *threads;struct perf_evsel *evsel; +struct perf_event_attr attr;unsigned int nr_open_calls =111 , i;int id =trace_event__id ("sys_enter_open" );
@@ -278,7 +279,10 @@ static int test__open_syscall_event(void)return -1 ; } - evsel =perf_evsel__new (PERF_TYPE_TRACEPOINT , id,0 ); +memset (&attr,0 ,sizeof (attr)); + attr.type =PERF_TYPE_TRACEPOINT ; + attr.config = id; + evsel =perf_evsel__new (&attr,0 );if (evsel ==NULL ) {pr_debug ("perf_evsel__new\n" ); goto out_thread_map_delete;
tools/perf/util/evsel.c +2 -3
@@ -6,14 +6,13 @@#define FD (e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) -struct perf_evsel *perf_evsel__new (u32 type,u64 config,int idx) +struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr,int idx) {struct perf_evsel *evsel =zalloc (sizeof (*evsel));if (evsel !=NULL ) { evsel->idx = idx; - evsel->attr.type = type; - evsel->attr.config = config; + evsel->attr = *attr;INIT_LIST_HEAD (&evsel->node); }
tools/perf/util/evsel.h +1 -1
@@ -37,7 +37,7 @@ struct perf_evsel {struct cpu_map ;struct thread_map ; -struct perf_evsel *perf_evsel__new (u32 type,u64 config,int idx); +struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr,int idx);void perf_evsel__delete (struct perf_evsel *evsel);int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads);
tools/perf/util/parse-events.c +10 -3
@@ -823,7 +823,7 @@ int parse_events(const struct option *opt __used, const char *str, int unset __uif (ret !=EVT_HANDLED_ALL ) {struct perf_evsel *evsel; - evsel =perf_evsel__new (attr.type, attr.config, + evsel =perf_evsel__new (&attr, nr_counters);if (evsel ==NULL )return -1 ;
@@ -1013,8 +1013,15 @@ void print_events(void)int perf_evsel_list__create_default (void ) { -struct perf_evsel *evsel =perf_evsel__new (PERF_TYPE_HARDWARE , -PERF_COUNT_HW_CPU_CYCLES ,0 ); +struct perf_evsel *evsel; +struct perf_event_attr attr; + +memset (&attr,0 ,sizeof (attr)); + attr.type =PERF_TYPE_HARDWARE ; + attr.config =PERF_COUNT_HW_CPU_CYCLES ; + + evsel =perf_evsel__new (&attr,0 ); +if (evsel ==NULL )return -ENOMEM ;