Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: Pass arg to fdarray__filter's call back function

Before this patch there's no way to pass arguments to fdarray__filter's
call back function.

This improvement will be used by 'perf record' to support unmapping ring
buffer for both main evlist and overwrite evlist. Without this patch
there's no way to track overwrite evlist from 'struct fdarray'.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1464183898-174512-10-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
258e4bfc 5a5ddeb6

+12 -9
+3 -2
tools/lib/api/fd/array.c
··· 85 85 } 86 86 87 87 int fdarray__filter(struct fdarray *fda, short revents, 88 - void (*entry_destructor)(struct fdarray *fda, int fd)) 88 + void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), 89 + void *arg) 89 90 { 90 91 int fd, nr = 0; 91 92 ··· 96 95 for (fd = 0; fd < fda->nr; ++fd) { 97 96 if (fda->entries[fd].revents & revents) { 98 97 if (entry_destructor) 99 - entry_destructor(fda, fd); 98 + entry_destructor(fda, fd, arg); 100 99 101 100 continue; 102 101 }
+2 -1
tools/lib/api/fd/array.h
··· 34 34 int fdarray__add(struct fdarray *fda, int fd, short revents); 35 35 int fdarray__poll(struct fdarray *fda, int timeout); 36 36 int fdarray__filter(struct fdarray *fda, short revents, 37 - void (*entry_destructor)(struct fdarray *fda, int fd)); 37 + void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), 38 + void *arg); 38 39 int fdarray__grow(struct fdarray *fda, int extra); 39 40 int fdarray__fprintf(struct fdarray *fda, FILE *fp); 40 41
+4 -4
tools/perf/tests/fdarray.c
··· 36 36 } 37 37 38 38 fdarray__init_revents(fda, POLLIN); 39 - nr_fds = fdarray__filter(fda, POLLHUP, NULL); 39 + nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL); 40 40 if (nr_fds != fda->nr_alloc) { 41 41 pr_debug("\nfdarray__filter()=%d != %d shouldn't have filtered anything", 42 42 nr_fds, fda->nr_alloc); ··· 44 44 } 45 45 46 46 fdarray__init_revents(fda, POLLHUP); 47 - nr_fds = fdarray__filter(fda, POLLHUP, NULL); 47 + nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL); 48 48 if (nr_fds != 0) { 49 49 pr_debug("\nfdarray__filter()=%d != %d, should have filtered all fds", 50 50 nr_fds, fda->nr_alloc); ··· 57 57 58 58 pr_debug("\nfiltering all but fda->entries[2]:"); 59 59 fdarray__fprintf_prefix(fda, "before", stderr); 60 - nr_fds = fdarray__filter(fda, POLLHUP, NULL); 60 + nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL); 61 61 fdarray__fprintf_prefix(fda, " after", stderr); 62 62 if (nr_fds != 1) { 63 63 pr_debug("\nfdarray__filter()=%d != 1, should have left just one event", nr_fds); ··· 78 78 79 79 pr_debug("\nfiltering all but (fda->entries[0], fda->entries[3]):"); 80 80 fdarray__fprintf_prefix(fda, "before", stderr); 81 - nr_fds = fdarray__filter(fda, POLLHUP, NULL); 81 + nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL); 82 82 fdarray__fprintf_prefix(fda, " after", stderr); 83 83 if (nr_fds != 2) { 84 84 pr_debug("\nfdarray__filter()=%d != 2, should have left just two events",
+3 -2
tools/perf/util/evlist.c
··· 483 483 return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN); 484 484 } 485 485 486 - static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd) 486 + static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, 487 + void *arg __maybe_unused) 487 488 { 488 489 struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd); 489 490 ··· 494 493 int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask) 495 494 { 496 495 return fdarray__filter(&evlist->pollfd, revents_and_mask, 497 - perf_evlist__munmap_filtered); 496 + perf_evlist__munmap_filtered, NULL); 498 497 } 499 498 500 499 int perf_evlist__poll(struct perf_evlist *evlist, int timeout)