prefetch.h 1.5 KB

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