blob: b83a3f944f287576a5c698bdb2e05dc714713eb2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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
11#ifndef _LINUX_PREFETCH_H
12#define _LINUX_PREFETCH_H
13
14#include <linux/types.h>
15#include <asm/processor.h>
16#include <asm/cache.h>
17
Li RongQing1fa5cef2020-08-18 15:07:57 +080018struct page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20 prefetch(x) attempts to pre-emptively get the memory pointed to
21 by address "x" into the CPU L1 cache.
22 prefetch(x) should not cause any kind of exception, prefetch(0) is
23 specifically ok.
24
25 prefetch() should be defined by the architecture, if not, the
26 #define below provides a no-op define.
27
28 There are 3 prefetch() macros:
29
30 prefetch(x) - prefetches the cacheline at "x" for read
31 prefetchw(x) - prefetches the cacheline at "x" for write
Dave Jones52161842007-07-15 23:40:51 -070032 spin_lock_prefetch(x) - prefetches the spinlock *x for taking
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Lucas De Marchi25985ed2011-03-30 22:57:33 -030034 there is also PREFETCH_STRIDE which is the architecure-preferred
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 "lookahead" size for prefetching streamed operations.
36
37*/
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#ifndef ARCH_HAS_PREFETCH
Andi Kleenab483572007-10-19 20:35:04 +020040#define prefetch(x) __builtin_prefetch(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
42
43#ifndef ARCH_HAS_PREFETCHW
Andi Kleenab483572007-10-19 20:35:04 +020044#define prefetchw(x) __builtin_prefetch(x,1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#endif
46
47#ifndef ARCH_HAS_SPINLOCK_PREFETCH
48#define spin_lock_prefetch(x) prefetchw(x)
49#endif
50
51#ifndef PREFETCH_STRIDE
52#define PREFETCH_STRIDE (4*L1_CACHE_BYTES)
53#endif
54
55static inline void prefetch_range(void *addr, size_t len)
56{
57#ifdef ARCH_HAS_PREFETCH
58 char *cp;
59 char *end = addr + len;
60
61 for (cp = addr; cp < end; cp += PREFETCH_STRIDE)
62 prefetch(cp);
63#endif
64}
65
Li RongQing1fa5cef2020-08-18 15:07:57 +080066static inline void prefetch_page_address(struct page *page)
67{
68#if defined(WANT_PAGE_VIRTUAL) || defined(HASHED_PAGE_VIRTUAL)
69 prefetch(page);
70#endif
71}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#endif