diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-07-14 04:34:37 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-07-15 16:27:47 -0400 |
commit | 4876075b3205af992bf1012f6d6fbc03593d55b9 (patch) | |
tree | d60d7f96f09b697c6dc7dad009dec1b29df57648 /tools | |
parent | a4ea0ec4f24a721bea5447a27ad5fbcb89275bae (diff) |
perf evlist: Record mmap cookie into fdarray private field
Insetad of saving a index into fdarray entries private field, save the
corresponding 'struct perf_mmap' pointer, and release them directly
using perf_mmap__put().
Following commits introduce multiple mmap arrays to evlist. Without this
patch, perf_evlist__munmap_filtered() is unable to retrive correct
'struct perf_mmap' pointer.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: He Kuang <hekuang@huawei.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1468485287-33422-6-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/evlist.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a4137e02eab8..1462085a8618 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -30,6 +30,7 @@ | |||
30 | static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); | 30 | static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); |
31 | static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); | 31 | static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); |
32 | static void perf_mmap__munmap(struct perf_mmap *map); | 32 | static void perf_mmap__munmap(struct perf_mmap *map); |
33 | static void perf_mmap__put(struct perf_mmap *map); | ||
33 | 34 | ||
34 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 35 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
35 | #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) | 36 | #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) |
@@ -466,7 +467,8 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) | |||
466 | return 0; | 467 | return 0; |
467 | } | 468 | } |
468 | 469 | ||
469 | static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent) | 470 | static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, |
471 | struct perf_mmap *map, short revent) | ||
470 | { | 472 | { |
471 | int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP); | 473 | int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP); |
472 | /* | 474 | /* |
@@ -474,7 +476,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx | |||
474 | * close the associated evlist->mmap[] entry. | 476 | * close the associated evlist->mmap[] entry. |
475 | */ | 477 | */ |
476 | if (pos >= 0) { | 478 | if (pos >= 0) { |
477 | evlist->pollfd.priv[pos].idx = idx; | 479 | evlist->pollfd.priv[pos].ptr = map; |
478 | 480 | ||
479 | fcntl(fd, F_SETFL, O_NONBLOCK); | 481 | fcntl(fd, F_SETFL, O_NONBLOCK); |
480 | } | 482 | } |
@@ -484,15 +486,16 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx | |||
484 | 486 | ||
485 | int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) | 487 | int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) |
486 | { | 488 | { |
487 | return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN); | 489 | return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN); |
488 | } | 490 | } |
489 | 491 | ||
490 | static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, | 492 | static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, |
491 | void *arg __maybe_unused) | 493 | void *arg __maybe_unused) |
492 | { | 494 | { |
493 | struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd); | 495 | struct perf_mmap *map = fda->priv[fd].ptr; |
494 | 496 | ||
495 | perf_evlist__mmap_put(evlist, fda->priv[fd].idx); | 497 | if (map) |
498 | perf_mmap__put(map); | ||
496 | } | 499 | } |
497 | 500 | ||
498 | int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask) | 501 | int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask) |
@@ -1098,7 +1101,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, | |||
1098 | * Therefore don't add it for polling. | 1101 | * Therefore don't add it for polling. |
1099 | */ | 1102 | */ |
1100 | if (!evsel->system_wide && | 1103 | if (!evsel->system_wide && |
1101 | __perf_evlist__add_pollfd(evlist, fd, idx, revent) < 0) { | 1104 | __perf_evlist__add_pollfd(evlist, fd, &evlist->mmap[idx], revent) < 0) { |
1102 | perf_evlist__mmap_put(evlist, idx); | 1105 | perf_evlist__mmap_put(evlist, idx); |
1103 | return -1; | 1106 | return -1; |
1104 | } | 1107 | } |