Commit 4876075b authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

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: default avatarWang Nan <wangnan0@huawei.com>
Acked-by: default avatarJiri 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a4ea0ec4
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);
static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx);
static void perf_mmap__munmap(struct perf_mmap *map); static void perf_mmap__munmap(struct perf_mmap *map);
static void perf_mmap__put(struct perf_mmap *map);
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
#define SID(e, x, y) xyarray__entry(e->sample_id, x, y) #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,7 +467,8 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
return 0; return 0;
} }
static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent) static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
struct perf_mmap *map, short revent)
{ {
int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP); int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
/* /*
...@@ -474,7 +476,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx ...@@ -474,7 +476,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
* close the associated evlist->mmap[] entry. * close the associated evlist->mmap[] entry.
*/ */
if (pos >= 0) { if (pos >= 0) {
evlist->pollfd.priv[pos].idx = idx; evlist->pollfd.priv[pos].ptr = map;
fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFL, O_NONBLOCK);
} }
...@@ -484,15 +486,16 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx ...@@ -484,15 +486,16 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
{ {
return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN); return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN);
} }
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
void *arg __maybe_unused) void *arg __maybe_unused)
{ {
struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd); struct perf_mmap *map = fda->priv[fd].ptr;
perf_evlist__mmap_put(evlist, fda->priv[fd].idx); if (map)
perf_mmap__put(map);
} }
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask) 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,7 +1101,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
* Therefore don't add it for polling. * Therefore don't add it for polling.
*/ */
if (!evsel->system_wide && if (!evsel->system_wide &&
__perf_evlist__add_pollfd(evlist, fd, idx, revent) < 0) { __perf_evlist__add_pollfd(evlist, fd, &evlist->mmap[idx], revent) < 0) {
perf_evlist__mmap_put(evlist, idx); perf_evlist__mmap_put(evlist, idx);
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment