[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 5 May 2020 11:36:25 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org, rostedt@...dmis.org,
mhiramat@...nel.org, bristot@...hat.com, jbaron@...mai.com,
torvalds@...ux-foundation.org, tglx@...utronix.de,
mingo@...nel.org, namit@...are.com, hpa@...or.com, luto@...nel.org,
ard.biesheuvel@...aro.org, jpoimboe@...hat.com,
pbonzini@...hat.com, mathieu.desnoyers@...icios.com,
hjl.tools@...il.com, ndesaulniers@...gle.com
Subject: Re: [PATCH v4 14/18] static_call: Add static_cond_call()
HJ, Nick,
Any chance any of you can see a way to make your respective compilers
not emit utter junk for this?
On Mon, May 04, 2020 at 10:14:45PM +0200, Peter Zijlstra wrote:
> https://godbolt.org/z/SDRG2q
>
> ---
> #include <stddef.h>
>
>
> #define READ_ONCE(var) (*((volatile typeof(var) *)&(var)))
> #define WRITE_ONCE(var, val) (*((volatile typeof(var) *)&(var)) = (val))
>
> struct static_call_key {
> void *func;
> };
>
> #define DECLARE_STATIC_CALL(name, func) \
> extern struct static_call_key name; \
> extern typeof(func) __SCT__##name;
>
> #define DEFINE_STATIC_COND_CALL(name, _func) \
> DECLARE_STATIC_CALL(name, _func) \
> struct static_call_key name = { \
> .func = NULL, \
> }
>
> static void __static_call_nop(void)
> {
> }
>
> #define __static_cond_call(name) \
> ({ \
> void *func = READ_ONCE(name.func); \
> if (!func) \
> func = &__static_call_nop; \
> (typeof(__SCT__##name)*)func; \
> })
>
> #define static_cond_call(name) (void)__static_cond_call(name)
>
> static void inline static_call_update(struct static_call_key *call, void *func)
> {
> WRITE_ONCE(call->func, func);
> }
>
> volatile int _x;
>
> void bar(int x)
> {
> _x = x;
> }
>
> DEFINE_STATIC_COND_CALL(foo, bar);
>
> void ponies(int x)
> {
> static_cond_call(foo)(x);
> }
Powered by blists - more mailing lists