forked from crazy2k/tp-arq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arqsimucache.cpp
66 lines (47 loc) · 1.55 KB
/
arqsimucache.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
#include "arqsimucache.hpp"
static std::ofstream outfile;
static Memory *front_memory;
static VOID rec_memread(VOID *ip, VOID *addr) {
front_memory->read(addr);
}
static VOID rec_memwrite(VOID * ip, VOID * addr) {
front_memory->write(addr);
}
static VOID instrument_instruction(INS ins, VOID *v) {
UINT32 memops = INS_MemoryOperandCount(ins);
for (UINT32 memop = 0; memop < memops; memop++) {
if (INS_MemoryOperandIsRead(ins, memop)) {
INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)rec_memread,
IARG_INST_PTR, IARG_MEMORYOP_EA, memop, IARG_END);
}
if (INS_MemoryOperandIsWritten(ins, memop)) {
INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
(AFUNPTR)rec_memwrite, IARG_INST_PTR, IARG_MEMORYOP_EA, memop,
IARG_END);
}
}
}
static VOID finalize(INT32 code, VOID *v) {
front_memory->output(&outfile);
outfile.close();
}
static INT32 usage() {
PIN_ERROR("This Pintool simulates a cache hierarchy\n" +
KNOB_BASE::StringKnobSummary() + "\n");
return -1;
}
int main(int argc, char *argv[])
{
if (PIN_Init(argc, argv))
return usage();
outfile.open("arqsimucache.out");
INS_AddInstrumentFunction(instrument_instruction, 0);
PIN_AddFiniFunction(finalize, 0);
RAM *ram = new RAM();
Cache *l2 = new Cache("L2", ram, 1000*1024, 2, 16);
Cache *l1 = new Cache("L1", l2, 64*1024, 2, 16);
front_memory = l1;
// start program and never return
PIN_StartProgram();
return 0;
}