244
==104125== Number of unnecessary flushes: 1
==104125== [0]
at 0x400868: flush (emmintrin.h:1459)
==104125==
by 0x400989: main (listing_12-33.c:64)
==104125==
Address: 0x4023000
size: 64
==104125== ERROR SUMMARY: 1 errors
To showcase Persistence Inspector, Listing 12-35 has code with a write dependency,
similar to what we did for Listing 12-11 in Listing 12-19. The extra flush occurs on line 65.
Listing 12-35. Example of writing to persistent memory with a write
dependency. The code does an extra flush for the flag
33 #include
34 #include
35 #include
36 #include
37 #include
38 #include
39
40 void flush(const void *addr, size_t len) {
41
uintptr_t flush_align = 64, uptr;
42
for (uptr = (uintptr_t)addr & ~(flush_align - 1);
43
uptr < (uintptr_t)addr + len;
44
uptr += flush_align)
45
_mm_clflush((char *)uptr);
46 }
47
48 int main(int argc, char *argv[]) {
49
int fd, *ptr, *data, *flag;
50
51
fd = open("/mnt/pmem/file", O_CREAT|O_RDWR, 0666);
52
posix_fallocate(fd, 0, sizeof(int) * 2);
53
54
ptr = (int *) mmap(NULL, sizeof(int) * 2,
55
PROT_READ | PROT_WRITE,
56
MAP_SHARED_VALIDATE | MAP_SYNC,
57
fd, 0);
Chapter 12 Debugging persistent MeMory appliCations
==104125== Number of unnecessary flushes: 1
==104125== [0]
at 0x400868: flush (emmintrin.h:1459)
==104125==
by 0x400989: main (listing_12-33.c:64)
==104125==
Address: 0x4023000
size: 64
==104125== ERROR SUMMARY: 1 errors
To showcase Persistence Inspector, Listing 12-35 has code with a write dependency,
similar to what we did for Listing 12-11 in Listing 12-19. The extra flush occurs on line 65.
Listing 12-35. Example of writing to persistent memory with a write
dependency. The code does an extra flush for the flag
33 #include
34 #include
35 #include
36 #include
37 #include
38 #include
39
40 void flush(const void *addr, size_t len) {
41
uintptr_t flush_align = 64, uptr;
42
for (uptr = (uintptr_t)addr & ~(flush_align - 1);
43
uptr < (uintptr_t)addr + len;
44
uptr += flush_align)
45
_mm_clflush((char *)uptr);
46 }
47
48 int main(int argc, char *argv[]) {
49
int fd, *ptr, *data, *flag;
50
51
fd = open("/mnt/pmem/file", O_CREAT|O_RDWR, 0666);
52
posix_fallocate(fd, 0, sizeof(int) * 2);
53
54
ptr = (int *) mmap(NULL, sizeof(int) * 2,
55
PROT_READ | PROT_WRITE,
56
MAP_SHARED_VALIDATE | MAP_SYNC,
57
fd, 0);
Chapter 12 Debugging persistent MeMory appliCations
