#define _GNU_SOURCE #include #include #include #include #include #include #include static inline uint64_t read_tscp(void) { uint64_t rax, rcx, rdx; asm volatile("rdtscp" : "=a" (rax), "=d" (rdx), "=c" (rcx)); return rax | (rdx << 32); } /* * * Latences : * N = 16 (cache L1) : ~ 4 cycles * N = 256 (cache L2) : ~ 15 cycles * N = 2048 (cache L3) : ~ 47 cycles * N = 32768 (mémoire) : * locale : ~ 148 cycles * distante un saut: ~ 264 cycles * distante deux sauts: ~ 365 cycles * */ #define NB_LOOPS 10 /* * Cache line, just a structure of 64 bytes */ struct cache_line { uint64_t val[8]; }; /* * Allocate n bytes */ struct cache_line* allocate(uint64_t n) { return 0; } /* * Prepare the buffer to perform a randomized access */ void randomize(struct cache_line* buf, uint64_t n) { } /* * Access all the nbc cache lines of the buffer buf */ uint64_t access(struct cache_line* buf, uint64_t nbc) { return 0; } /* * Pine the current thread to the core core_id */ void pine_thread(int core_id) { } /* * Bind the nbc cache lines of the buffer the numa domain node_id */ void bind_memory(struct cache_line* buf, uint64_t nbc, uint32_t node_id) { } int main(int argc, char** argv) { if(argc != 4) { fprintf(stderr, "Usage: %s k p n\n", argv[0]); fprintf(stderr, " k: number of KiB in the buffer\n"); fprintf(stderr, " p: processor number of the thread\n"); fprintf(stderr, " n: numa node of the memory\n"); return 1; } uint64_t nbb = atol(argv[1]) * 1024L; /* number of bytes to allocate */ uint64_t core_id = atol(argv[2]); /* core id on which we pine the thread */ uint64_t numa_id = atol(argv[3]); /* numa domain on which we bind the memory */ struct cache_line* buf = allocate(nbb); /* allocate the buffer of nbb bytes */ uint64_t nbc = nbb/sizeof(struct cache_line); /* compute the number of cache lines */ uint64_t r = 0; /* just a number, see TP */ pine_thread(core_id); /* pine the thread */ bind_memory(buf, nbc, numa_id); /* bind the memory */ randomize(buf, nbc); /* randomize the access to buffer */ uint64_t start = 666; /* start of experiment */ for(uint64_t i=0; i