Re: [RFC PATCH 5/6] implement per-cpu&per-domain state machinecall_srcu()

From: Paul E. McKenney
Date: Fri Mar 09 2012 - 11:00:18 EST


On Tue, Mar 06, 2012 at 04:38:18PM +0100, Peter Zijlstra wrote:
> On Tue, 2012-03-06 at 23:17 +0800, Lai Jiangshan wrote:
> > On Tue, Mar 6, 2012 at 6:58 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > > On Tue, 2012-03-06 at 17:57 +0800, Lai Jiangshan wrote:
> > >> /*
> > >> + * 'return left < right;' but handle the overflow issues.
> > >> + * The same as 'return (long)(right - left) > 0;' but it cares more.
> > >
> > > About what? And why? We do the (long)(a - b) thing all over the kernel,
> > > why would you care more?
> >
> > @left is constants of the callers(callbacks's snapshot), @right
> > increases very slow.
> > if (long)(right - left) is a big negative, we have to wait for a long
> > time in this kinds of overflow.
> > this kinds of overflow can not happen in this safe_less_than()
>
> I'm afraid I'm being particularly dense, but what?!

I have been converting the "(long)(a - b)" stuff in RCU to use unsigned
arithmetic. The ULONG_CMP_GE() and friends in rcupdate.h are for this
purpose.

I too have used (long)(a - b) for a long time, but I saw with my own eyes
the glee in the compiler-writers' eyes when they discussed signed overflow
being undefined in the C standard. I believe that the reasons for signed
overflow being undefined are long obsolete, but better safe than sorry.

Thanx, Paul

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/