Skip to content

Commit 258e4bf

Browse files
WangNan0acmel
authored andcommitted
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 <[email protected]> Cc: He Kuang <[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: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5a5ddeb commit 258e4bf

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

tools/lib/api/fd/array.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ int fdarray__add(struct fdarray *fda, int fd, short revents)
8585
}
8686

8787
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)
8990
{
9091
int fd, nr = 0;
9192

@@ -95,7 +96,7 @@ int fdarray__filter(struct fdarray *fda, short revents,
9596
for (fd = 0; fd < fda->nr; ++fd) {
9697
if (fda->entries[fd].revents & revents) {
9798
if (entry_destructor)
98-
entry_destructor(fda, fd);
99+
entry_destructor(fda, fd, arg);
99100

100101
continue;
101102
}

tools/lib/api/fd/array.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ void fdarray__delete(struct fdarray *fda);
3434
int fdarray__add(struct fdarray *fda, int fd, short revents);
3535
int fdarray__poll(struct fdarray *fda, int timeout);
3636
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);
3839
int fdarray__grow(struct fdarray *fda, int extra);
3940
int fdarray__fprintf(struct fdarray *fda, FILE *fp);
4041

tools/perf/tests/fdarray.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ int test__fdarray__filter(int subtest __maybe_unused)
3636
}
3737

3838
fdarray__init_revents(fda, POLLIN);
39-
nr_fds = fdarray__filter(fda, POLLHUP, NULL);
39+
nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL);
4040
if (nr_fds != fda->nr_alloc) {
4141
pr_debug("\nfdarray__filter()=%d != %d shouldn't have filtered anything",
4242
nr_fds, fda->nr_alloc);
4343
goto out_delete;
4444
}
4545

4646
fdarray__init_revents(fda, POLLHUP);
47-
nr_fds = fdarray__filter(fda, POLLHUP, NULL);
47+
nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL);
4848
if (nr_fds != 0) {
4949
pr_debug("\nfdarray__filter()=%d != %d, should have filtered all fds",
5050
nr_fds, fda->nr_alloc);
@@ -57,7 +57,7 @@ int test__fdarray__filter(int subtest __maybe_unused)
5757

5858
pr_debug("\nfiltering all but fda->entries[2]:");
5959
fdarray__fprintf_prefix(fda, "before", stderr);
60-
nr_fds = fdarray__filter(fda, POLLHUP, NULL);
60+
nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL);
6161
fdarray__fprintf_prefix(fda, " after", stderr);
6262
if (nr_fds != 1) {
6363
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)
7878

7979
pr_debug("\nfiltering all but (fda->entries[0], fda->entries[3]):");
8080
fdarray__fprintf_prefix(fda, "before", stderr);
81-
nr_fds = fdarray__filter(fda, POLLHUP, NULL);
81+
nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL);
8282
fdarray__fprintf_prefix(fda, " after", stderr);
8383
if (nr_fds != 2) {
8484
pr_debug("\nfdarray__filter()=%d != 2, should have left just two events",

tools/perf/util/evlist.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
483483
return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
484484
}
485485

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)
487488
{
488489
struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd);
489490

@@ -493,7 +494,7 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
493494
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask)
494495
{
495496
return fdarray__filter(&evlist->pollfd, revents_and_mask,
496-
perf_evlist__munmap_filtered);
497+
perf_evlist__munmap_filtered, NULL);
497498
}
498499

499500
int perf_evlist__poll(struct perf_evlist *evlist, int timeout)

0 commit comments

Comments
 (0)