prefetch.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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) - prefectches the spinlock *x for taking
  25. there is also PREFETCH_STRIDE which is the architecure-prefered
  26. "lookahead" size for prefetching streamed operations.
  27. */
  28. /*
  29. * These cannot be do{}while(0) macros. See the mental gymnastics in
  30. * the loop macro.
  31. */
  32. #ifndef ARCH_HAS_PREFETCH
  33. static inline void prefetch(const void *x) {;}
  34. #endif
  35. #ifndef ARCH_HAS_PREFETCHW
  36. static inline void prefetchw(const void *x) {;}
  37. #endif
  38. #ifndef ARCH_HAS_SPINLOCK_PREFETCH
  39. #define spin_lock_prefetch(x) prefetchw(x)
  40. #endif
  41. #ifndef PREFETCH_STRIDE
  42. #define PREFETCH_STRIDE (4*L1_CACHE_BYTES)
  43. #endif
  44. static inline void prefetch_range(void *addr, size_t len)
  45. {
  46. #ifdef ARCH_HAS_PREFETCH
  47. char *cp;
  48. char *end = addr + len;
  49. for (cp = addr; cp < end; cp += PREFETCH_STRIDE)
  50. prefetch(cp);
  51. #endif
  52. }
  53. #endif