Skip to content

Commit f3058a1

Browse files
WangNan0acmel
authored andcommitted
perf evlist: Don't poll and mmap overwritable events
There's no need to receive events from overwritable ring buffer. Instead, perf should make them run in background until some external event of interest takes place. This patch makes ignores normal events from overwrite evlists. Overwritable events must be mapped readonly and backward, so if evlist and evsel doesn't match (evsel->overwrite is true but either evlist is read/write or evlist is not backward, and vice versa), skip mapping it. Signed-off-by: Wang Nan <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: He Kuang <[email protected]> [ Split from a larger patch ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent c45628b commit f3058a1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tools/perf/util/evlist.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
462462
return 0;
463463
}
464464

465-
static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx)
465+
static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent)
466466
{
467-
int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP);
467+
int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
468468
/*
469469
* Save the idx so that when we filter out fds POLLHUP'ed we can
470470
* close the associated evlist->mmap[] entry.
@@ -480,7 +480,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
480480

481481
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
482482
{
483-
return __perf_evlist__add_pollfd(evlist, fd, -1);
483+
return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
484484
}
485485

486486
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
@@ -983,15 +983,28 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
983983
return 0;
984984
}
985985

986+
static bool
987+
perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused,
988+
struct perf_evsel *evsel)
989+
{
990+
if (evsel->overwrite)
991+
return false;
992+
return true;
993+
}
994+
986995
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
987996
struct mmap_params *mp, int cpu,
988997
int thread, int *output)
989998
{
990999
struct perf_evsel *evsel;
1000+
int revent;
9911001

9921002
evlist__for_each(evlist, evsel) {
9931003
int fd;
9941004

1005+
if (evsel->overwrite != (evlist->overwrite && evlist->backward))
1006+
continue;
1007+
9951008
if (evsel->system_wide && thread)
9961009
continue;
9971010

@@ -1008,6 +1021,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
10081021
perf_evlist__mmap_get(evlist, idx);
10091022
}
10101023

1024+
revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
1025+
10111026
/*
10121027
* The system_wide flag causes a selected event to be opened
10131028
* always without a pid. Consequently it will never get a
@@ -1016,7 +1031,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
10161031
* Therefore don't add it for polling.
10171032
*/
10181033
if (!evsel->system_wide &&
1019-
__perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
1034+
__perf_evlist__add_pollfd(evlist, fd, idx, revent) < 0) {
10201035
perf_evlist__mmap_put(evlist, idx);
10211036
return -1;
10221037
}

0 commit comments

Comments
 (0)