提交 4e1fd25d 编写于 作者: A Andrii Nakryiko 提交者: Alexei Starovoitov

selftests/bpf: Fix usleep() implementation

nanosleep syscall expects pointer to struct timespec, not nanoseconds
directly. Current implementation fulfills its purpose of invoking nanosleep
syscall, but doesn't really provide sleeping capabilities, which can cause
flakiness for tests relying on usleep() to wait for something.

Fixes: ec12a57b822c ("selftests/bpf: Guarantee that useep() calls nanosleep() syscall")
Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200313061837.3685572-1-andriin@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
上级 1afbcd94
......@@ -35,7 +35,16 @@ struct prog_test_def {
*/
int usleep(useconds_t usec)
{
return syscall(__NR_nanosleep, usec * 1000UL);
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);
}
static bool should_run(struct test_selector *sel, int num, const char *name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册