Skip to content

Commit c4e8720

Browse files
brooniewilldeacon
authored andcommitted
kselftest/arm64: Allow epoll_wait() to return more than one result
When everything is starting up we are likely to have a lot of child processes producing output at once. This means that we can reduce overhead a bit by allowing epoll_wait() to return more than one descriptor at once, it cuts down on the number of system calls we need to do which on virtual platforms where the syscall overhead is a bit more noticable and we're likely to have a lot more children active can make a small but noticable difference. On physical platforms the relatively small number of processes being run and vastly improved speeds push the effects of this change into the noise. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 92145d8 commit c4e8720

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/testing/selftests/arm64/fp/fp-stress.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct child_data {
3939

4040
static int epoll_fd;
4141
static struct child_data *children;
42+
static struct epoll_event *evs;
43+
static int tests;
4244
static int num_children;
4345
static bool terminate;
4446

@@ -393,20 +395,20 @@ static void probe_vls(int vls[], int *vl_count, int set_vl)
393395
/* Handle any pending output without blocking */
394396
static void drain_output(bool flush)
395397
{
396-
struct epoll_event ev;
397398
int ret = 1;
399+
int i;
398400

399401
while (ret > 0) {
400-
ret = epoll_wait(epoll_fd, &ev, 1, 0);
402+
ret = epoll_wait(epoll_fd, evs, tests, 0);
401403
if (ret < 0) {
402404
if (errno == EINTR)
403405
continue;
404406
ksft_print_msg("epoll_wait() failed: %s (%d)\n",
405407
strerror(errno), errno);
406408
}
407409

408-
if (ret == 1)
409-
child_output(ev.data.ptr, ev.events, flush);
410+
for (i = 0; i < ret; i++)
411+
child_output(evs[i].data.ptr, evs[i].events, flush);
410412
}
411413
}
412414

@@ -419,12 +421,11 @@ int main(int argc, char **argv)
419421
{
420422
int ret;
421423
int timeout = 10;
422-
int cpus, tests, i, j, c;
424+
int cpus, i, j, c;
423425
int sve_vl_count, sme_vl_count, fpsimd_per_cpu;
424426
bool all_children_started = false;
425427
int seen_children;
426428
int sve_vls[MAX_VLS], sme_vls[MAX_VLS];
427-
struct epoll_event ev;
428429
struct sigaction sa;
429430

430431
while ((c = getopt_long(argc, argv, "t:", options, NULL)) != -1) {
@@ -510,6 +511,11 @@ int main(int argc, char **argv)
510511
ksft_print_msg("Failed to install SIGCHLD handler: %s (%d)\n",
511512
strerror(errno), errno);
512513

514+
evs = calloc(tests, sizeof(*evs));
515+
if (!evs)
516+
ksft_exit_fail_msg("Failed to allocated %d epoll events\n",
517+
tests);
518+
513519
for (i = 0; i < cpus; i++) {
514520
for (j = 0; j < fpsimd_per_cpu; j++)
515521
start_fpsimd(&children[num_children++], i, j);
@@ -543,7 +549,7 @@ int main(int argc, char **argv)
543549
* useful in emulation where we will both be slow and
544550
* likely to have a large set of VLs.
545551
*/
546-
ret = epoll_wait(epoll_fd, &ev, 1, 1000);
552+
ret = epoll_wait(epoll_fd, evs, tests, 1000);
547553
if (ret < 0) {
548554
if (errno == EINTR)
549555
continue;
@@ -552,8 +558,11 @@ int main(int argc, char **argv)
552558
}
553559

554560
/* Output? */
555-
if (ret == 1) {
556-
child_output(ev.data.ptr, ev.events, false);
561+
if (ret > 0) {
562+
for (i = 0; i < ret; i++) {
563+
child_output(evs[i].data.ptr, evs[i].events,
564+
false);
565+
}
557566
continue;
558567
}
559568

0 commit comments

Comments
 (0)