Add a test that ensures unregistering is reasonably quick
PATCH 1/1 Add a test that ensures unregistering is reasonably quick
There was a bug [1] in io_uring that caused a 1 second delay on shutdown due to how registered resources were cleaned up. This test exposes the bug, and verifies that it does not reoccur. While time based tests have the potential to be flaky, locally with the fix it completes in 5ms, and so I do not expect this to be a practical problem.
[1]: https://lore.kernel.org/io-uring/[email protected]/T/#u
Signed-off-by Dylan Yudaken <[email protected]>
--- test/io_uring_register.c | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
test/io_uring_register.c +46 -0
@@ -609,6 +609,50 @@ out:return 0 ; } +static size_t timeus (struct timespec t) +{ +return (size_t )t.tv_sec *1000000 + t.tv_nsec /1000 ; +} + +static int +test_unregister_speed (void ) +{ +struct timespec start, end; +struct io_uring_params p; +int fd, ret; +struct iovec iov; +size_t diff; +void *buf; + +memset (&p,0 ,sizeof (p)); + fd =new_io_uring (1 , &p); + + buf =t_malloc (pagesize); + iov.iov_base = buf; + iov.iov_len = pagesize; + + ret =__sys_io_uring_register (fd,IORING_REGISTER_BUFFERS , &iov,1 ); +if (ret) { +fprintf (stderr,"error registering buffers\n" ); + goto done; + } + +clock_gettime (CLOCK_MONOTONIC_RAW , &start); +__sys_io_uring_register (fd,IORING_UNREGISTER_BUFFERS ,0 ,0 ); +clock_gettime (CLOCK_MONOTONIC_RAW , &end); + diff =timeus (end) -timeus (start); + +/* 500ms should be enough to deregister any buffers */ + ret = diff >500000 ?-1 :0 ; + +fprintf (stderr,"took %lu us to unregister buffers: %s\n" , + diff, ret ?"FAIL" :"PASS" ); +done: +free (buf); +close (fd); +return ret; +} +int main (int argc,char **argv) {
@@ -660,6 +704,8 @@ main(int argc, char **argv)/* uring poll on the uring fd */ status |=test_poll_ringfd (); + status |=test_unregister_speed (); +if (!status)printf ("PASS\n" );else
base-commit: bbcaabf808b53ef11ad9851c6b968140fb430500
Signature · 1 line
2.30.2