mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-25 02:09:42 +00:00
libperf: Avoid internal moving of fdarray fds
Avoid moving of fds by fdarray__filter() so fds indices returned by fdarray__add() can be used for access and processing of objects at struct pollfd *entries. Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/676844f8-55d3-c628-23db-aa163a81519e@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
070b3b5ad7
commit
59b4412f27
2 changed files with 7 additions and 24 deletions
|
@ -93,22 +93,21 @@ int fdarray__filter(struct fdarray *fda, short revents,
|
|||
return 0;
|
||||
|
||||
for (fd = 0; fd < fda->nr; ++fd) {
|
||||
if (!fda->entries[fd].events)
|
||||
continue;
|
||||
|
||||
if (fda->entries[fd].revents & revents) {
|
||||
if (entry_destructor)
|
||||
entry_destructor(fda, fd, arg);
|
||||
|
||||
fda->entries[fd].revents = fda->entries[fd].events = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fd != nr) {
|
||||
fda->entries[nr] = fda->entries[fd];
|
||||
fda->priv[nr] = fda->priv[fd];
|
||||
}
|
||||
|
||||
++nr;
|
||||
}
|
||||
|
||||
return fda->nr = nr;
|
||||
return nr;
|
||||
}
|
||||
|
||||
int fdarray__poll(struct fdarray *fda, int timeout)
|
||||
|
|
|
@ -12,6 +12,7 @@ static void fdarray__init_revents(struct fdarray *fda, short revents)
|
|||
|
||||
for (fd = 0; fd < fda->nr; ++fd) {
|
||||
fda->entries[fd].fd = fda->nr - fd;
|
||||
fda->entries[fd].events = revents;
|
||||
fda->entries[fd].revents = revents;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +30,7 @@ static int fdarray__fprintf_prefix(struct fdarray *fda, const char *prefix, FILE
|
|||
|
||||
int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_unused)
|
||||
{
|
||||
int nr_fds, expected_fd[2], fd, err = TEST_FAIL;
|
||||
int nr_fds, err = TEST_FAIL;
|
||||
struct fdarray *fda = fdarray__new(5, 5);
|
||||
|
||||
if (fda == NULL) {
|
||||
|
@ -55,7 +56,6 @@ int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_
|
|||
|
||||
fdarray__init_revents(fda, POLLHUP);
|
||||
fda->entries[2].revents = POLLIN;
|
||||
expected_fd[0] = fda->entries[2].fd;
|
||||
|
||||
pr_debug("\nfiltering all but fda->entries[2]:");
|
||||
fdarray__fprintf_prefix(fda, "before", stderr);
|
||||
|
@ -66,17 +66,9 @@ int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_
|
|||
goto out_delete;
|
||||
}
|
||||
|
||||
if (fda->entries[0].fd != expected_fd[0]) {
|
||||
pr_debug("\nfda->entries[0].fd=%d != %d\n",
|
||||
fda->entries[0].fd, expected_fd[0]);
|
||||
goto out_delete;
|
||||
}
|
||||
|
||||
fdarray__init_revents(fda, POLLHUP);
|
||||
fda->entries[0].revents = POLLIN;
|
||||
expected_fd[0] = fda->entries[0].fd;
|
||||
fda->entries[3].revents = POLLIN;
|
||||
expected_fd[1] = fda->entries[3].fd;
|
||||
|
||||
pr_debug("\nfiltering all but (fda->entries[0], fda->entries[3]):");
|
||||
fdarray__fprintf_prefix(fda, "before", stderr);
|
||||
|
@ -88,14 +80,6 @@ int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_
|
|||
goto out_delete;
|
||||
}
|
||||
|
||||
for (fd = 0; fd < 2; ++fd) {
|
||||
if (fda->entries[fd].fd != expected_fd[fd]) {
|
||||
pr_debug("\nfda->entries[%d].fd=%d != %d\n", fd,
|
||||
fda->entries[fd].fd, expected_fd[fd]);
|
||||
goto out_delete;
|
||||
}
|
||||
}
|
||||
|
||||
pr_debug("\n");
|
||||
|
||||
err = 0;
|
||||
|
|
Loading…
Reference in a new issue