-
Notifications
You must be signed in to change notification settings - Fork 0
/
flush.h
121 lines (81 loc) · 2.69 KB
/
flush.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include "statistics.h"
#ifndef __APPLE__
#include "pmdk.h"
#include <libpmem.h>
#endif
#include <memory>
#if defined(USE_CLWB)
template <typename T> void write(T *dest, const T &val) {
*dest = val;
flush_clwb_nolog(dest, sizeof(T));
}
template <typename F> void flush(const F &f, FlushKind Kind) {
f();
predrain_memory_barrier();
}
[[maybe_unused]] static void flushRange(void *Addr, size_t len, FlushKind Kind) {
flush_clwb_nolog(Addr, len);
predrain_memory_barrier();
}
template <typename T> void flushObj(const T *t, FlushKind Kind) {
flush_clwb_nolog(t, sizeof(T));
predrain_memory_barrier();
}
#elif defined(USE_CLFLUSHOPT)
template <typename T> void write(T *dest, const T &val) {
*dest = val;
flush_clflushopt_nolog(dest, sizeof(T));
}
template <typename F> void flush(const F &f, FlushKind Kind) {
f();
predrain_memory_barrier();
}
template <typename T> void flushObj(const T *t, FlushKind Kind) {
flush_clflushopt_nolog(t, sizeof(T));
predrain_memory_barrier();
}
#elif defined(USE_CLFLUSH)
template <typename T> void write(T *dest, const T &val) {
*dest = val;
flush_clflush_nolog(dest, sizeof(T));
}
template <typename F> void flush(const F &f, FlushKind Kind) { f(); }
template <typename T> void flushObj(const T *t, FlushKind Kind) {
flush_clflush_nolog(t, sizeof(T));
}
#elif defined(USE_SFENCE)
template <typename T> void write(T *dest, const T &val) { *dest = val; }
template <typename F> void flush(const F &f, FlushKind Kind) {
f();
predrain_memory_barrier();
}
template <typename T> void flushObj(const T *t, FlushKind Kind) { predrain_memory_barrier(); }
#elif defined(USE_NOFLUSH)
template <typename T> void write(T *dest, const T &val) { *dest = val; }
template <typename F> void flush(const F &f, FlushKind Kind) {
f();
}
template <typename T> void flushObj(const T *t, FlushKind Kind) { }
#elif defined(USE_PMDK)
template <typename T> void write(T *dest, const T &val) {
*dest = val;
pmem_flush(dest, sizeof(T));
}
template <typename F> void flush(const F &f, FlushKind Kind) {
f();
pmem_drain();
}
template <typename T> void flushObj(const T *t, FlushKind Kind) {
pmem_flush(t, sizeof(T));
pmem_drain();
}
#elif defined(USE_STATISTICS)
template <typename T> void write(T *dest, const T &val) { *dest = val; }
template <typename F> void flush(const F &f, FlushKind Kind) { f(); statistics->addFlush(Kind); }
template <typename T> void flushObj(const T *t, FlushKind Kind) { statistics->addFlush(Kind); }
#else
template <typename T> void write(T *dest, const T &val) { *dest = val; }
template <typename F> void flush(const F &f, FlushKind Kind) { f(); }
template <typename T> void flushObj(const T *t, FlushKind Kind) {}
#endif