[PATCH] [PPC64] No prefetch for NULL pointers

Andrew Morton akpm at osdl.org
Mon Apr 11 09:03:41 EST 2005


olof at austin.ibm.com (Olof Johansson) wrote:
>
> Hi,
> 
> 
> For prefetches of NULL (as when walking a short linked list), PPC64 will
> in some cases take a performance hit. The hardware needs to do the TLB
> walk, and said walk will always miss, which means (up to) two L2 misses
> as penalty. This seems to hurt overall performance, so for NULL pointers
> skip the prefetch alltogether.
> 

I wonder if prefetch(0) is a common thing, or if only one or two callsites
do it?

If the latter then perhaps this would be better fixed at the callsites, so
well-behaved callsites don't bear the cost of the (unneeded) test?


> 
> Index: 2.6/include/asm-ppc64/processor.h
> ===================================================================
> --- 2.6.orig/include/asm-ppc64/processor.h	2005-03-28 11:08:00.000000000 -0600
> +++ 2.6/include/asm-ppc64/processor.h	2005-03-28 11:14:34.000000000 -0600
> @@ -635,11 +635,17 @@ static inline unsigned long __pack_fe01(
>  
>  static inline void prefetch(const void *x)
>  {
> +	if (unlikely(!x))
> +		return;
> +
>  	__asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
>  }
>  
>  static inline void prefetchw(const void *x)
>  {
> +	if (unlikely(!x))
> +		return;
> +
>  	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
>  }
>  



More information about the Linuxppc64-dev mailing list