Re: [PATCH net-next 1/4] selftests/net/forwarding: add slowwait functions

Paolo Abeni
2024-01-26T09:53:41Z

On Fri, 2024-01-26 at 17:22 +0800, Hangbin Liu wrote:
> On Wed, Jan 24, 2024 at 02:25:57PM +0100, Przemek Kitszel wrote:
> >
> > > + echo -n "$out"
> > > + return 0
> > > + fi
> > > +
> > > + local current_time="$(date -u +%s)"
> > > + if ((current_time - start_time > timeout)); then
> > > + echo -n "$out"
> > > + return 1
> > > + fi
> > > +
> > > + sleep 1
> >
> > I see that `sleep 1` is simplest correct impl, but it's tempting to
> > suggest exponential back-off, perhaps with saturation at 15
> >
> > (but then you will have to cap last sleep to don't exceed timeout by
> > more than 1).
>
> Do you mean sleep longer when cmd exec failed? I'm not sure if it's a good
> idea as the caller still wants to return ASAP when cmd exec succeeds.

I think exponential backoff is not needed here: we don't care about
minimizing the CPU usage overhead, and there should not be 'collision'
issues.

Instead I *think* you could use a smaller sleep, e.g.

sleep 0.1

and hopefully reduce the latency even further.

Cheers,

Paolo