-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem-replay-rtmcommit.c
91 lines (73 loc) · 2.01 KB
/
mem-replay-rtmcommit.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
#include "time.h"
#include "mem.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <pthread.h>
/*#define DEBUG*/
#include "debug.h"
// Simluate every basic block containing RTM_BATCH_N memory accesses.
// Start RTM at the start of a basic block, and end it at the end.
static __thread int g_sim_bbcnt;
struct mapped_log g_commit_log;
tid_t g_next_thr;
void read_next_thr() {
tid_t *ptid = (tid_t *)read_log_entry(&g_commit_log, sizeof(tid_t));
if (!ptid) {
fprintf(stderr, "no more threads in commit order log\n");
/*exit(1);*/
return;
}
g_next_thr = *ptid;
}
void mem_init(tid_t nthr, int nobj) {
g_nobj = nobj;
if (open_mapped_log_path(LOGDIR"commit", &g_commit_log) != 0) {
DPRINTF("Can't open commit log\n");
}
read_next_thr();
}
void mem_init_thr(tid_t tid) {
g_tid = tid;
}
void mem_finish(tid_t nthr, int nobj) {
end_clock();
}
void mem_finish_thr() {
if (g_sim_bbcnt % RTM_BATCH_N != 0) {
read_next_thr();
}
}
uint32_t mem_read(tid_t tid, uint32_t *addr) {
int val;
if ((g_sim_bbcnt % RTM_BATCH_N) == 0) { // Simulate basic block begin.
while (g_next_thr != g_tid) {
sched_yield();
}
/*printf("T%d bb start\n", g_tid);*/
}
assert(g_next_thr == g_tid);
val = *addr;
if (g_sim_bbcnt % RTM_BATCH_N == RTM_BATCH_N - 1) { // Simulate basic block end.
/*printf("T%d bb end\n", g_tid);*/
read_next_thr();
}
g_sim_bbcnt++;
return val;
}
void mem_write(tid_t tid, uint32_t *addr, uint32_t val) {
if ((g_sim_bbcnt % RTM_BATCH_N) == 0) { // Simulate basic block begin.
while (g_next_thr != g_tid) {
sched_yield();
}
/*printf("T%d bb start\n", g_tid);*/
}
assert(g_next_thr == g_tid);
*addr = val;
if (g_sim_bbcnt % RTM_BATCH_N == RTM_BATCH_N - 1) { // Simulate basic block end.
/*printf("T%d bb end\n", g_tid);*/
read_next_thr();
}
g_sim_bbcnt++;
}