Subject: Re: [PATCH] tcp_probe: avoid modulus operation and wrap fix

From: Stephen Hemminger <[email-masked]>
Date: Mon, 25 Jan 2010 08:30:06 -0800

On Sun, 24 Jan 2010 22:41:22 -0800 (PST)
David Miller <[email-masked]> wrote:

> From: Stephen Hemminger <[email-masked]>
> Date: Sun, 24 Jan 2010 21:50:01 -0800
> 
> > @@ -75,12 +75,12 @@ static struct {
> >  
> >  static inline int tcp_probe_used(void)
> >  {
> > -	return (tcp_probe.head - tcp_probe.tail) % bufsize;
> > +	return (tcp_probe.head - tcp_probe.tail) & (bufsize - 1);
> >  }
> >  
> >  static inline int tcp_probe_avail(void)
> >  {
> > -	return bufsize - tcp_probe_used();
> > +	return bufsize - tcp_probe_used() - 1;
> >  }
> >  
> >  /*
> 
> Hmmm...  When the ring is full head==tail, which means
> tcp_probe_used() returns 0.  Which would now make tcp_probe_avail()
> return "bufsize - 0 - 1".
> 
> Is that right?

Yes. in this ring; empty is head == tail, and full needs to
be tail == head - 1.

--