prefetch.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Generic cache management functions. Everything is arch-specific,
  3. * but this header exists to make sure the defines/functions can be
  4. * used in a generic way.
  5. *
  6. * 2000-11-13 Arjan van de Ven <arjan@fenrus.demon.nl>
  7. *
  8. */
  9. #ifndef _LINUX_PREFETCH_H
  10. #define _LINUX_PREFETCH_H
  11. #include <linux/types.h>
  12. #include <asm/processor.h>
  13. #include <asm/cache.h>
  14. /*
  15. prefetch(x) attempts to pre-emptively get the memory pointed to
  16. by address "x" into the CPU L1 cache.
  17. prefetch(x) should not cause any kind of exception, prefetch(0) is
  18. specifically ok.
  19. prefetch() should be defined by the architecture, if not, the
  20. #define below provides a no-op define.
  21. There are 3 prefetch() macros:
  22. prefetch(x) - prefetches the cacheline at "x" for read
  23. prefetchw(x) - prefetches the cacheline at "x" for write
  24. spin_lock_prefetch(x) - prefetches the spinlock *x for taking
  25. there is also PREFETCH_STRIDE which is the architecure-preferred
  26. "lookahead" size for prefetching streamed operations.
  27. */
  28. #ifndef ARCH_HAS_PREFETCH
  29. #define prefetch(x) __builtin_prefetch(x)
  30. #endif
  31. #ifndef ARCH_HAS_PREFETCHW
  32. #define prefetchw(x) __builtin_prefetch(x,1)
  33. #endif
  34. #ifndef ARCH_HAS_SPINLOCK_PREFETCH
  35. #define spin_lock_prefetch(x) prefetchw(x)
  36. #endif
  37. #ifndef PREFETCH_STRIDE
  38. #define PREFETCH_STRIDE (4*L1_CACHE_BYTES)
  39. #endif
  40. static inline void prefetch_range(void *addr, size_t len)
  41. {
  42. #ifdef ARCH_HAS_PREFETCH
  43. char *cp;
  44. char *end = addr + len;
  45. for (cp = addr; cp < end; cp += PREFETCH_STRIDE)
  46. prefetch(cp);
  47. #endif
  48. }
  49. #endif