Messages in this thread | | | Date | Fri, 17 Jun 2016 10:01:09 +0800 | From | Yuyang Du <> | Subject | Re: [PATCH] sched/fair: Fix cfs_rq avg tracking underflow |
| |
On Fri, Jun 17, 2016 at 11:19:48AM +0200, Peter Zijlstra wrote: > +/* > + * Unsigned subtract and clamp on underflow. > + * > + * Explicitly do a load-store to ensure the intermediate value never hits > + * memory. This allows lockless observations without ever seeing the negative > + * values. > + */ > +#define sub_positive(_ptr, _val) do { \ > + typeof(_ptr) ptr = (_ptr); \ > + typeof(*ptr) val = (_val); \ > + typeof(*ptr) res, var = READ_ONCE(*ptr); \ > + res = var - val; \ > + if (res > var) \ > + res = 0; \ > + WRITE_ONCE(*ptr, res); \ > +} while (0) > +
maybe sub_nonnegative() or sub_til_zero() ...
I wonder whether it is the if statement finally allows GCC to 'registerize' load_avg, and I almost tried it...
| |