-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainmemory.cpp
86 lines (74 loc) · 2.02 KB
/
mainmemory.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
#include "mainmemory.h"
#include "main.h"
#include "cache.h"
#include <stdio.h>
#include <stdlib.h>
int PAGE_SIZE = 0;
int DRAM_L = DEFAULT_PAGE_SIZE;
//size in byte
int init_mainmemory(mainmemory* target, int dram_size, int nand_size, int writebuffer_size){
if(PAGE_SIZE){
DRAM_L = PAGE_SIZE;
}else{
PAGE_SIZE = DEFAULT_PAGE_SIZE;
}
if(flag_debug)
printf("PAGE SIZE is %d\n", PAGE_SIZE);
if(flag_fullassociative){
int dram_k = dram_size / DRAM_L;
dram_k -= writebuffer_size;
initialize_cache(&target->dram, DRAM, DRAM_L, dram_k, 1);
}else{
if(dram_size % (DRAM_L * DRAM_K)){
printf("%s fail, dram size fault\n", __func__);
return 1;
}
int dram_n = dram_size / (DRAM_L * DRAM_K);
dram_n -= DRAM_NS + DRAM_NV + writebuffer_size;
if( dram_n % DRAM_K ){
printf("%s fail, dram_n size fault\n", __func__);
return 1;
}
initialize_cache(&(target->dram), DRAM, DRAM_L, DRAM_K, dram_n, DRAM_NS, DRAM_NV);
}
target->dram.name = "DRAM";
target->dram.lower_cache = NULL;
target->dram.writebuffer_size = writebuffer_size;
target->nand.write_time = 200000;
target->nand.read_time = 25000;
target->init = 0;
return 0;
}
void free_mainmemory(mainmemory* target){
if(target->init)
return;
free_cache(&(target->dram));
}
void print_mainmemory(mainmemory* target){
if(target->init)
return;
print_cache(&target->dram);
check_nand(target);
}
int mainmemory_access(mainmemory* target, uint64_t addr, int op){
if(target->init)
return 1;
cache* c = &target->dram;
cache_access(c, addr, op);
return 0;
}
void fetch_nand(mainmemory *target, uint64_t addr, int op){
if(target->init)
return;
execution_time += target->nand.read_time;
}
void put_nand(mainmemory* target, uint64_t addr){
if(target->init || !flag_nandsize)
return;
target->nand.mem.insert(addr);
}
void check_nand(mainmemory* target){
if(target->init || !flag_nandsize)
return;
printf("%lu page, %luKB(%luMB) used\n", target->nand.mem.size(), target->nand.mem.size() * PAGE_SIZE / 1024, target->nand.mem.size() * PAGE_SIZE / 1024 / 1024);
}