Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions

From: David Laight
Date: Tue Mar 18 2025 - 18:06:17 EST


On Mon, 17 Mar 2025 17:11:58 -0700
Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:

> On Mon, Mar 17, 2025 at 08:04:32PM +0000, David Laight wrote:
> > Is the ARG() necessary just to handle the comma separated lists?
> > If so is it only actually needed if there is more than one item?
>
> No, but my preference is to require the use of the macro even for single
> constraints as it helps visually separate the lists.
>
> > Another option is to just require () and add the ARG in the expansion.
> > So with:
> > #define __asm_call(qual, alt, out, in, clobber) \
> > asm("zzz", ARG out, ARG in, ARG clobber)
> >
> > __asm_call(qual, ALT(), \
> > ([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \
> > "+d" (old__.high)), \
> > ("b" (new__.low), "c" (new__.high), "S" (&(_var))), \
> > ("memory"));
> >
> > would get expanded the same as the line below.
>
> Interesting idea, though I still prefer the self-documenting ASM_OUTPUT
> / ASM_INPUT / ASM_CLOBBER macros which are self-documenting and make it
> easier to read and visually distinguish the constraint lists.

Except that non of this really makes it easier to get out/in in the correct
order or to use the right constraints.
So are you just adding 'syntactic sugar' for no real gain?

Looking back at one of the changes:
-#define mb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "mfence", \
- X86_FEATURE_XMM2) ::: "memory", "cc")
+#define mb() alternative_io("lock addl $0,-4(%%esp)", \
+ "mfence", X86_FEATURE_XMM2, \
+ ARG(), \
+ ARG(), \
+ ARG("memory", "cc"))

is it really an improvement?

David