Re: [PATCH -v7][RFC]: mutex: implement adaptive spinning

From: Ingo Molnar
Date: Fri Jan 09 2009 - 15:41:45 EST



* Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Fri, 9 Jan 2009, Ingo Molnar wrote:
> >
> > -static inline int constant_test_bit(int nr, const volatile unsigned long *addr)
> > +static __asm_inline int
> > +constant_test_bit(int nr, const volatile unsigned long *addr)
> > {
> > return ((1UL << (nr % BITS_PER_LONG)) &
> > (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
>
> Thios makes absolutely no sense.
>
> It's called "__always_inline", not __asm_inline.

yeah.

Note that meanwhile i also figured out why gcc got the inlining wrong
there: the 'int nr' combined with the '% BITS_PER_LONG' signed arithmetics
was too much for it to figure out at the inlining stage - it generated
IDIV instructions, etc. With forced inlining later optimization stages
managed to prove that the expression can be simplified.

The second patch below that changes 'int nr' to 'unsigned nr' solves that
problem, without the need to mark the function __always_inline.


How did i end up with __asm_inline? The thing is, i started the day under
the assumption that there's some big practical problem here. I expected to
find a lot of places in need of annotation, so i introduced hpa's
suggestion and added the __asm_inline (via the patch attached below).

I wrote 40 patches that annotated 200+ asm inline functions, and i was
fully expected to find that GCC made a mess, and i also wrote a patch to
disable CONFIG_OPTIMIZE_INLINING on those grounds.

The irony is that indeed pretty much the _only_ annotation that made a
difference was the one that isnt even an asm() inline (as you noted).

So, should we not remove CONFIG_OPTIMIZE_INLINING, then the correct one
would be to mark it __always_inline [__asm_inline is senseless there], or
the second patch below that changes the bit parameter to unsigned int.

Ingo

---
include/linux/compiler.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux/include/linux/compiler.h
===================================================================
--- linux.orig/include/linux/compiler.h
+++ linux/include/linux/compiler.h
@@ -223,7 +223,11 @@ void ftrace_likely_update(struct ftrace_
#define noinline_for_stack noinline

#ifndef __always_inline
-#define __always_inline inline
+# define __always_inline inline
+#endif
+
+#ifndef __asm_inline
+# define __asm_inline __always_inline
#endif

#endif /* __KERNEL__ */

Index: linux/arch/x86/include/asm/bitops.h
===================================================================
--- linux.orig/arch/x86/include/asm/bitops.h
+++ linux/arch/x86/include/asm/bitops.h
@@ -300,7 +300,7 @@ static inline int test_and_change_bit(in
return oldbit;
}

-static inline int constant_test_bit(int nr, const volatile unsigned long *addr)
+static int constant_test_bit(unsigned int nr, const volatile unsigned long *addr)
{
return ((1UL << (nr % BITS_PER_LONG)) &
(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
--
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/