Re: [PATCH] bug: Use xchg() to update WARN_ON_ONCE() staticvariable

From: Steven Rostedt
Date: Tue Oct 15 2013 - 16:36:08 EST


On Tue, 15 Oct 2013 13:12:59 -0700
Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:


> Also, we're now incurring an atomic op for every "call". Presumably
> these calls are rare, but not necessarily - one can envisage uses of a
> generic ONCE() which are called at high frequency. Should we avoid
> that with
>
> #define ONCE() ({
> static int state;
> int ret;
>
> if (likely(state))
> ret = 0;
> else
> ret = !xchg(&state, 1);
> ret;
> })

I was talking with Boris on IRC about having a shortcut if "state" is
already true. I argued against it, but that was just for the WARN()
operations because I rather add a LOCK xchg, then more branches to hot
paths.

But for a generic ONCE() function, I guess we would want the shortcut
as it may be used by something that gets hit all the time with a normal
kernel.

-- Steve
--
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/