src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
10 / 10
100.0%
Branches:
2 / 2
100.0%
Functions:
3 / 3
100.0%

storage/nvm/pet_kv/persistence.h
Line Branch Exec Source
1 #pragma once
2 #include "base/base.h"
3 #include "base/log.h"
4
5 static const int kCACHELINE_SIZE = 64;
6
7 #define IF_Persistence(something) \
8 if (Persistence) { \
9 something \
10 }
11
12 namespace base {
13 class FENCE {
14 public:
15 static void mfence() { asm volatile("mfence" ::: "memory"); }
16 static void lfence() { asm volatile("lfence" ::: "memory"); }
17 171590 static void sfence() { asm volatile("sfence" ::: "memory"); }
18 };
19
20 12446984 inline void clflushopt(void* addr) {
21 12446984 return;
22 static int isClflushoptEnabled = !system("lscpu |grep clflushopt >/dev/null");
23 static int isClwbEnabled = !system("lscpu |grep clfw >/dev/null");
24 static int isClflushEnabled = !system("lscpu |grep clflush >/dev/null");
25 if (isClflushoptEnabled) {
26 asm volatile(".byte 0x66; clflush %0" : "+m"(*(volatile char*)(addr)));
27 } else if (isClwbEnabled) {
28 asm volatile(".byte 0x66; xsaveopt %0" : "+m"(*(volatile char*)(addr)));
29 } else if (isClflushEnabled) {
30 asm volatile("clflush %0" : "+m"(*(volatile char*)addr));
31 } else {
32 LOG(FATAL) << "system does't support clflush-like instrs";
33 return;
34 }
35 }
36
37 171590 inline void clflushopt_range(void* des, size_t size) {
38 171590 char* addr = reinterpret_cast<char*>(des);
39 171590 size = size + ((uint64)(addr) & (kCACHELINE_SIZE - 1));
40
2/2
✓ Branch 0 taken 12446984 times.
✓ Branch 1 taken 171590 times.
12618574 for (size_t i = 0; i < size; i += kCACHELINE_SIZE) {
41 12446984 clflushopt(addr + i);
42 }
43 171590 FENCE::sfence();
44 171590 }
45 }; // namespace base
46