tools/perf: fix the event grouping functionality
cover tools/perf: fix the event grouping functionality
Two patches relating to the event state and group_fd of grouped events at creation.
Deng-Cheng Zhu (2):
tools/perf: Don't set attr->disabled when doing grouping tools/perf: Make group_fd static and move its place in
__perf_evsel__open()
tools/perf/builtin-record.c | 6 +++--- tools/perf/builtin-stat.c | 3 ++- tools/perf/util/evsel.c | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-)
RFC PATCH 1/2 tools/perf: Don't set attr->disabled when doing grouping
Events will be created at the state PERF_EVENT_STATE_OFF if attr->disabled is set. When these events go to arch level validate_group(), the function won't do anything real because they are filtered out by the state check.
--- tools/perf/builtin-record.c | 6 +++--- tools/perf/builtin-stat.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +3 -3
@@ -161,7 +161,6 @@ static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist)struct perf_event_attr *attr = &evsel->attr;int track = !evsel->idx;/* only the first counter needs these */ - attr->disabled =1 ; attr->inherit = !no_inherit; attr->read_format =PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING |
@@ -222,10 +221,11 @@ static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist) attr->mmap = track; attr->comm = track; -if (target_pid ==-1 && target_tid ==-1 && !system_wide) { +if (!group) attr->disabled =1 ; + +if (target_pid ==-1 && target_tid ==-1 && !system_wide) attr->enable_on_exec =1 ; - } } static bool perf_evlist__equal(struct perf_evlist *evlist,
tools/perf/builtin-stat.c +2 -1
@@ -284,7 +284,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)return perf_evsel__open_per_cpu (evsel, evsel_list->cpus, group);if (target_pid ==-1 && target_tid ==-1 ) { - attr->disabled =1 ; +if (!group) + attr->disabled =1 ; attr->enable_on_exec =1 ; }
Signature · 1 line
1.7.1
RFC PATCH 2/2 tools/perf: Make group_fd static and move its place in __perf_evsel__open()
In reply to Deng-Cheng Zhu__perf_evsel__open() is called per event, it does not work for all the grouped events at one time. So, currently group_fd will alway be -1 for the events in a group. This patch fixes it.
--- tools/perf/util/evsel.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/util/evsel.c +1 -2
@@ -219,9 +219,8 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, }for (cpu =0 ; cpu < cpus->nr; cpu++) { -int group_fd =-1 ; -for (thread =0 ; thread < threads->nr; thread++) { +static int group_fd =-1 ;if (!evsel->cgrp) pid = threads->map[thread];
Signature · 1 line
1.7.1
Re: [RFC PATCH 2/2] tools/perf: Make group_fd static and move its place in __perf_evsel__open()
Em Mon, Oct 24, 2011 at 06:57:00PM +0800, Deng-Cheng Zhu escreveu:
Quoted 18 lines
__perf_evsel__open()is called per event, it does not work for all the grouped events at one time. So, currentlygroup_fdwill alway be -1 for the events in a group. This patch fixes it.Signed-off-by Deng-Cheng Zhu <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Paul Mackerras <[email protected]>Cc Ingo Molnar <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/evsel.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)tools/perf/util/evsel.c +0
-0
tools/perf/util/evsel.c static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, · line 226
Quoted 10 lines
tools/perf/util/evsel.c +1
-2@@ -219,9 +219,8 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, }for (cpu =0 ; cpu < cpus->nr; cpu++) { -int group_fd =-1 ; -for (thread =0 ; thread < threads->nr; thread++) { +static int group_fd =-1 ;if (!evsel->cgrp) pid = threads->map[thread];
Lets not do it that way, using statics for this is humm, ugly, IMHO.
Just pass an integer pointer that is a member of perf_evlist, I'll work on a patch now.
Thanks for reporting the bug tho!
- Arnaldo
Re: [RFC PATCH 1/2] tools/perf: Don't set attr->disabled when doing grouping
In reply to Deng-Cheng ZhuQuoted 3 lines · Deng-Cheng Zhu
Events will be created at the state
PERF_EVENT_STATE_OFFifattr->disabledis set. When these events go to arch levelvalidate_group(), the function won't do anything real because they are filtered out by the state check.
Seems like a bug with the group checks. You should be able to enable and disable events - including creating them disabled.
David
Quoted 51 lines
Signed-off-by Deng-Cheng Zhu <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Paul Mackerras <[email protected]>Cc Ingo Molnar <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/builtin-record.c | 6 +++--- tools/perf/builtin-stat.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)tools/perf/builtin-record.c +3
-3@@ -161,7 +161,6 @@ static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist)struct perf_event_attr *attr = &evsel->attr;int track = !evsel->idx;/* only the first counter needs these */ - attr->disabled =1 ; attr->inherit = !no_inherit; attr->read_format =PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING |@@ -222,10 +221,11 @@ static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist) attr->mmap = track; attr->comm = track; -if (target_pid ==-1 && target_tid ==-1 && !system_wide) { +if (!group) attr->disabled =1 ; + +if (target_pid ==-1 && target_tid ==-1 && !system_wide) attr->enable_on_exec =1 ; - } } static bool perf_evlist__equal(struct perf_evlist *evlist,tools/perf/builtin-stat.c +2
-1@@ -284,7 +284,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)return perf_evsel__open_per_cpu (evsel, evsel_list->cpus, group);if (target_pid ==-1 && target_tid ==-1 ) { - attr->disabled =1 ; +if (!group) + attr->disabled =1 ; attr->enable_on_exec =1 ; }
Re: [RFC PATCH 1/2] tools/perf: Don't set attr->disabled when doing grouping
Quoted 3 lines · David Ahern
Seems like a bug with the group checks. You should be able to enable and disable events - including creating them disabled.
Agreed, it makes no sense to allow creating a group you can't use.
Re: [RFC PATCH 2/2] tools/perf: Make group_fd static and move its place in __perf_evsel__open()
In reply to Arnaldo Carvalho de MeloEm Mon, Oct 24, 2011 at 12:03:28PM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 32 lines
Em Mon, Oct 24, 2011 at 06:57:00PM +0800, Deng-Cheng Zhu escreveu:
Quoted 18 lines
__perf_evsel__open()is called per event, it does not work for all the grouped events at one time. So, currentlygroup_fdwill alway be -1 for the events in a group. This patch fixes it.Signed-off-by Deng-Cheng Zhu <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Paul Mackerras <[email protected]>Cc Ingo Molnar <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/evsel.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)tools/perf/util/evsel.c +0
-0tools/perf/util/evsel.c static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, · line 226
Quoted 10 lines
tools/perf/util/evsel.c +1
-2@@ -219,9 +219,8 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, }for (cpu =0 ; cpu < cpus->nr; cpu++) { -int group_fd =-1 ; -for (thread =0 ; thread < threads->nr; thread++) { +static int group_fd =-1 ;if (!evsel->cgrp) pid = threads->map[thread];Lets not do it that way, using statics for this is humm, ugly, IMHO.
Quoted 4 lines
Just pass an integer pointer that is a member of
perf_evlist, I'll work on a patch now.Thanks for reporting the bug tho!
Can you try this patch?
I tested it with:
[root@emilia ~]# perf top -e cycles -e instructions --group
and
[root@emilia ~]# perf record -e cycles -e instructions --group -a sleep 2
Peter,
Do you see anything wrong with it?
Thanks,
- Arnaldo
Quoted 1 line
From
fa5e5376207a3e08e0893c3a15321d8972e51fd1Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Tue, 25 Oct 2011 10:42:19 -0200
Subject: [PATCH] perf evlist: Fix grouping of multiple events
The __perf_evsel__open routing was grouping just the threads for that specific events per cpu when we want to group all threads in all events to the first fd opened on that cpu.
So pass the xyarray with the first event, where the other events will be able to get that first per cpu fd.
At some point top and record will switch to using perf_evlist__open that takes care of this detail and probably will also handle the fallback from hw to soft counters, etc.
--- tools/perf/builtin-record.c | 11 +++++++++-- tools/perf/builtin-stat.c | 20 ++++++++++++++------ tools/perf/builtin-test.c | 6 +++--- tools/perf/builtin-top.c | 11 +++++++++-- tools/perf/util/evlist.c | 30 ++++++++++++++++++++++++++++++ tools/perf/util/evlist.h | 2 ++ tools/perf/util/evsel.c | 43 +++++++++++++++++++++++++++++++------------ tools/perf/util/evsel.h | 10 +++++++--- tools/perf/util/python.c | 31 ++++++++++++++++++++++++++++++- 9 files changed, 135 insertions(+), 29 deletions(-)
tools/perf/builtin-record.c +9 -2
@@ -262,13 +262,16 @@ static bool perf_evlist__equal(struct perf_evlist *evlist,static void open_counters (struct perf_evlist *evlist) { -struct perf_evsel *pos; +struct perf_evsel *pos, *first;if (evlist->cpus->map[0 ] <0 ) no_inherit = true; + first = list_entry(evlist->entries.next, struct perf_evsel, node); +list_for_each_entry (pos, &evlist->entries, node) {struct perf_event_attr *attr = &pos->attr; +struct xyarray *group_fd =NULL ;/* * Check if parse_single_tracepoint_event has already asked for * PERF_SAMPLE_TIME.
@@ -283,11 +286,15 @@ static void open_counters(struct perf_evlist *evlist)*/ bool time_needed = attr->sample_type &PERF_SAMPLE_TIME ; +if (group && pos != first) + group_fd = first->fd; +config_attr (pos, evlist); retry_sample_id: attr->sample_id_all = sample_id_all_avail ?1 :0 ; try_again: -if (perf_evsel__open (pos, evlist->cpus, evlist->threads, group) <0 ) { +if (perf_evsel__open (pos, evlist->cpus, evlist->threads, group, + group_fd) <0 ) {int err = errno;if (err ==EPERM || err ==EACCES ) {
tools/perf/builtin-stat.c +14 -6
@@ -278,9 +278,14 @@ struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS ];struct stats walltime_nsecs_stats; -static int create_perf_stat_counter (struct perf_evsel *evsel) +static int create_perf_stat_counter (struct perf_evsel *evsel, +struct perf_evsel *first) {struct perf_event_attr *attr = &evsel->attr; +struct xyarray *group_fd =NULL ; + +if (group && evsel != first) + group_fd = first->fd;if (scale) attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -289,14 +294,15 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->inherit = !no_inherit;if (system_wide) -return perf_evsel__open_per_cpu (evsel, evsel_list->cpus, group); - +return perf_evsel__open_per_cpu (evsel, evsel_list->cpus, + group, group_fd);if (target_pid ==-1 && target_tid ==-1 ) { attr->disabled =1 ; attr->enable_on_exec =1 ; } -return perf_evsel__open_per_thread (evsel, evsel_list->threads, group); +return perf_evsel__open_per_thread (evsel, evsel_list->threads, + group, group_fd); }/*
@@ -396,7 +402,7 @@ static int read_counter(struct perf_evsel *counter)static int run_perf_stat (int argc__used ,const char **argv) {unsigned long long t0, t1; -struct perf_evsel *counter; +struct perf_evsel *counter, *first;int status =0 ;int child_ready_pipe[2 ], go_pipe[2 ];const bool forks = (argc >0 );
@@ -453,8 +459,10 @@ static int run_perf_stat(int argc __used, const char **argv)close (child_ready_pipe[0 ]); } + first = list_entry(evsel_list->entries.next, struct perf_evsel, node); +list_for_each_entry (counter, &evsel_list->entries, node) { -if (create_perf_stat_counter (counter) <0 ) { +if (create_perf_stat_counter (counter, first) <0 ) {if (errno ==EINVAL || errno ==ENOSYS || errno ==ENOENT ) {if (verbose) ui__warning("%s event is not supported by the kernel.\n",
tools/perf/builtin-test.c +3 -3
@@ -291,7 +291,7 @@ static int test__open_syscall_event(void) goto out_thread_map_delete; } -if (perf_evsel__open_per_thread (evsel, threads, false) <0 ) { +if (perf_evsel__open_per_thread (evsel, threads, false,NULL ) <0 ) {pr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,strerror (errno));
@@ -366,7 +366,7 @@ static int test__open_syscall_event_on_all_cpus(void) goto out_thread_map_delete; } -if (perf_evsel__open (evsel, cpus, threads, false) <0 ) { +if (perf_evsel__open (evsel, cpus, threads, false,NULL ) <0 ) {pr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,strerror (errno));
@@ -531,7 +531,7 @@ static int test__basic_mmap(void)perf_evlist__add (evlist, evsels[i]); -if (perf_evsel__open (evsels[i], cpus, threads, false) <0 ) { +if (perf_evsel__open (evsels[i], cpus, threads, false,NULL ) <0 ) {pr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,strerror (errno));
tools/perf/builtin-top.c +9 -2
@@ -834,10 +834,16 @@ static void perf_session__mmap_read(struct perf_session *self)static void start_counters (struct perf_evlist *evlist) { -struct perf_evsel *counter; +struct perf_evsel *counter, *first; + + first = list_entry(evlist->entries.next, struct perf_evsel, node);list_for_each_entry (counter, &evlist->entries, node) {struct perf_event_attr *attr = &counter->attr; +struct xyarray *group_fd =NULL ; + +if (group && counter != first) + group_fd = first->fd; attr->sample_type =PERF_SAMPLE_IP |PERF_SAMPLE_TID ;
@@ -860,7 +866,8 @@ static void start_counters(struct perf_evlist *evlist) attr->inherit = inherit; try_again:if (perf_evsel__open (counter, top.evlist->cpus, - top.evlist->threads, group) <0 ) { + top.evlist->threads, group, + group_fd) <0 ) {int err = errno;if (err ==EPERM || err ==EACCES ) {
tools/perf/util/evlist.c +30 -0
@@ -539,3 +539,33 @@ void perf_evlist__set_selected(struct perf_evlist *evlist, { evlist->selected = evsel; } + +int perf_evlist__open (struct perf_evlist *evlist,bool group) +{ +struct perf_evsel *evsel, *first; +int err, ncpus, nthreads; + + first = list_entry(evlist->entries.next, struct perf_evsel, node); + +list_for_each_entry (evsel, &evlist->entries, node) { +struct xyarray *group_fd =NULL ; + +if (group && evsel != first) + group_fd = first->fd; + + err =perf_evsel__open (evsel, evlist->cpus, evlist->threads, + group, group_fd); +if (err <0 ) + goto out_err; + } + +return 0 ; +out_err: + ncpus = evlist->cpus ? evlist->cpus->nr :1 ; + nthreads = evlist->threads ? evlist->threads->nr :1 ; + +list_for_each_entry_reverse (evsel, &evlist->entries, node) +perf_evsel__close (evsel, ncpus, nthreads); + +return err; +}
tools/perf/util/evlist.h +2 -0
@@ -50,6 +50,8 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);union perf_event *perf_evlist__mmap_read (struct perf_evlist *self,int idx); +int perf_evlist__open (struct perf_evlist *evlist,bool group); +int perf_evlist__alloc_mmap (struct perf_evlist *evlist);int perf_evlist__mmap (struct perf_evlist *evlist,int pages,bool overwrite);void perf_evlist__munmap (struct perf_evlist *evlist);
tools/perf/util/evsel.c +31 -12
100 lines not on this page · raw message
tools/perf/util/evsel.h +7 -3
@@ -82,11 +82,15 @@ void perf_evsel__free_id(struct perf_evsel *evsel);void perf_evsel__close_fd (struct perf_evsel *evsel,int ncpus,int nthreads);int perf_evsel__open_per_cpu (struct perf_evsel *evsel, -struct cpu_map *cpus,bool group); +struct cpu_map *cpus,bool group, +struct xyarray *group_fds);int perf_evsel__open_per_thread (struct perf_evsel *evsel, -struct thread_map *threads,bool group); +struct thread_map *threads,bool group, +struct xyarray *group_fds);int perf_evsel__open (struct perf_evsel *evsel,struct cpu_map *cpus, -struct thread_map *threads,bool group); +struct thread_map *threads,bool group, +struct xyarray *group_fds); +void perf_evsel__close (struct perf_evsel *evsel,int ncpus,int nthreads);#define perf_evsel__match (evsel, t, c) \ (evsel->attr.type == PERF_TYPE_##t && \
tools/perf/util/python.c +30 -1
@@ -623,7 +623,11 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel, cpus = ((struct pyrf_cpu_map *)pcpus)->cpus; evsel->attr.inherit = inherit; -if (perf_evsel__open (evsel, cpus, threads, group) <0 ) { +/* +* This will group just the fds for this single evsel, to group +* multiple events, use evlist.open(). +*/ +if (perf_evsel__open (evsel, cpus, threads, group,NULL ) <0 ) {PyErr_SetFromErrno (PyExc_OSError);return NULL ; }
@@ -814,6 +818,25 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,return Py_None; } +static PyObject *pyrf_evlist__open (struct pyrf_evlist *pevlist, +PyObject *args,PyObject *kwargs) +{ +struct perf_evlist *evlist = &pevlist->evlist; +int group =0 ; +static char *kwlist[] = {"group" ,NULL }; + +if (!PyArg_ParseTupleAndKeywords (args, kwargs,"|OOii" , kwlist, &group)) +return NULL ; + +if (perf_evlist__open (evlist, group) <0 ) { +PyErr_SetFromErrno (PyExc_OSError); +return NULL ; + } + +Py_INCREF (Py_None); +return Py_None; +} +static PyMethodDef pyrf_evlist__methods[] = { { .ml_name ="mmap" ,
@@ -822,6 +845,12 @@ static PyMethodDef pyrf_evlist__methods[] = { .ml_doc = PyDoc_STR("mmap the file descriptor table.") }, { + .ml_name = "open", + .ml_meth = (PyCFunction)pyrf_evlist__open, + .ml_flags = METH_VARARGS | METH_KEYWORDS, + .ml_doc =PyDoc_STR ("open the file descriptors." ) + }, + { .ml_name = "poll", .ml_meth = (PyCFunction)pyrf_evlist__poll, .ml_flags = METH_VARARGS | METH_KEYWORDS,
Signature · 1 line
1.7.1
Re: [RFC PATCH 2/2] tools/perf: Make group_fd static and move its place in __perf_evsel__open()
Quoted 40 lines · Arnaldo Carvalho de Melo
Em Mon, Oct 24, 2011 at 12:03:28PM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 32 lines
Em Mon, Oct 24, 2011 at 06:57:00PM +0800, Deng-Cheng Zhu escreveu:
Quoted 18 lines
__perf_evsel__open()is called per event, it does not work for all the grouped events at one time. So, currentlygroup_fdwill alway be -1 for the events in a group. This patch fixes it.Signed-off-by Deng-Cheng Zhu<[email protected]>Cc Peter Zijlstra<[email protected]>Cc Paul Mackerras<[email protected]>Cc Ingo Molnar<[email protected]>Cc Arnaldo Carvalho de Melo<[email protected]>--- tools/perf/util/evsel.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)tools/perf/util/evsel.c +0
-0tools/perf/util/evsel.c static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, · line 226
Quoted 10 lines
tools/perf/util/evsel.c +1
-2@@ -219,9 +219,8 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, }for (cpu =0 ; cpu< cpus->nr; cpu++) { -int group_fd =-1 ; -for (thread =0 ; thread< threads->nr; thread++) { +static int group_fd =-1 ;if (!evsel->cgrp) pid = threads->map[thread];Lets not do it that way, using statics for this is humm, ugly, IMHO.
Quoted 4 lines
Just pass an integer pointer that is a member of
perf_evlist, I'll work on a patch now.Thanks for reporting the bug tho!
Can you try this patch?
Quoted 8 lines
I tested it with:
[root@emilia ~]# perf top -e cycles -e instructions --group
and
[root@emilia ~]# perf record -e cycles -e instructions --group -a sleep 2
Your patch does fix the group fd issue. But to get event grouping workable, the event state fix is still needed. Please see the discussion
here: http://www.spinics.net/lists/mips/msg42190.html
With _only_ your patch applied, I tested with the following commands on MIPS 74K (4 counters available in total):
perf stat -g -e L1-dcache-load-misses,cycles,LLC-load-misses,iTLB-loads,instructions find / >/dev/null
I tried to group up to 5 events in the hope of seeing NOSPC error. But the command didn't fail and output:
Performance counter stats for 'find /':
9300823 L1-dcache-load-misses
<not counted> cycles
<not counted> LLC-load-misses
<not counted> iTLB-loads
<not counted> instructions
8.463207591 seconds time elapsed
This is due to the event state check in validate_group() filtering out the grouped events in OFF state. They are in OFF state because we are running the command with the perf tool as opposed to attaching to an existing task:
builtin-stat.c:create_perf_stat_counter():
if (target_pid == -1 && target_tid == -1) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}I suppose X86 has this issue too -- collect_events() in validate_group() won't do real work in the bottom half of the function.
Deng-Cheng
Re: [RFC PATCH 2/2] tools/perf: Make group_fd static and move its place in __perf_evsel__open()
Em Wed, Oct 26, 2011 at 02:26:03PM +0800, Deng-Cheng Zhu escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 4 lines
Em Mon, Oct 24, 2011 at 12:03:28PM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 3 lines
Em Mon, Oct 24, 2011 at 06:57:00PM +0800, Deng-Cheng Zhu escreveu:
Quoted 2 lines
__perf_evsel__open()is called per event, it does not work for all the grouped events at one time. So, currentlygroup_fdwill alway be -1 for
<SNIP>
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +1
-0+ static int group_fd = -1; if (!evsel->cgrp) pid = threads->map[thread];Lets not do it that way, using statics for this is humm, ugly, IMHO.
Quoted 8 lines
Quoted 5 lines
Can you try this patch?
I tested it with:
[root@emilia ~]# perf top -e cycles -e instructions --group
Your patch does fix the group fd issue. But to get event grouping workable, the event state fix is still needed. Please see the discussion
Can I have your "Reviewed-by:" or "Tested-by:" tag for this patch then?
Quoted 27 lines
here: http://www.spinics.net/lists/mips/msg42190.html
With _only_ your patch applied, I tested with the following commands on MIPS 74K (4 counters available in total):
perf stat -g -e L1-dcache-load-misses,cycles,LLC-load-misses,iTLB-loads,instructions find / >/dev/null
I tried to group up to 5 events in the hope of seeing NOSPC error. But the command didn't fail and output:
Performance counter stats for 'find /':
9300823 L1-dcache-load-misses
<not counted> cycles
<not counted> LLC-load-misses
<not counted> iTLB-loads
<not counted> instructions8.463207591 seconds time elapsed
This is due to the event state check in
validate_group()filtering out the grouped events in OFF state. They are in OFF state because we are running the command with the perf tool as opposed to attaching to an existing task:
Quoted 6 lines
builtin-stat.c:create_perf_stat_counter():
if (target_pid == -1 && target_tid == -1) { attr->disabled = 1; attr->enable_on_exec = 1; }
But they should be in OFF state only till the target program gets exec'ed, right?
Quoted 2 lines
I suppose X86 has this issue too --
collect_events()invalidate_group()won't do real work in the bottom half of the function.
I'm testing that now.
- Arnaldo
Re: [RFC PATCH 2/2] tools/perf: Make group_fd static and move its place in __perf_evsel__open()
Em Wed, Oct 26, 2011 at 09:18:28AM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 33 lines
Em Wed, Oct 26, 2011 at 02:26:03PM +0800, Deng-Cheng Zhu escreveu:
Quoted 25 lines
With _only_ your patch applied, I tested with the following commands on MIPS 74K (4 counters available in total):
perf stat -g -e L1-dcache-load-misses,cycles,LLC-load-misses,iTLB-loads,instructions find / >/dev/null
I tried to group up to 5 events in the hope of seeing NOSPC error. But the command didn't fail and output:
Performance counter stats for 'find /':
9300823 L1-dcache-load-misses
<not counted> cycles
<not counted> LLC-load-misses
<not counted> iTLB-loads
<not counted> instructions8.463207591 seconds time elapsed
This is due to the event state check in
validate_group()filtering out the grouped events in OFF state. They are in OFF state because we are running the command with the perf tool as opposed to attaching to an existing task:Quoted 6 lines
builtin-stat.c:create_perf_stat_counter():
if (target_pid == -1 && target_tid == -1) { attr->disabled = 1; attr->enable_on_exec = 1; }
Quoted 7 lines
But they should be in OFF state only till the target program gets exec'ed, right?
Quoted 2 lines
I suppose X86 has this issue too --
collect_events()invalidate_group()won't do real work in the bottom half of the function.I'm testing that now.
[root@emilia ~]# perf stat -g -e L1-dcache-load-misses,cycles,LLC-load-misses,iTLB-loads,instructions find / >/dev/null
Performance counter stats for 'find /':
158,807,949 L1-dcache-load-misses
<not counted> cycles
<not counted> LLC-load-misses
<not counted> iTLB-loads
<not counted> instructions
100.676645958 seconds time elapsed
[root@emilia ~]#
Yeah, reading more code...
- Arnaldo
Zhu, DengCheng
Tested-byRE: [RFC PATCH 2/2] tools/perf: Make group_fd static and move its place in __perf_evsel__open()
In reply to Arnaldo Carvalho de MeloQuoted 24 lines
________________________________________
From: Arnaldo Carvalho de Melo [[email protected]] on behalf of Arnaldo Carvalho de Melo [[email protected]]
Sent: Wednesday, October 26, 2011 7:18 PM
To: Zhu, DengCheng
Cc: [email protected]; Peter Zijlstra; Paul Mackerras; Ingo Molnar
Subject: Re: [RFC PATCH 2/2]tools/perf: Makegroup_fdstatic and move its place in__perf_evsel__open()Em Wed, Oct 26, 2011 at 02:26:03PM +0800, Deng-Cheng Zhu escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 4 lines
Em Mon, Oct 24, 2011 at 12:03:28PM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 3 lines
Em Mon, Oct 24, 2011 at 06:57:00PM +0800, Deng-Cheng Zhu escreveu:
Quoted 2 lines
__perf_evsel__open()is called per event, it does not work for all the grouped events at one time. So, currentlygroup_fdwill alway be -1 for<SNIP>
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
+ static int group_fd = -1; if (!evsel->cgrp) pid = threads->map[thread];Lets not do it that way, using statics for this is humm, ugly, IMHO.
Can you try this patch?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I tested it with:
[root@emilia ~]# perf top -e cycles -e instructions --group
Your patch does fix the group fd issue. But to get event grouping workable, the event state fix is still needed. Please see the discussion
Can I have your "Reviewed-by:" or "Tested-by:" tag for this patch then?
Yes, you may add my:
Quoted 29 lines
Quoted 29 lines
here: http://www.spinics.net/lists/mips/msg42190.html
With _only_ your patch applied, I tested with the following commands on MIPS 74K (4 counters available in total):
perf stat -g -e L1-dcache-load-misses,cycles,LLC-load-misses,iTLB-loads,instructions find / >/dev/null
I tried to group up to 5 events in the hope of seeing NOSPC error. But the command didn't fail and output:
Performance counter stats for 'find /':
9300823 L1-dcache-load-misses
<not counted> cycles
<not counted> LLC-load-misses
<not counted> iTLB-loads
<not counted> instructions8.463207591 seconds time elapsed
This is due to the event state check in
validate_group()filtering out the grouped events in OFF state. They are in OFF state because we are running the command with the perf tool as opposed to attaching to an existing task:builtin-stat.c:create_perf_stat_counter():
Quoted 8 lines
Quoted 4 lines
if (target_pid == -1 && target_tid == -1) { attr->disabled = 1; attr->enable_on_exec = 1; }But they should be in OFF state only till the target program gets exec'ed, right?
Yes, or else event timestamps won't be updated on exec. That's why I came to a new idea in one of my MIPS perf-events patches (link provided above).
Quoted 4 lines
Quoted 2 lines
I suppose X86 has this issue too --
collect_events()invalidate_group()won't do real work in the bottom half of the function.I'm testing that now.
As you can see from the test results in your another post, I think we see "not counted" because collect_events() in validate_group() does not do real work on events in OFF state. On x86 a patch may be needed in event init, but on MIPS (or ARM) I suppose the pmu and event state checks in validate_event() perhaps could be deleted...
Deng-Cheng