-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathDWSL.c
More file actions
97 lines (86 loc) · 2.05 KB
/
DWSL.c
File metadata and controls
97 lines (86 loc) · 2.05 KB
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
// SPDX-License-Identifier: MIT
/**
* Nanobenchmark: ADD
* JC. PROCESS = {ovewrite file and sync. at /test/$PROCESS}
* - TEST: journal commit
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdlib.h>
#include <assert.h>
#include "fxmark.h"
#include "util.h"
static void set_test_root(struct worker *worker, char *test_root)
{
struct fx_opt *fx_opt = fx_opt_worker(worker);
sprintf(test_root, "%s/%d", fx_opt->root, worker->id);
}
static int pre_work(struct worker *worker)
{
char *page = NULL;
struct bench *bench = worker->bench;
char test_root[PATH_MAX];
char file[PATH_MAX];
int fd, rc = 0;
/* create test root */
set_test_root(worker, test_root);
rc = mkdir_p(test_root);
if (rc) return rc;
/* create a test file */
snprintf(file, PATH_MAX, "%s/n_jnl_cmt.dat", test_root);
if ((fd = open(file, O_CREAT | O_RDWR, S_IRWXU)) == -1)
goto err_out;
/* allocate data buffer aligned with pagesize*/
if(posix_memalign((void **)&(worker->page), PAGE_SIZE, PAGE_SIZE))
goto err_out;
page = worker->page;
if (!page)
goto err_out;
/*set flag with O_DIRECT if need*/
if(bench->directio && (fcntl(fd, F_SETFL, O_DIRECT)==-1))
goto err_out;
if (write(fd, page, PAGE_SIZE) != PAGE_SIZE)
goto err_out;
out:
/* put fd to worker's private */
worker->private[0] = (uint64_t)fd;
return rc;
err_out:
bench->stop = 1;
rc = errno;
free(page);
goto out;
}
static int main_work(struct worker *worker)
{
char *page = worker->page;
struct bench *bench = worker->bench;
int fd, rc = 0;
uint64_t iter = 0;
assert(page);
/* fsync */
fd = (int)worker->private[0];
for (iter = 0; !bench->stop; ++iter) {
if (pwrite(fd, page, PAGE_SIZE, 0) != PAGE_SIZE)
goto err_out;
if (fsync(fd) == -1)
goto err_out;
}
out:
close(fd);
worker->works = (double)iter;
return rc;
err_out:
bench->stop = 1;
rc = errno;
goto out;
}
struct bench_operations n_jnl_cmt_ops = {
.pre_work = pre_work,
.main_work = main_work,
};