mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 21:02:43 +01: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 <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
This commit is contained in:
1 parent
070b3b5ad7
commit
59b4412f27
2 files changed
+7
-24
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user