aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-05-25 09:44:57 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-05-30 11:41:46 -0400
commit258e4bfcbdaa6d128c391e6e25f03d54dee4f226 (patch)
treeed95856af99c28a17a75a8d065365d0c5cbd7419
parent5a5ddeb6e3559675070df6b39ba32a4dd1ab4dd5 (diff)
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>
-rw-r--r--tools/lib/api/fd/array.c5
-rw-r--r--tools/lib/api/fd/array.h3
-rw-r--r--tools/perf/tests/fdarray.c8
-rw-r--r--tools/perf/util/evlist.c5
4 files changed, 12 insertions, 9 deletions
diff --git a/tools/lib/api/fd/array.c b/tools/lib/api/fd/array.c
index 0e636c4339b8..b0a035fc87b3 100644
--- a/tools/lib/api/fd/array.c
+++ b/tools/lib/api/fd/array.c
@@ -85,7 +85,8 @@ int fdarray__add(struct fdarray *fda, int fd, short revents)
85} 85}
86 86
87int fdarray__filter(struct fdarray *fda, short revents, 87int 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 int fd, nr = 0; 91 int fd, nr = 0;
91 92
@@ -95,7 +96,7 @@ int fdarray__filter(struct fdarray *fda, short revents,
95 for (fd = 0; fd < fda->nr; ++fd) { 96 for (fd = 0; fd < fda->nr; ++fd) {
96 if (fda->entries[fd].revents & revents) { 97 if (fda->entries[fd].revents & revents) {
97 if (entry_destructor) 98 if (entry_destructor)
98 entry_destructor(fda, fd); 99 entry_destructor(fda, fd, arg);
99 100
100 continue; 101 continue;
101 } 102 }
diff --git a/tools/lib/api/fd/array.h b/tools/lib/api/fd/array.h
index 45db01818f45..e87fd800fa8d 100644
--- a/tools/lib/api/fd/array.h
+++ b/tools/lib/api/fd/array.h
@@ -34,7 +34,8 @@ void fdarray__delete(struct fdarray *fda);
34int fdarray__add(struct fdarray *fda, int fd, short revents); 34int fdarray__add(struct fdarray *fda, int fd, short revents);
35int fdarray__poll(struct fdarray *fda, int timeout); 35int fdarray__poll(struct fdarray *fda, int timeout);
36int fdarray__filter(struct fdarray *fda, short revents, 36int 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);
38int fdarray__grow(struct fdarray *fda, int extra); 39int fdarray__grow(struct fdarray *fda, int extra);
39int fdarray__fprintf(struct fdarray *fda, FILE *fp); 40int fdarray__fprintf(struct fdarray *fda, FILE *fp);
40 41
diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c
index c809463edbe5..59dbd0550c51 100644
--- a/tools/perf/tests/fdarray.c
+++ b/tools/perf/tests/fdarray.c
@@ -36,7 +36,7 @@ int test__fdarray__filter(int subtest __maybe_unused)
36 } 36 }
37 37
38 fdarray__init_revents(fda, POLLIN); 38 fdarray__init_revents(fda, POLLIN);
39 nr_fds = fdarray__filter(fda, POLLHUP, NULL); 39 nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL);
40 if (nr_fds != fda->nr_alloc) { 40 if (nr_fds != fda->nr_alloc) {
41 pr_debug("\nfdarray__filter()=%d != %d shouldn't have filtered anything", 41 pr_debug("\nfdarray__filter()=%d != %d shouldn't have filtered anything",
42 nr_fds, fda->nr_alloc); 42 nr_fds, fda->nr_alloc);
@@ -44,7 +44,7 @@ int test__fdarray__filter(int subtest __maybe_unused)
44 } 44 }
45 45
46 fdarray__init_revents(fda, POLLHUP); 46 fdarray__init_revents(fda, POLLHUP);
47 nr_fds = fdarray__filter(fda, POLLHUP, NULL); 47 nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL);
48 if (nr_fds != 0) { 48 if (nr_fds != 0) {
49 pr_debug("\nfdarray__filter()=%d != %d, should have filtered all fds", 49 pr_debug("\nfdarray__filter()=%d != %d, should have filtered all fds",
50 nr_fds, fda->nr_alloc); 50 nr_fds, fda->nr_alloc);
@@ -57,7 +57,7 @@ int test__fdarray__filter(int subtest __maybe_unused)
57 57
58 pr_debug("\nfiltering all but fda->entries[2]:"); 58 pr_debug("\nfiltering all but fda->entries[2]:");
59 fdarray__fprintf_prefix(fda, "before", stderr); 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 fdarray__fprintf_prefix(fda, " after", stderr); 61 fdarray__fprintf_prefix(fda, " after", stderr);
62 if (nr_fds != 1) { 62 if (nr_fds != 1) {
63 pr_debug("\nfdarray__filter()=%d != 1, should have left just one event", nr_fds); 63 pr_debug("\nfdarray__filter()=%d != 1, should have left just one event", nr_fds);
@@ -78,7 +78,7 @@ int test__fdarray__filter(int subtest __maybe_unused)
78 78
79 pr_debug("\nfiltering all but (fda->entries[0], fda->entries[3]):"); 79 pr_debug("\nfiltering all but (fda->entries[0], fda->entries[3]):");
80 fdarray__fprintf_prefix(fda, "before", stderr); 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 fdarray__fprintf_prefix(fda, " after", stderr); 82 fdarray__fprintf_prefix(fda, " after", stderr);
83 if (nr_fds != 2) { 83 if (nr_fds != 2) {
84 pr_debug("\nfdarray__filter()=%d != 2, should have left just two events", 84 pr_debug("\nfdarray__filter()=%d != 2, should have left just two events",
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 719729ef9d7c..e0f30946ed1a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -483,7 +483,8 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
483 return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN); 483 return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
484} 484}
485 485
486static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd) 486static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
487 void *arg __maybe_unused)
487{ 488{
488 struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd); 489 struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd);
489 490
@@ -493,7 +494,7 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
493int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask) 494int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask)
494{ 495{
495 return fdarray__filter(&evlist->pollfd, revents_and_mask, 496 return fdarray__filter(&evlist->pollfd, revents_and_mask,
496 perf_evlist__munmap_filtered); 497 perf_evlist__munmap_filtered, NULL);
497} 498}
498 499
499int perf_evlist__poll(struct perf_evlist *evlist, int timeout) 500int perf_evlist__poll(struct perf_evlist *evlist, int timeout)