Subject: Re: [PATCH net 1/1] net: stmmac: add fsleep() in HW Rx timestamp checking loop

From: Tan Tee Min <[email-masked]>
Date: Tue, 19 Apr 2022 08:52:20 +0800

On Thu, Apr 14, 2022 at 10:42:59AM +0200, Jakub Kicinski wrote:
> On Thu, 14 Apr 2022 15:29:34 +0800 Tan Tee Min wrote:
> > > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
> > > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
> > > > @@ -279,10 +279,11 @@ static int dwmac4_wrback_get_rx_timestamp_status(void *desc, void *next_desc,
> > > >  			/* Check if timestamp is OK from context descriptor */
> > > >  			do {
> > > >  				ret = dwmac4_rx_check_timestamp(next_desc);
> > > > -				if (ret < 0)
> > > > +				if (ret <= 0)
> > > >  					goto exit;
> > > >  				i++;
> > > >  
> > > > +				fsleep(1);  
> > > 
> > > This is nutty.  Why isn't this code using proper deferral mechanisms
> > > like work or kthread?  
> > 
> > Appreciate your comment.
> > The dwmac4_wrback_get_rx_timestamp_status() is called by stmmac_rx()
> > function which is scheduled by NAPI framework.
> > Do we still need to create deferred work inside NAPI work?
> > Would you mind to explain it more in detail?
> 
> fsleep() is a big hammer, can you try cpu_relax() and bumping the max
> loop count a little?

Thanks for the suggestion!
I tried cpu_relax(), unfortunately the issue still happens when
the system is in a high-load situation.

I agree that the fsleep(1) (=1us) is a big hammer.
Thus in order to improve this, I’ve figured out a smaller delay
time that is enough for the context descriptor to be ready which
is ndelay(500) (=500ns).

Would you think this is more acceptable?