selftests/bpf: fix nanosleep for real this time
Subsystems (5)
PATCH v2 1/1 selftests/bpf: fix nanosleep for real this time
Amazingly, some libc implementations don't call __NR_nanosleep syscall from their nanosleep() APIs. Hammer it down with explicit syscall() call and never get back to it again. Also simplify code for timespec initialization.
I verified that nanosleep is called w/ printk and in exactly same Linux image that is used in Travis CI. So it should both sleep and call correct syscall.
v1->v2:
- math is too hard, fix usec -> nsec convertion (Martin);
- test_vmlinux has explicit nanosleep() call, convert that one as well.
--- tools/testing/selftests/bpf/prog_tests/vmlinux.c | 2 +- tools/testing/selftests/bpf/test_progs.c | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/prog_tests/vmlinux.c +1 -1
@@ -11,7 +11,7 @@ static void nsleep() {struct timespec ts = { .tv_nsec =MY_TV_NSEC }; - (void )nanosleep (&ts,NULL ); + (void )syscall (__NR_nanosleep, &ts,NULL ); }void test_vmlinux (void )
tools/testing/selftests/bpf/test_progs.c +6 -10
@@ -35,16 +35,12 @@ struct prog_test_def {*/ int usleep (useconds_t usec) { -struct timespec ts; - -if (usec >999999 ) { - ts.tv_sec = usec /1000000 ; - ts.tv_nsec = usec %1000000 ; - }else { - ts.tv_sec =0 ; - ts.tv_nsec = usec; - } -return nanosleep (&ts,NULL ); +struct timespec ts = { + .tv_sec = usec /1000000 , + .tv_nsec = (usec %1000000 ) *1000 , + }; + +return syscall (__NR_nanosleep, &ts,NULL ); }static bool should_run (struct test_selector *sel,int num,const char *name)
Signature · 1 line
2.17.1
Quoted 10 lines · Andrii Nakryiko
Amazingly, some libc implementations don't call
__NR_nanosleepsyscall from theirnanosleep()APIs. Hammer it down with explicitsyscall()call and never get back to it again. Also simplify code for timespec initialization.I verified that nanosleep is called w/ printk and in exactly same Linux image that is used in Travis CI. So it should both sleep and call correct syscall.
v1->v2:
- math is too hard, fix usec -> nsec convertion (Martin);
-test_vmlinuxhas explicitnanosleep()call, convert that one as well.
Quoted 7 lines · Andrii Nakryiko
Amazingly, some libc implementations don't call
__NR_nanosleepsyscall from theirnanosleep()APIs. Hammer it down with explicitsyscall()call and never get back to it again. Also simplify code for timespec initialization.I verified that nanosleep is called w/ printk and in exactly same Linux image that is used in Travis CI. So it should both sleep and call correct syscall.
Quoted 6 lines
v1->v2:
- math is too hard, fix usec -> nsec convertion (Martin);
-test_vmlinuxhas explicitnanosleep()call, convert that one as well.Fixes 4e1fd25d19e8 ("selftests/bpf: Fix usleep() implementation")Signed-off-by Andrii Nakryiko <[email protected]>
Applied, thanks!