[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200313233535.3557677-1-andriin@fb.com>
Date: Fri, 13 Mar 2020 16:35:35 -0700
From: Andrii Nakryiko <andriin@...com>
To: <bpf@...r.kernel.org>, <netdev@...r.kernel.org>, <ast@...com>,
<daniel@...earbox.net>
CC: <andrii.nakryiko@...il.com>, <kernel-team@...com>,
Andrii Nakryiko <andriin@...com>
Subject: [PATCH bpf-next] 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.
Fixes: 4e1fd25d19e8 ("selftests/bpf: Fix usleep() implementation")
Signed-off-by: Andrii Nakryiko <andriin@...com>
---
tools/testing/selftests/bpf/test_progs.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index f85a06512541..6956d722a463 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -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,
+ };
+
+ return syscall(__NR_nanosleep, &ts, NULL);
}
static bool should_run(struct test_selector *sel, int num, const char *name)
--
2.17.1
Powered by blists - more mailing lists