bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: fix usleep() implementation
@ 2020-03-13  6:18 Andrii Nakryiko
  2020-03-13  6:45 ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-03-13  6:18 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko

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: Andrii Nakryiko <andriin@fb.com>
---
 tools/testing/selftests/bpf/test_progs.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 2b0bc1171c9c..b6201dd82edf 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -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)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: fix usleep() implementation
  2020-03-13  6:18 [PATCH bpf-next] selftests/bpf: fix usleep() implementation Andrii Nakryiko
@ 2020-03-13  6:45 ` Alexei Starovoitov
  2020-03-13  6:52   ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2020-03-13  6:45 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, netdev, ast, daniel, andrii.nakryiko, kernel-team

On Thu, Mar 12, 2020 at 11:18:37PM -0700, Andrii Nakryiko wrote:
> 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: Andrii Nakryiko <andriin@fb.com>
> ---
>  tools/testing/selftests/bpf/test_progs.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index 2b0bc1171c9c..b6201dd82edf 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -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);
>  }

Is this a copy-paste from somewhere?
Above 'if' looks like premature optimization.
I applied it anyway, since it fixes flakiness in test_progs -n 24.
Now pin*tp* tests are stable.

But the other one is still flaky:
server_thread:FAIL:237
Failed to accept client: Resource temporarily unavailable
#64 tcp_rtt:FAIL
Note that if I run the test alone (test_progs -n 64) it is stable.
It fails only when run as part of bigger test_progs.
test_progs -n 30-64 sporadically fails (most of the time)
test_progs -n 40-64 consistently passes
Haven't bisected further.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: fix usleep() implementation
  2020-03-13  6:45 ` Alexei Starovoitov
@ 2020-03-13  6:52   ` Andrii Nakryiko
  0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-03-13  6:52 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Andrii Nakryiko, bpf, Networking, Alexei Starovoitov,
	Daniel Borkmann, Kernel Team

On Thu, Mar 12, 2020 at 11:45 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Mar 12, 2020 at 11:18:37PM -0700, Andrii Nakryiko wrote:
> > 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: Andrii Nakryiko <andriin@fb.com>
> > ---
> >  tools/testing/selftests/bpf/test_progs.c | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> > index 2b0bc1171c9c..b6201dd82edf 100644
> > --- a/tools/testing/selftests/bpf/test_progs.c
> > +++ b/tools/testing/selftests/bpf/test_progs.c
> > @@ -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);
> >  }
>
> Is this a copy-paste from somewhere?

nope, my very own prematurely optimized implementation :)

> Above 'if' looks like premature optimization.
> I applied it anyway, since it fixes flakiness in test_progs -n 24.
> Now pin*tp* tests are stable.
>

Great, I hoped as much.

> But the other one is still flaky:
> server_thread:FAIL:237
> Failed to accept client: Resource temporarily unavailable
> #64 tcp_rtt:FAIL
> Note that if I run the test alone (test_progs -n 64) it is stable.
> It fails only when run as part of bigger test_progs.
> test_progs -n 30-64 sporadically fails (most of the time)
> test_progs -n 40-64 consistently passes
> Haven't bisected further.

Okey, I'll get to it once I'm done fixing a bunch of other problems.
Seems like tcp_rtt needs some more love, sigh... :(

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-13  6:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13  6:18 [PATCH bpf-next] selftests/bpf: fix usleep() implementation Andrii Nakryiko
2020-03-13  6:45 ` Alexei Starovoitov
2020-03-13  6:52   ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).