-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreorder-memop.cpp
93 lines (77 loc) · 2.5 KB
/
reorder-memop.cpp
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
#include "mem.h"
#include "log.h"
#include <cassert>
#include <cstdio>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
// #define DEBUG
#include "debug.h"
typedef vector< vector<struct wait_memop> > wait_memop_all;
static long load_wait_memop_log(wait_memop_all &all, tid_t tid) {
struct mapped_log log;
open_mapped_log("memop", tid, &log);
DPRINTF("map log done, buf start %p end %p\n", log.buf, log.end);
struct wait_memop *wmlog = (struct wait_memop *)log.buf;
long cnt = 0; // cnt is the number of recorded log entries
long total = 0; // total excludes those with memop -1
while (wmlog->objid != (objid_t)-1) {
cnt++;
// No previous memop, no need to wait.
if (wmlog->memop == -1) {
goto skip;
}
// printf("%d %d %d\n", objid, version, memop);
if (wmlog->objid < 0 || wmlog->objid >= g_nobj) {
printf("ERROR: #%ld objid %d, g_nobj %d\n", cnt, wmlog->objid, g_nobj);
assert(0);
}
// if (wmlog->memop > NITER * g_nobj * 2) {
// printf("ERROR: #%ld memop %d > maximum possible %d\n", cnt, (int)wmlog->memop,
// NITER * g_nobj * 2);
// assert(0);
// }
all[wmlog->objid].push_back(*wmlog);
total++;
skip:
++wmlog;
}
unmap_log(&log);
DPRINTF("log loaded, total %ld\n", total);
return total;
}
static void write_out_memop_log(const wait_memop_all &all, long total, tid_t tid) {
char path[MAX_PATH_LEN];
logpath(path, "sorted-memop", tid);
struct wait_memop *buf = (struct wait_memop *)create_mapped_file(path, total * sizeof(struct wait_memop));
DPRINTF("Open sorted log done\n");
wait_memop_all::const_iterator objit;
for (objit = all.begin(); objit != all.end(); ++objit) {
const struct wait_memop *st = &(*objit)[0];
memcpy(buf, st, sizeof(struct wait_memop) * objit->size());
buf += objit->size();
}
}
int main(int argc, char const *argv[]) {
if (argc != 3) {
printf("Usage: reorder-memop <nobj> <tid>\n");
exit(1);
}
istringstream nobjs(argv[1]);
nobjs >> g_nobj;
int tid;
istringstream nthrs(argv[2]);
nthrs >> tid;
wait_memop_all all(g_nobj);
long total = load_wait_memop_log(all, tid);
if (total != 0)
write_out_memop_log(all, total, tid);
return 0;
}