| 1 | // SPDX-License-Identifier: BSD-2-Clause |
| 2 | /* |
| 3 | * Copyright (c) 2025 Intel Corporation |
| 4 | */ |
| 5 | |
| 6 | #ifndef _POINTER_CHASING_H_ |
| 7 | #define _POINTER_CHASING_H_ |
| 8 | |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | #define CACHE_LINE_SIZE 64 |
| 12 | |
| 13 | typedef union ptr_node { |
| 14 | struct { |
| 15 | union ptr_node *next; |
| 16 | int val; |
| 17 | }; |
| 18 | uint8_t bytes[64]; |
| 19 | } ptr_node; |
| 20 | |
| 21 | typedef struct ptr_chaser { |
| 22 | uint64_t buff; |
| 23 | uint64_t span; |
| 24 | void *head; |
| 25 | void (*workload)(struct ptr_chaser *); |
| 26 | } ptr_chaser_t; |
| 27 | |
| 28 | extern void __chasing_code_loop(void); |
| 29 | __asm__(".global __chasing_code_loop ;\n\t" |
| 30 | "__chasing_code_loop: ;\n\t" |
| 31 | "mov (%rax), %rax ;\n\t" |
| 32 | "test %rax, %rax ;\n\t" |
| 33 | "jne __chasing_code_loop ;\n\t" |
| 34 | "ret ;\n\t"); |
| 35 | |
| 36 | /* |
| 37 | * Inline function used to run workload. |
| 38 | * code_ptr: holds a pointer to workload bytecode |
| 39 | * %%RAX: holds a pointer to head of data set |
| 40 | */ |
| 41 | static __attribute__((always_inline)) inline void __ptr_chasing_run_workload( |
| 42 | ptr_chaser_t *ptr_chaser) |
| 43 | { |
| 44 | __asm__ __volatile__("call *%[code_ptr] ;\n\t" |
| 45 | : |
| 46 | : [code_ptr] "g"(ptr_chaser->workload), "a"(ptr_chaser->head) |
| 47 | :); |
| 48 | } |
| 49 | |
| 50 | int generate_linked_list(ptr_chaser_t *ptr_chaser, unsigned int seed); |
| 51 | union ptr_node *createLinkedList(void); |
| 52 | int ptr_chase_setup(int argc, char *argv[]); |
| 53 | void run_ptr_chasing(void); |
| 54 | |
| 55 | #endif /* _POINTER_CHASING_H_ */ |