GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 88.2% 15 / 0 / 17
Functions: 75.0% 3 / 0 / 4
Branches: 75.0% 3 / 0 / 4

storage/index/utils/util.h
Line Branch Exec Source
1 #pragma once
2
3 #include <cstdlib>
4 #include <stdint.h>
5
6 #define CPU_FREQ_MHZ (1994) // cat /proc/cpuinfo
7 #define CAS(_p, _u, _v) \
8 (__atomic_compare_exchange_n( \
9 _p, _u, _v, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE))
10 #define _kCacheLineSize (64)
11
12 inline constexpr uint64_t kWriteLatencyInNS = 10;
13 inline uint64_t clflushCount = 0;
14
15 static inline void CPUPause(void) { __asm__ volatile("pause" ::: "memory"); }
16
17 289856 static inline unsigned long ReadTSC(void) {
18 unsigned long var;
19 unsigned int hi, lo;
20 289856 asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
21 289856 var = ((unsigned long long int)hi << 32) | lo;
22 289856 return var;
23 }
24
25 269210 inline void mfence(void) { asm volatile("mfence" ::: "memory"); }
26
27 107556 inline void clflush(char* data, size_t len) {
28 107556 volatile char* ptr = (char*)((unsigned long)data & (~(_kCacheLineSize - 1)));
29 107556 mfence();
30
2/2
✓ Branch 0 taken 144928 times.
✓ Branch 1 taken 107556 times.
252484 for (; ptr < data + len; ptr += _kCacheLineSize) {
31 unsigned long etcs =
32 144928 ReadTSC() + (unsigned long)(kWriteLatencyInNS * CPU_FREQ_MHZ / 1000);
33 144928 asm volatile("clflush %0" : "+m"(*(volatile char*)ptr));
34
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 144928 times.
144928 while (ReadTSC() < etcs)
35 CPUPause();
36 144928 clflushCount++;
37 }
38 107556 mfence();
39 107556 }
40