-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheController.cpp
More file actions
48 lines (39 loc) · 1.48 KB
/
CacheController.cpp
File metadata and controls
48 lines (39 loc) · 1.48 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
#include <array>
#include "CacheController.h"
#include <libcachesim/ExclusiveCache.h>
CacheController::CacheController(const CacheConfig& L1_config, const CacheConfig& L2_config,
unsigned int L1_latency, unsigned int L2_latency,
unsigned int dram_latency) : hierarchy(L1_config, L2_config)
{
latencies[static_cast<int>(ExclusiveCache::ACCESS_STATUS::L1_HIT)] = L1_latency;
latencies[static_cast<int>(ExclusiveCache::ACCESS_STATUS::L1_MISS_L2_HIT)] = L2_latency;
latencies[static_cast<int>(ExclusiveCache::ACCESS_STATUS::L1_MISS_L2_MISS)] = dram_latency;
}
unsigned CacheController::access(addr_t address, unsigned tid)
{
const ExclusiveCache::ACCESS_STATUS status = hierarchy.access(address, tid);
L1_stats[tid].log_access();
switch (status)
{
case ExclusiveCache::ACCESS_STATUS::L1_HIT:
break;
case ExclusiveCache::ACCESS_STATUS::L1_MISS_L2_HIT:
L1_stats[tid].log_miss();
L2_stats[tid].log_access();
break;
case ExclusiveCache::ACCESS_STATUS::L1_MISS_L2_MISS:
L1_stats[tid].log_miss();
L2_stats[tid].log_access();
L2_stats[tid].log_miss();
break;
}
return latencies[static_cast<int>(status)];
}
std::array<CacheStats, 2> CacheController::get_L1_stats(void) const
{
return L1_stats;
}
std::array<CacheStats, 2> CacheController::get_L2_stats(void) const
{
return L2_stats;
}