vppinfra: Add macro for targeted prefetching 82/41182/2
authorNiyaz Murshed <[email protected]>
Mon, 24 Jun 2024 20:38:11 +0000 (20:38 +0000)
committerFan Zhang <[email protected]>
Wed, 17 Jul 2024 14:59:26 +0000 (14:59 +0000)
In Arm platform, targeted prefetching[1] is supported. Adding this in infra
to use it in future optimisation.

[1] https://developer.arm.com/documentation/101458/2404/Optimize/Prefetching-with---builtin-prefetch

Type: improvement
Change-Id: Id3e2a274628289707840a6b2ba4b83c5e4add60b
Signed-off-by: Niyaz Murshed <[email protected]>
src/vppinfra/cache.h

index 4229a06..13778a4 100644 (file)
 #define CLIB_PREFETCH_WRITE 1
 #define CLIB_PREFETCH_STORE 1  /* alias for write */
 
+/* locality arguments to __builtin_prefetch. */
+#define CLIB_PREFETCH_TO_STREAM 0 // NTA
+#define CLIB_PREFETCH_TO_L3    1 // T2
+#define CLIB_PREFETCH_TO_L2    2 // T1
+#define CLIB_PREFETCH_TO_L1    3 // T0
+
+#define _CLIB_TARGETED_PREFETCH(n, size, type, loc)                           \
+  if ((size) > (n) *CLIB_CACHE_PREFETCH_BYTES)                                \
+    __builtin_prefetch (_addr + (n) *CLIB_CACHE_PREFETCH_BYTES,               \
+                       CLIB_PREFETCH_##type, CLIB_PREFETCH_TO_##loc);
+
 #define _CLIB_PREFETCH(n, size, type)                                         \
   if ((size) > (n) *CLIB_CACHE_PREFETCH_BYTES)                                \
     __builtin_prefetch (_addr + (n) *CLIB_CACHE_PREFETCH_BYTES,               \
     }                                                                         \
   while (0)
 
+#define CLIB_TARGETED_PREFETCH(addr, size, type, locality)                    \
+  do                                                                          \
+    {                                                                         \
+      void *_addr = (addr);                                                   \
+                                                                              \
+      ASSERT ((size) <= 4 * CLIB_CACHE_PREFETCH_BYTES);                       \
+      _CLIB_TARGETED_PREFETCH (0, size, type, locality);                      \
+      _CLIB_TARGETED_PREFETCH (1, size, type, locality);                      \
+      _CLIB_TARGETED_PREFETCH (2, size, type, locality);                      \
+      _CLIB_TARGETED_PREFETCH (3, size, type, locality);                      \
+    }                                                                         \
+  while (0)
+
 #undef _
 
 static_always_inline void