Messages in this thread | | | Date | Mon, 12 Mar 2012 10:52:21 -0700 | From | "Paul E. McKenney" <> | Subject | Re: [RFC PATCH 5/6] implement per-cpu&per-domain state machine call_srcu() |
| |
On Sat, Mar 10, 2012 at 11:12:29AM +0100, Peter Zijlstra wrote: > On Thu, 2012-03-08 at 11:49 -0800, Paul E. McKenney wrote: > > > > 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. > > Thing is, if they break that the whole kernel comes falling down, I > really wouldn't worry about RCU at that point. But to each their > pet-paranoia I guess ;-)
But just because I am paranoid doesn't mean that no one is after me! ;-)
I agree that the compiler guys would need to provide a chicken switch due to the huge amount of code that relies on (long)(a - b) handling overflow reasonably. But avoiding signed integer overflow is pretty straightforward. For example, I use the following in RCU:
#define UINT_CMP_GE(a, b) (UINT_MAX / 2 >= (a) - (b)) #define UINT_CMP_LT(a, b) (UINT_MAX / 2 < (a) - (b)) #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b)) #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
But yes, part of the reason for my doing this was to make conversations with the usual standards-committee suspects go more smoothly.
Thanx, Paul
| |