-
Notifications
You must be signed in to change notification settings - Fork 1
/
MemoryController.h
62 lines (52 loc) · 1.82 KB
/
MemoryController.h
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
#ifndef MEM_CON_H
#define MEM_CON_H
#include "BitUtilities.cpp"
#include "DataCache/Cache.h"
#include "PageTable/PageTable.cpp"
#include "LookupBuffer/DTLB.cpp"
#include "ReferenceStats.h"
#include "PageFaultHandler.cpp"
#include "Trace.h"
#include "TraceStats.h"
#include "MemoryOptions.h"
#include "HardwareStats.h"
#include <cmath>
/// <summary>
/// Controller of memory management.
/// </summary>
class MemoryController {
private:
TLB *DTLB; // our TLB
Cache *DC; // our data cache
PageTable*PT; // our page table
// Statistics
int refCountMainMemory = 0; // number of references to main memory
int refCountDisk = 0; // number of references to external disk
int refCountPageTable = 0; // number of references to page table
MemoryOptions MemConfig;
// Configuration
bool useVirtualMemory; // true: use PT and TLB. False: only use DC
bool useTLB; // true: use PT,TLB,DC. False: use PT, DC
int bitCountOffset; // number of bits for offset
int bitCountVPN; // number of bits for VPN
int bitCountPFN; // number of bits for PFN
int CheckPageTable(TraceStats* traceW);
int CheckDataTLB(TraceStats* traceW);
int HandlePageFault(int VPN);
void TranslateVirtualMemory(TraceStats* traceW);
void AttachVPNandOffset(TraceStats* traceW);
int ExtractBits(int number, int k, int p);
int CalculatePhysicalAddress(int PFN, int offset);
void SetupConfigBits(MemoryOptions* MO);
public:
MemoryController();
MemoryController(MemoryOptions config);
~MemoryController();
TraceStats RunMemory(Trace trace);
HardwareStats GetPTStats();
HardwareStats GetDTLBStats();
HardwareStats GetDCStats();
MemoryOptions GetConfigOptions();
ReferenceStats GetReferenceCounts();
};
#endif