-
Notifications
You must be signed in to change notification settings - Fork 1
/
pmem.h
45 lines (39 loc) · 1.06 KB
/
pmem.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
#include <x86intrin.h>
enum {noflush = 1, use_clwb = 0, use_intrinsics = 1, streaming = 1, verbose = 0};
enum {microlog_size = logsize * sizeof (struct pmblock)};
static void clflushopt(volatile void *p)
{
asm volatile("clflushopt %P0" : "+m" (*(volatile char *)p));
}
static void clwb(volatile void *p)
{
if (noflush)
return;
if (verbose)
printf("clwb %p\n", p);
if (use_clwb) {
asm volatile("clwb (%[pax])" // originally from kernel (gpl)
: [p] "+m" (*(volatile char *)p)
: [pax] "a" ((volatile char *)p));
} else
clflushopt(p);
}
static void sfence(void)
{
if (noflush)
return;
if (verbose)
printf("sfence\n");
if (use_intrinsics)
_mm_sfence();
else
asm volatile("sfence" ::: "memory");
}
static void ntstore64(cell_t *to, cell_t value)
{
_mm_stream_si64((long long int*)to, value);
}
void pmwrite(void *to, void *from, unsigned len);
void log_clear(struct pmblock log[logsize]);
void log_commit(struct pmblock log[logsize], void *data, unsigned len, unsigned *pgen);
void log_read(struct pmblock *block, struct pmblock log[logsize], unsigned i);