-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_monitor.cc
More file actions
142 lines (130 loc) · 2.85 KB
/
Copy pathmemory_monitor.cc
File metadata and controls
142 lines (130 loc) · 2.85 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//#ifndef _Memory_Monitor_CC
//#define _Memory_Monitor_CC
#include "memory_monitor.h"
#include "cache.h"
#include <memory.h>
#include <stdio.h>
MemoryMonitor::MemoryMonitor(char* filename)
{
/*
inisp=MEMSIZE-1;
char buff_ehdr[70];
Elf64_Ehdr* p_ehdr;
FILE* fd=fopen(filename,"rb");
fread(buff_ehdr,1,64,fd);
p_ehdr=(Elf64_Ehdr*)buff_ehdr;//pointer to elf header;
entry = p_ehdr->e_entry;// entry address
Elf64_Off prooff=p_ehdr->e_phoff;
Elf64_Half pronum=p_ehdr->e_phnum;//56
fseek(fd,prooff,SEEK_SET);
for(int i=0;i<pronum;i++)
{
char buff_phdr[60];
Elf64_Phdr* p_phdr;
fread(buff_phdr,1,56,fd);
p_phdr=(Elf64_Phdr*)buff_phdr;
if(p_phdr->p_type==PT_LOAD)
{
Elf64_Addr SegAd=p_phdr->p_vaddr;
Elf64_Off SegOff=p_phdr->p_offset;
Elf64_Xword SegSize=p_phdr->p_memsz;
fseek(fd,SegOff,SEEK_SET);
fread(simumem+SegAd,1,SegSize,fd);
}
}
fclose(fd);
*/
//printf("monitor\n");
memory = new Memory(filename);
llc = new Cache((1<<23), (1<<14), 8, 0, 1, memory);
l2 = new Cache((1<<18), (1<<9), 8, 0, 1, llc);
//llc = new Cache(256, 1, 16, 0, 1, memory);
//l2 = new Cache(256, 1, 16, 0, 1, llc);
//l1 = new Cache(256, 1, 16, 1, 0, memory);
l1 = new Cache((1<<15), (1<<6), 8, 0, 1, l2);
entry = memory->entry;
inisp = memory->inisp;
//printf("l1\n");
StorageStats s;
s.access_time = 0;
memory->SetStats(s);
llc->SetStats(s);
l2->SetStats(s);
l1->SetStats(s);
//printf("setstats1\n");
StorageLatency ml;
ml.bus_latency = 6;
ml.hit_latency = 100;
memory->SetLatency(ml);
//printf("setstats2\n");
StorageLatency ll;
ll.bus_latency = 3;
ll.hit_latency = 11;
llc->SetLatency(ll);
//printf("setstats3\n");
ll.bus_latency = 2;
ll.hit_latency = 5;
l2->SetLatency(ll);
//printf("setstats4\n");
ll.bus_latency = 1;
ll.hit_latency = 4;
l1->SetLatency(ll);
time = 0;
hitSum = 0;
request = 0;
}
MemoryMonitor::~MemoryMonitor()
{
printf("Memory Over");
delete l1, l2, llc;
delete memory;
}
void*
MemoryMonitor::Load(lint ad, int length)
{
char* loadcontent=new char[length];
//memcpy(loadcontent,simumem+ad,length);
int hit = 0;
request ++;
//int time;
//printf("load %llx\n", ad);
for(int i = 0; i < length; i++)
l1->HandleRequest(ad+i, 1, 1, loadcontent+i, hit, time);
hitSum += hit;
return loadcontent;
}
void
MemoryMonitor::Store(lint ad,int length, char*content)
{
//memcpy(simumem+ad,content,length);
int hit = 0;
request ++;
//int time;
for(int i = 0; i < length; i++)
l1->HandleRequest(ad+i, 1, 0, content+i, hit, time);
hitSum += hit;
return;
}
void
MemoryMonitor::PrintHitTime()
{
printf("Requests: %d\nHits: %d\nAccess Time: %d\n", request, hitSum, time);
//memory->PrintVisits();
}
/*
void *
Memory::Translate(lint ad)
{
//return (void*)(simumem+ad);
return 0;
}
*/
//#endif
/*
int main(int argc,char** argv)
{
Memory* MyMemory=new Memory(argv[1]);
printf("Entry Point:%x\n",MyMemory->entry);
return 0;
}
*/