lkml.org 
[lkml]   [2016]   [Jun]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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...

\
 
 \ /
  Last update: 2016-06-17 12:41    [W:0.126 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site