prefetch.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <[email protected]>
  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. struct page;
  16. /*
  17. prefetch(x) attempts to pre-emptively get the memory pointed to
  18. by address "x" into the CPU L1 cache.
  19. prefetch(x) should not cause any kind of exception, prefetch(0) is
  20. specifically ok.
  21. prefetch() should be defined by the architecture, if not, the
  22. #define below provides a no-op define.
  23. There are 3 prefetch() macros:
  24. prefetch(x) - prefetches the cacheline at "x" for read
  25. prefetchw(x) - prefetches the cacheline at "x" for write
  26. spin_lock_prefetch(x) - prefetches the spinlock *x for taking
  27. there is also PREFETCH_STRIDE which is the architecure-preferred
  28. "lookahead" size for prefetching streamed operations.
  29. */
  30. #ifndef ARCH_HAS_PREFETCH
  31. #define prefetch(x) __builtin_prefetch(x)
  32. #endif
  33. #ifndef ARCH_HAS_PREFETCHW
  34. #define prefetchw(x) __builtin_prefetch(x,1)
  35. #endif
  36. #ifndef ARCH_HAS_SPINLOCK_PREFETCH
  37. #define spin_lock_prefetch(x) prefetchw(x)
  38. #endif
  39. #ifndef PREFETCH_STRIDE
  40. #define PREFETCH_STRIDE (4*L1_CACHE_BYTES)
  41. #endif
  42. static inline void prefetch_range(void *addr, size_t len)
  43. {
  44. #ifdef ARCH_HAS_PREFETCH
  45. char *cp;
  46. char *end = addr + len;
  47. for (cp = addr; cp < end; cp += PREFETCH_STRIDE)
  48. prefetch(cp);
  49. #endif
  50. }
  51. static inline void prefetch_page_address(struct page *page)
  52. {
  53. #if defined(WANT_PAGE_VIRTUAL) || defined(HASHED_PAGE_VIRTUAL)
  54. prefetch(page);
  55. #endif
  56. }
  57. #endif