Skip to contentSkip to conversation

make spin_lock_prefetch a noop for UP

PATCH In review Nick Piggin 2 participants 5 messages Aug 4, 2005 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make spin_lock_prefetch a noop for UP

Is this any good?

The counter argument would be that one might prefetch a spinlock in the head of a data structure, and expect the rest of the cacheline to be in cache as well. Though in that case, maybe prefetch/prefetchw should be used instead.

Signature · 1 line
SUSE Labs, Novell Inc.

#define spin_lock_prefetch to be a noop on UP builds.

Also, make architectures that define spin_lock_prefetch to be prefetchw just use the generic spin_lock_prefetch.

include/asm-i386/processor.h +0 -2
Index: linux-2.6/include/asm-i386/processor.h
===================================================================
@@ -673,7 +673,6 @@ extern inline void prefetch(const void *
 
 #define ARCH_HAS_PREFETCH
 #define ARCH_HAS_PREFETCHW
-#define ARCH_HAS_SPINLOCK_PREFETCH
 
 /* 3dnow! prefetch to get an exclusive cache line. Useful for 
    spinlocks to avoid one state transition in the cache coherency protocol. */
@@ -684,7 +683,6 @@ extern inline void prefetchw(const void 
 			  X86_FEATURE_3DNOW,
 			  "r" (x));
 }
-#define spin_lock_prefetch(x)	prefetchw(x)
 
 extern void select_idle_routine(const struct cpuinfo_x86 *c);
 
include/asm-ia64/processor.h +0 -3
Index: linux-2.6/include/asm-ia64/processor.h
===================================================================
@@ -676,7 +676,6 @@ ia64_imva (void *addr)
 
 #define ARCH_HAS_PREFETCH
 #define ARCH_HAS_PREFETCHW
-#define ARCH_HAS_SPINLOCK_PREFETCH
 #define PREFETCH_STRIDE			L1_CACHE_BYTES
 
 static inline void
@@ -691,8 +690,6 @@ prefetchw (const void *x)
 	ia64_lfetch_excl(ia64_lfhint_none, x);
 }
 
-#define spin_lock_prefetch(x)	prefetchw(x)
-
 extern unsigned long boot_option_idle_override;
 
 #endif /* !__ASSEMBLY__ */
include/asm-ppc/processor.h +0 -3
Index: linux-2.6/include/asm-ppc/processor.h
===================================================================
@@ -179,7 +179,6 @@ void _nmask_and_or_msr(unsigned long nma
  */
 #define ARCH_HAS_PREFETCH
 #define ARCH_HAS_PREFETCHW
-#define ARCH_HAS_SPINLOCK_PREFETCH
 
 extern inline void prefetch(const void *x)
 {
@@ -191,8 +190,6 @@ extern inline void prefetchw(const void 
 	 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
 }
 
-#define spin_lock_prefetch(x)	prefetchw(x)
-
 extern int emulate_altivec(struct pt_regs *regs);
 
 #endif /* !__ASSEMBLY__ */
include/asm-ppc64/processor.h +0 -3
Index: linux-2.6/include/asm-ppc64/processor.h
===================================================================
@@ -476,7 +476,6 @@ static inline unsigned long __pack_fe01(
  */
 #define ARCH_HAS_PREFETCH
 #define ARCH_HAS_PREFETCHW
-#define ARCH_HAS_SPINLOCK_PREFETCH
 
 static inline void prefetch(const void *x)
 {
@@ -494,8 +493,6 @@ static inline void prefetchw(const void 
 	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
 }
 
-#define spin_lock_prefetch(x)	prefetchw(x)
-
 #define HAVE_ARCH_PICK_MMAP_LAYOUT
 
 static inline void ppc64_runlatch_on(void)
include/asm-sparc64/processor.h +0 -3
Index: linux-2.6/include/asm-sparc64/processor.h
===================================================================
@@ -198,7 +198,6 @@ extern unsigned long get_wchan(struct ta
  */
 #define ARCH_HAS_PREFETCH
 #define ARCH_HAS_PREFETCHW
-#define ARCH_HAS_SPINLOCK_PREFETCH
 
 static inline void prefetch(const void *x)
 {
@@ -224,8 +223,6 @@ static inline void prefetchw(const void 
 			     : "r" (x));
 }
 
-#define spin_lock_prefetch(x)	prefetchw(x)
-
 #endif /* !(__ASSEMBLY__) */
 
 #endif /* !(__ASM_SPARC64_PROCESSOR_H) */
include/asm-x86_64/processor.h +0 -4
Index: linux-2.6/include/asm-x86_64/processor.h
===================================================================
@@ -404,10 +404,6 @@ static inline void prefetchw(void *x) 
 			  "r" (x));
 } 
 
-#define ARCH_HAS_SPINLOCK_PREFETCH 1
-
-#define spin_lock_prefetch(x)  prefetchw(x)
-
 #define cpu_relax()   rep_nop()
 
 /*
include/linux/prefetch.h +4 -0
Index: linux-2.6/include/linux/prefetch.h
===================================================================
@@ -48,7 +48,11 @@ static inline void prefetchw(const void 
 #endif
 
 #ifndef ARCH_HAS_SPINLOCK_PREFETCH
+#ifdef CONFIG_SMP
 #define spin_lock_prefetch(x) prefetchw(x)
+#else
+#define spin_lock_prefetch(x)
+#endif
 #endif
 
 #ifndef PREFETCH_STRIDE
#1 lore raw
Quoted 7 lines · Nick Piggin

Is this any good?

The counter argument would be that one might prefetch a spinlock in the head of a data structure, and expect the rest of the cacheline to be in cache as well. Though in that case, maybe prefetch/prefetchw should be used instead.

Can you describe what the supposed improvement of the patch is?

-Andi

#2 lore raw
Quoted 4 lines · Andi Kleen
Quoted 2 lines · Nick Piggin

Is this any good?

Quoted 9 lines
Quoted 5 lines

The counter argument would be that one might prefetch a spinlock in the head of a data structure, and expect the rest of the cacheline to be in cache as well. Though in that case, maybe prefetch/prefetchw should be used instead.

Can you describe what the supposed improvement of the patch is?

From include/linux/prefetch.h:

"spin_lock_prefetch(x) - prefectches the spinlock *x for taking"

So this would reduce icache footprint and possibly memory traffic on UP where taking a spinlock is a noop.

Granted, there aren't many users of spin_lock_prefetch at the moment.

Signature · 3 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 
#3 lore raw
Quoted 6 lines

From include/linux/prefetch.h:

"spin_lock_prefetch(x) - prefectches the spinlock *x for taking"

So this would reduce icache footprint and possibly memory traffic on UP where taking a spinlock is a noop.

Ah you want to disable it on UP?
Ok that makes more sense. Why didn't you just say that? :)

Anyways, even on UP it might be useful on all these mutex or whatever lock is envogue these days preemptive kernels.

-Andi

#4 lore raw
Quoted 10 lines · Andi Kleen
Quoted 6 lines

From include/linux/prefetch.h:

"spin_lock_prefetch(x) - prefectches the spinlock *x for taking"

So this would reduce icache footprint and possibly memory traffic on UP where taking a spinlock is a noop.

Ah you want to disable it on UP? Ok that makes more sense. Why didn't you just say that? :)

Well I did, in a confusing kind of way ;) ... with the alternative input stuff being used here, "noop" becomes ambiguous I guess.

Quoted 3 lines

Anyways, even on UP it might be useful on all these mutex or whatever lock is envogue these days preemptive kernels.

I'm sure it would be useful. Though it is something that could be maintained out of tree.

Signature · 3 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com