Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  Generic cache management functions. Everything is arch-specific,  
0004  *  but this header exists to make sure the defines/functions can be
0005  *  used in a generic way.
0006  *
0007  *  2000-11-13  Arjan van de Ven   <arjan@fenrus.demon.nl>
0008  *
0009  */
0010 
0011 #ifndef _LINUX_PREFETCH_H
0012 #define _LINUX_PREFETCH_H
0013 
0014 #include <linux/types.h>
0015 #include <asm/processor.h>
0016 #include <asm/cache.h>
0017 
0018 struct page;
0019 /*
0020     prefetch(x) attempts to pre-emptively get the memory pointed to
0021     by address "x" into the CPU L1 cache. 
0022     prefetch(x) should not cause any kind of exception, prefetch(0) is
0023     specifically ok.
0024 
0025     prefetch() should be defined by the architecture, if not, the 
0026     #define below provides a no-op define.  
0027     
0028     There are 3 prefetch() macros:
0029     
0030     prefetch(x)     - prefetches the cacheline at "x" for read
0031     prefetchw(x)    - prefetches the cacheline at "x" for write
0032     spin_lock_prefetch(x) - prefetches the spinlock *x for taking
0033     
0034     there is also PREFETCH_STRIDE which is the architecure-preferred 
0035     "lookahead" size for prefetching streamed operations.
0036     
0037 */
0038 
0039 #ifndef ARCH_HAS_PREFETCH
0040 #define prefetch(x) __builtin_prefetch(x)
0041 #endif
0042 
0043 #ifndef ARCH_HAS_PREFETCHW
0044 #define prefetchw(x) __builtin_prefetch(x,1)
0045 #endif
0046 
0047 #ifndef ARCH_HAS_SPINLOCK_PREFETCH
0048 #define spin_lock_prefetch(x) prefetchw(x)
0049 #endif
0050 
0051 #ifndef PREFETCH_STRIDE
0052 #define PREFETCH_STRIDE (4*L1_CACHE_BYTES)
0053 #endif
0054 
0055 static inline void prefetch_range(void *addr, size_t len)
0056 {
0057 #ifdef ARCH_HAS_PREFETCH
0058     char *cp;
0059     char *end = addr + len;
0060 
0061     for (cp = addr; cp < end; cp += PREFETCH_STRIDE)
0062         prefetch(cp);
0063 #endif
0064 }
0065 
0066 static inline void prefetch_page_address(struct page *page)
0067 {
0068 #if defined(WANT_PAGE_VIRTUAL) || defined(HASHED_PAGE_VIRTUAL)
0069     prefetch(page);
0070 #endif
0071 }
0072 
0073 #endif