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.
Fixes: 4e1fd25d19
("selftests/bpf: Fix usleep() implementation")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200314002743.3782677-1-andriin@fb.com
This commit is contained in:
parent
cc9864a7aa
commit
41078907ee
@ -11,7 +11,7 @@ static void nsleep()
|
|||||||
{
|
{
|
||||||
struct timespec ts = { .tv_nsec = MY_TV_NSEC };
|
struct timespec ts = { .tv_nsec = MY_TV_NSEC };
|
||||||
|
|
||||||
(void)nanosleep(&ts, NULL);
|
(void)syscall(__NR_nanosleep, &ts, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_vmlinux(void)
|
void test_vmlinux(void)
|
||||||
|
@ -35,16 +35,12 @@ struct prog_test_def {
|
|||||||
*/
|
*/
|
||||||
int usleep(useconds_t usec)
|
int usleep(useconds_t usec)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts = {
|
||||||
|
.tv_sec = usec / 1000000,
|
||||||
|
.tv_nsec = (usec % 1000000) * 1000,
|
||||||
|
};
|
||||||
|
|
||||||
if (usec > 999999) {
|
return syscall(__NR_nanosleep, &ts, NULL);
|
||||||
ts.tv_sec = usec / 1000000;
|
|
||||||
ts.tv_nsec = usec % 1000000;
|
|
||||||
} else {
|
|
||||||
ts.tv_sec = 0;
|
|
||||||
ts.tv_nsec = usec;
|
|
||||||
}
|
|
||||||
return nanosleep(&ts, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool should_run(struct test_selector *sel, int num, const char *name)
|
static bool should_run(struct test_selector *sel, int num, const char *name)
|
||||||
|
Loading…
Reference in New Issue
Block a user