add epoll_pwait2 syscall
Subsystems (19)
v4 cover add epoll_pwait2 syscall
From: Willem de Bruijn <[email protected]>
Enable nanosecond timeouts for epoll.
Analogous to pselect and ppoll, introduce an epoll_wait syscall variant that takes a struct timespec instead of int timeout.
See patch 2 for more details.
patch 1: pre patch cleanup: convert internal epoll to timespec64 patch 2: add syscall
patch 3: wire up syscall
patch 4: selftest
Applies cleanly to next-20201120
No update to man-pages since v3, see commit
https://lore.kernel.org/patchwork/patch/1341103/
Willem de Bruijn (4):
epoll: convert internal api to timespec64
epoll: add syscall epoll_pwait2
epoll: wire up syscall epoll_pwait2 selftests/filesystems: expand epoll with epoll_pwait2
arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/eventpoll.c | 130 ++++++++++++++---- include/linux/compat.h | 6 + include/linux/syscalls.h | 5 + include/uapi/asm-generic/unistd.h | 4 +- kernel/sys_ni.c | 2 + .../filesystems/epoll/epoll_wakeup_test.c | 72 ++++++++++ 24 files changed, 210 insertions(+), 29 deletions(-)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH v4 1/4 epoll: convert internal api to timespec64
From: Willem de Bruijn <[email protected]>
Make epoll more consistent with select/poll: pass along the timeout as timespec64 pointer.
In anticipation of additional changes affecting all three polling mechanisms:
- add epoll_pwait2 syscall with timespec semantics, and share poll_select_set_timeout implementation.
- compute slack before conversion to absolute time, to save one ktime_get_ts64 call.
--- fs/eventpoll.c | 57 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 20 deletions(-)
fs/eventpoll.c +37 -20
@@ -1714,15 +1714,25 @@ static int ep_send_events(struct eventpoll *ep,return res; } -static inline struct timespec64 ep_set_mstimeout (long ms) +static struct timespec64 *ep_timeout_to_timespec (struct timespec64 *to,long ms) { -struct timespec64 now, ts = { - .tv_sec = ms /MSEC_PER_SEC , - .tv_nsec =NSEC_PER_MSEC * (ms %MSEC_PER_SEC ), - }; +struct timespec64 now; + +if (ms <0 ) +return NULL ; + +if (!ms) { + to->tv_sec =0 ; + to->tv_nsec =0 ; +return to; + } + + to->tv_sec = ms /MSEC_PER_SEC ; + to->tv_nsec =NSEC_PER_MSEC * (ms %MSEC_PER_SEC );ktime_get_ts64 (&now); -return timespec64_add_safe (now, ts); + *to =timespec64_add_safe (now, *to); +return to; }/**
@@ -1734,8 +1744,8 @@ static inline struct timespec64 ep_set_mstimeout(long ms)* stored. * @maxevents: Size (in terms of number of events) of the caller event buffer. * @timeout: Maximum timeout for the ready events fetch operation, in -* milliseconds. If the @timeout is zero, the function will not block, -* while if the @timeout is less than zero, the function will block +* timespec. If the timeout is zero, the function will not block, +* while if the @timeout ptr is NULL, the function will block * until at least one event has been retrieved (or an error * occurred). *
@@ -1743,7 +1753,7 @@ static inline struct timespec64 ep_set_mstimeout(long ms)* error code, in case of error. */ static int ep_poll (struct eventpoll *ep,struct epoll_event __user *events, -int maxevents,long timeout) +int maxevents,struct timespec64 *timeout) {int res, eavail, timed_out =0 ;u64 slack =0 ;
@@ -1752,13 +1762,11 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,lockdep_assert_irqs_enabled (); -if (timeout >0 ) { -struct timespec64 end_time =ep_set_mstimeout (timeout); - - slack =select_estimate_accuracy (&end_time); +if (timeout && (timeout->tv_sec | timeout->tv_nsec)) { + slack =select_estimate_accuracy (timeout); to = &expires; - *to =timespec64_to_ktime (end_time); - }else if (timeout ==0 ) { + *to =timespec64_to_ktime (*timeout); + }else if (timeout) {/* * Avoid the unnecessary trip to the wait queue loop, if the * caller specified a non blocking operation.
@@ -2177,7 +2185,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,* part of the user space epoll_wait(2). */ static int do_epoll_wait (int epfd,struct epoll_event __user *events, -int maxevents,int timeout) +int maxevents,struct timespec64 *to) {int error;struct fd f;
@@ -2211,7 +2219,7 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events, ep = f.file->private_data;/* Time to fish for events ... */ - error =ep_poll (ep, events, maxevents, timeout); + error =ep_poll (ep, events, maxevents, to); error_fput:fdput (f);
@@ -2221,7 +2229,10 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events, SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events, int, maxevents, int, timeout) { -return do_epoll_wait (epfd, events, maxevents, timeout); +struct timespec64 to; + +return do_epoll_wait (epfd, events, maxevents, +ep_timeout_to_timespec (&to, timeout)); }/*
@@ -2232,6 +2243,7 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events, int, maxevents, int, timeout, const sigset_t __user *, sigmask, size_t, sigsetsize) { + struct timespec64 to;int error;/*
@@ -2242,7 +2254,9 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,if (error)return error; - error =do_epoll_wait (epfd, events, maxevents, timeout); + error =do_epoll_wait (epfd, events, maxevents, +ep_timeout_to_timespec (&to, timeout)); +restore_saved_sigmask_unless (error == -EINTR );return error;
@@ -2255,6 +2269,7 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd, const compat_sigset_t __user *, sigmask, compat_size_t, sigsetsize) { + struct timespec64 to;long err;/*
@@ -2265,7 +2280,9 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,if (err)return err; - err =do_epoll_wait (epfd, events, maxevents, timeout); + err =do_epoll_wait (epfd, events, maxevents, +ep_timeout_to_timespec (&to, timeout)); +restore_saved_sigmask_unless (err == -EINTR );return err;
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH v4 2/4 epoll: add syscall epoll_pwait2
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Add syscall epoll_pwait2, an epoll_wait variant with nsec resolution that replaces int timeout with struct timespec. It is equivalent otherwise.
int epoll_pwait2(int fd, struct epoll_event *events,
int maxevents,
const struct timespec *timeout, const sigset_t *sigset);
The underlying hrtimer is already programmed with nsec resolution. pselect and ppoll also set nsec resolution timeout with timespec.
The sigset_t in epoll_pwait has a compat variant. epoll_pwait2 needs the same.
For timespec, only support this new interface on 2038 aware platforms that define __kernel_timespec_t. So no CONFIG_COMPAT_32BIT_TIME.
Changes
v4:
- on top of patch that converts eventpoll.c to pass timespec64
- split off wiring up the syscall
- fix alpha syscall number (Arnd)
v3:
- rewrite: add epoll_pwait2 syscall instead of epoll_create1 flag v2:
- cast to s64: avoid overflow on 32-bit platforms (Shuo Chen)
- minor commit message rewording
--- fs/eventpoll.c | 87 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 14 deletions(-)
fs/eventpoll.c +73 -14
@@ -2239,11 +2239,10 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,* Implement the event wait interface for the eventpoll file. It is the kernel * part of the user space epoll_pwait(2). */ -SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events, - int, maxevents, int, timeout, const sigset_t __user *, sigmask, - size_t, sigsetsize) +static int do_epoll_pwait (int epfd,struct epoll_event __user *events, +int maxevents,struct timespec64 *to, +const sigset_t __user *sigmask,size_t sigsetsize) { -struct timespec64 to;int error;/*
@@ -2254,22 +2253,48 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,if (error)return error; - error =do_epoll_wait (epfd, events, maxevents, -ep_timeout_to_timespec (&to, timeout)); + error =do_epoll_wait (epfd, events, maxevents, to);restore_saved_sigmask_unless (error == -EINTR );return error; } -#ifdef CONFIG_COMPAT -COMPAT_SYSCALL_DEFINE6 (epoll_pwait, int, epfd, - struct epoll_event __user *, events, - int, maxevents, int, timeout, - const compat_sigset_t __user *, sigmask, - compat_size_t, sigsetsize) +SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events, + int, maxevents, int, timeout, const sigset_t __user *, sigmask, + size_t, sigsetsize) {struct timespec64 to; + +return do_epoll_pwait (epfd, events, maxevents, +ep_timeout_to_timespec (&to, timeout), + sigmask, sigsetsize); +} + +SYSCALL_DEFINE6(epoll_pwait2, int, epfd, struct epoll_event __user *, events, + int, maxevents, const struct __kernel_timespec __user *, timeout, + const sigset_t __user *, sigmask, size_t, sigsetsize) +{ +struct timespec64 ts, *to =NULL ; + +if (timeout) { +if (get_timespec64 (&ts, timeout)) +return -EFAULT ; + to = &ts; +if (poll_select_set_timeout (to, ts.tv_sec, ts.tv_nsec)) +return -EINVAL ; + } + +return do_epoll_pwait (epfd, events, maxevents, to, + sigmask, sigsetsize); +} + +#ifdef CONFIG_COMPAT +static int do_compat_epoll_pwait (int epfd,struct epoll_event __user *events, +int maxevents,struct timespec64 *timeout, +const compat_sigset_t __user *sigmask, +compat_size_t sigsetsize) +{long err;/*
@@ -2280,13 +2305,47 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,if (err)return err; - err =do_epoll_wait (epfd, events, maxevents, -ep_timeout_to_timespec (&to, timeout)); + err =do_epoll_wait (epfd, events, maxevents, timeout);restore_saved_sigmask_unless (err == -EINTR );return err; } + +COMPAT_SYSCALL_DEFINE6 (epoll_pwait, int, epfd, + struct epoll_event __user *, events, + int, maxevents, int, timeout, + const compat_sigset_t __user *, sigmask, + compat_size_t, sigsetsize) +{ +struct timespec64 to; + +return do_compat_epoll_pwait (epfd, events, maxevents, +ep_timeout_to_timespec (&to, timeout), + sigmask, sigsetsize); +} + +COMPAT_SYSCALL_DEFINE6 (epoll_pwait2, int, epfd, + struct epoll_event __user *, events, + int, maxevents, + const struct __kernel_timespec __user *, timeout, + const compat_sigset_t __user *, sigmask, + compat_size_t, sigsetsize) +{ +struct timespec64 ts, *to =NULL ; + +if (timeout) { +if (get_timespec64 (&ts, timeout)) +return -EFAULT ; + to = &ts; +if (poll_select_set_timeout (to, ts.tv_sec, ts.tv_nsec)) +return -EINVAL ; + } + +return do_compat_epoll_pwait (epfd, events, maxevents, to, + sigmask, sigsetsize); +} +#endif static int __init eventpoll_init (void )
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH v4 3/4 epoll: wire up syscall epoll_pwait2
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Split off from prev patch in the series that implements the syscall.
--- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 ++ arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + include/linux/compat.h | 6 ++++++ include/linux/syscalls.h | 5 +++++ include/uapi/asm-generic/unistd.h | 4 +++- kernel/sys_ni.c | 2 ++ 22 files changed, 35 insertions(+), 2 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +1 -0
@@ -481,3 +481,4 @@ 549 common faccessat2 sys_faccessat2 550 common process_madvise sys_process_madvise 551 common watch_mount sys_watch_mount +553 common epoll_pwait2 sys_epoll_pwait2
arch/arm/tools/syscall.tbl +1 -0
@@ -455,3 +455,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
arch/arm64/include/asm/unistd.h +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 443 +#define __NR_compat_syscalls 444#endif #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +2 -0
@@ -893,6 +893,8 @@ __SYSCALL(__NR_process_madvise, sys_process_madvise) __SYSCALL(__NR_watch_mount, sys_watch_mount)#define __NR_memfd_secret 442 __SYSCALL(__NR_memfd_secret, sys_memfd_secret) +#define __NR_epoll_pwait2 443 +__SYSCALL (__NR_epoll_pwait2, sys_epoll_pwait2)/* * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +1 -0
@@ -362,3 +362,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
arch/m68k/kernel/syscalls/syscall.tbl +1 -0
@@ -441,3 +441,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
arch/microblaze/kernel/syscalls/syscall.tbl +1 -0
@@ -447,3 +447,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
arch/mips/kernel/syscalls/syscall_n32.tbl +1 -0
@@ -380,3 +380,4 @@ 439 n32 faccessat2 sys_faccessat2 440 n32 process_madvise sys_process_madvise 441 n32 watch_mount sys_watch_mount +443 n32 epoll_pwait2 sys_epoll_pwait2
arch/mips/kernel/syscalls/syscall_n64.tbl +1 -0
@@ -356,3 +356,4 @@ 439 n64 faccessat2 sys_faccessat2 440 n64 process_madvise sys_process_madvise 441 n64 watch_mount sys_watch_mount +443 n64 epoll_pwait2 sys_epoll_pwait2
arch/mips/kernel/syscalls/syscall_o32.tbl +1 -0
@@ -429,3 +429,4 @@ 439 o32 faccessat2 sys_faccessat2 440 o32 process_madvise sys_process_madvise 441 o32 watch_mount sys_watch_mount +443 o32 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2
arch/parisc/kernel/syscalls/syscall.tbl +1 -0
@@ -439,3 +439,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2
arch/powerpc/kernel/syscalls/syscall.tbl +1 -0
@@ -531,3 +531,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2
arch/s390/kernel/syscalls/syscall.tbl +1 -0
@@ -444,3 +444,4 @@ 439 common faccessat2 sys_faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2 sys_epoll_pwait2
arch/sh/kernel/syscalls/syscall.tbl +1 -0
@@ -444,3 +444,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
arch/sparc/kernel/syscalls/syscall.tbl +1 -0
@@ -487,3 +487,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -447,3 +447,4 @@ 440 i386 process_madvise sys_process_madvise 441 i386 watch_mount sys_watch_mount 442 i386 memfd_secret sys_memfd_secret +443 i386 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -364,6 +364,7 @@ 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount 442 common memfd_secret sys_memfd_secret +443 common epoll_pwait2 sys_epoll_pwait2 # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +1 -0
@@ -412,3 +412,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common watch_mount sys_watch_mount +443 common epoll_pwait2 sys_epoll_pwait2
include/linux/compat.h +6 -0
@@ -505,6 +505,12 @@ asmlinkage long compat_sys_epoll_pwait(int epfd, int maxevents, int timeout, const compat_sigset_t __user *sigmask, compat_size_t sigsetsize); +asmlinkage long compat_sys_epoll_pwait2 (int epfd, +struct epoll_event __user *events, +int maxevents, +const struct __kernel_timespec __user *timeout, +const compat_sigset_t __user *sigmask, +compat_size_t sigsetsize);/* fs/fcntl.c */ asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
include/linux/syscalls.h +5 -0
@@ -362,6 +362,11 @@ asmlinkage long sys_epoll_pwait(int epfd, struct epoll_event __user *events, int maxevents, int timeout, const sigset_t __user *sigmask, size_t sigsetsize); +asmlinkage long sys_epoll_pwait2 (int epfd,struct epoll_event __user *events, +int maxevents, +const struct __kernel_timespec __user *timeout, +const sigset_t __user *sigmask, +size_t sigsetsize);/* fs/fcntl.c */ asmlinkage long sys_dup (unsigned int fildes);
include/uapi/asm-generic/unistd.h +3 -1
@@ -865,9 +865,11 @@ __SYSCALL(__NR_watch_mount, sys_watch_mount)#define __NR_memfd_secret 442 __SYSCALL(__NR_memfd_secret, sys_memfd_secret)#endif +#define __NR_epoll_pwait2 443 +__SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2)#undef __NR_syscalls -#define __NR_syscalls 443 +#define __NR_syscalls 444/* * 32 bit systems traditionally used different
kernel/sys_ni.c +2 -0
@@ -68,6 +68,8 @@ COND_SYSCALL(epoll_create1);COND_SYSCALL (epoll_ctl);COND_SYSCALL (epoll_pwait);COND_SYSCALL_COMPAT (epoll_pwait); +COND_SYSCALL (epoll_pwait2); +COND_SYSCALL_COMPAT (epoll_pwait2);/* fs/fcntl.c */
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH v4 4/4 selftests/filesystems: expand epoll with epoll_pwait2
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Code coverage for the epoll_pwait2 syscall.
epoll62: Repeat basic test epoll1, but exercising the new syscall.
epoll63: Pass a timespec and exercise the timeout wakeup path.
Changes
v4:
- fix sys_epoll_pwait2 to take __kernel_timespec (Arnd).
- fix sys_epoll_pwait2 to have sigsetsize arg.
--- .../filesystems/epoll/epoll_wakeup_test.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+)
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c +72 -0
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 #define _GNU_SOURCE +#include <asm/unistd.h> +#include <linux/time_types.h> #include <poll.h> #include <unistd.h> #include <assert.h>
@@ -21,6 +23,19 @@ struct epoll_mtcontextpthread_t waiter; }; +#ifndef __NR_epoll_pwait2 +#define __NR_epoll_pwait2 -1 +#endif + +static inline int sys_epoll_pwait2 (int fd,struct epoll_event *events, +int maxevents, +const struct __kernel_timespec *timeout, +const sigset_t *sigset,size_t sigsetsize) +{ +return syscall (__NR_epoll_pwait2, fd, events, maxevents, timeout, + sigset, sigsetsize); +} +static void signal_handler (int signum) { }
@@ -3377,4 +3392,61 @@ TEST(epoll61)close (ctx.evfd); } +/* Equivalent to basic test epoll1, but exercising epoll_pwait2. */ +TEST (epoll62) +{ +int efd; +int sfd[2 ]; +struct epoll_event e; + +ASSERT_EQ (socketpair (AF_UNIX ,SOCK_STREAM ,0 , sfd),0 ); + + efd =epoll_create (1 ); +ASSERT_GE (efd,0 ); + + e.events =EPOLLIN ; +ASSERT_EQ (epoll_ctl (efd,EPOLL_CTL_ADD , sfd[0 ], &e),0 ); + +ASSERT_EQ (write (sfd[1 ],"w" ,1 ),1 ); + +EXPECT_EQ (sys_epoll_pwait2 (efd, &e,1 ,NULL ,NULL ,0 ),1 ); +EXPECT_EQ (sys_epoll_pwait2 (efd, &e,1 ,NULL ,NULL ,0 ),1 ); + +close (efd); +close (sfd[0 ]); +close (sfd[1 ]); +} + +/* Epoll_pwait2 basic timeout test. */ +TEST (epoll63) +{ +const int cfg_delay_ms =10 ; +unsigned long long tdiff; +struct __kernel_timespec ts; +int efd; +int sfd[2 ]; +struct epoll_event e; + +ASSERT_EQ (socketpair (AF_UNIX ,SOCK_STREAM ,0 , sfd),0 ); + + efd =epoll_create (1 ); +ASSERT_GE (efd,0 ); + + e.events =EPOLLIN ; +ASSERT_EQ (epoll_ctl (efd,EPOLL_CTL_ADD , sfd[0 ], &e),0 ); + + ts.tv_sec =0 ; + ts.tv_nsec = cfg_delay_ms *1000 *1000 ; + + tdiff =msecs (); +EXPECT_EQ (sys_epoll_pwait2 (efd, &e,1 , &ts,NULL ,0 ),0 ); + tdiff =msecs () - tdiff; + +EXPECT_GE (tdiff, cfg_delay_ms); + +close (efd); +close (sfd[0 ]); +close (sfd[1 ]); +} +TEST_HARNESS_MAIN
Signature · 1 line
2.29.2.454.gaff20da3a2-goog