-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsa_pmem_miniasync.c
113 lines (92 loc) · 2.2 KB
/
dsa_pmem_miniasync.c
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
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dml/dml.h>
#include <libminiasync.h>
#include <libminiasync-dml.h>
#include <libpmem2.h>
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "usage: dsa_pmem_miniasync <file>");
exit(-1);
}
char *file = argv[1];
printf("file: %s\n", file);
int n_vals = 8;
int buf_alloc_size = sizeof(char) * n_vals;
char *buf = malloc(buf_alloc_size);
memset(buf, 111, n_vals);
struct pmem2_source *src;
struct pmem2_config *cfg;
struct pmem2_map *map;
int fd = open(file, O_RDWR | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
perror("open");
return errno;
}
int ret = ftruncate(fd, sizeof(buf));
if (ret == -1) {
perror("ftruncate");
return errno;
}
/* PMEM2 */
ret = pmem2_source_from_fd(&src, fd);
if (ret) {
pmem2_perror("pmem2_source_from_fd");
return ret;
}
ret = pmem2_config_new(&cfg);
if (ret) {
pmem2_perror("pmem2_config_new");
return ret;
}
ret = pmem2_config_set_required_store_granularity(cfg,
PMEM2_GRANULARITY_CACHE_LINE);
if (ret) {
pmem2_perror("pmem2_config_set_required_store_granularity");
return ret;
}
ret = pmem2_map_new(&map, cfg, src);
if (ret) {
pmem2_perror("pmem2_map_new");
return ret;
}
void *map_addr = pmem2_map_get_address(map);
size_t map_size = pmem2_map_get_size(map);
/* MINIASYNC */
struct runtime *r = runtime_new();
struct vdm *dml_mover = vdm_new(vdm_descriptor_dml_async());
struct vdm_memcpy_future dml_memcpy_future = vdm_memcpy(dml_mover,
map_addr, buf, buf_alloc_size, MINIASYNC_DML_F_MEM_DURABLE);
runtime_wait(r, FUTURE_AS_RUNNABLE(&dml_memcpy_future));
/* validation */
for (int i = 0; i < n_vals; i++) {
printf("dst[%d]: %d\n", i, ((char *)map_addr)[i]);
}
/* cleanup */
ret = pmem2_map_delete(&map);
if (ret) {
pmem2_perror("pmem2_map_delete");
return ret;
}
ret = pmem2_config_delete(&cfg);
if (ret) {
pmem2_perror("pmem2_config_delete");
return ret;
}
ret = pmem2_source_delete(&src);
if (ret) {
pmem2_perror("pmem2_source_delete");
return ret;
}
ret = close(fd);
if (ret == -1) {
perror("close");
return errno;
}
free(buf);
return 0;
}