[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160617020109.GQ8105@intel.com>
Date: Fri, 17 Jun 2016 10:01:09 +0800
From: Yuyang Du <yuyang.du@...el.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Chris Wilson <chris@...is-wilson.co.uk>,
Andrey Ryabinin <aryabinin@...tuozzo.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Mike Galbraith <efault@....de>,
Thomas Gleixner <tglx@...utronix.de>, bsegall@...gle.com,
morten.rasmussen@....com, pjt@...gle.com, steve.muckle@...aro.org,
linux-kernel@...r.kernel.org, kernel@...p.com
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...
Powered by blists - more mailing lists