-
Notifications
You must be signed in to change notification settings - Fork 0
/
CacheHierarchy.hh
78 lines (57 loc) · 2.56 KB
/
CacheHierarchy.hh
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
#pragma once
#include <iostream>
#include <memory>
#include "cache.hh"
struct BundleStats {
uint64_t times_encountered { 0 }, total_ops { 0 };
};
class CacheHierarchy {
// TODO: support inclusive and exclusive caches
/* A 0-indexed list of cache levels (Ln is `levels[n-1]`) */
std::vector<std::unique_ptr<Cache>> levels;
/* The cache traffic, in bytes, between each level and the one above.
* `traffic[0]` is the total amount of data requested from this hierarchy
* `traffic[nlevels()]` is the total amount of data transferred between this hierarchy
* and main memory */
std::vector<uint64_t> traffic;
/* The scatter/gather bundles encountered, as a mapping from PC to number of separate
* ops */
std::map<uint64_t, BundleStats> bundles;
/* A counter of how many requests this hierarchy has serviced so far. Each cache level
can read this shared counter, but only the hierarchy can cause it to tick */
const std::shared_ptr<Clock> clock_;
void constuctor_common_();
public:
CacheHierarchy(const std::vector<CacheConfig>& cache_configs);
CacheHierarchy(std::istream&& config_file);
/* Parameters */
int nlevels() const;
CacheType getType(int level) const;
int getSize(int level) const;
int getLineSize(int level) const;
int getSetSize(int level) const;
/* Returns the current value shown by the clock */
uint64_t current_cycle() const;
/* Stats */
uint64_t getHits(int level) const;
uint64_t getMisses(int level) const;
uint64_t getTotalAccesses(int level) const;
uint64_t getEvictions(int level) const;
/* TODO: it may be useful to add a metric for "useful" cache traffic, counting how much
data was requested and had to be fetched, as opposed to how much was actually fetched
due to cache line restrictions */
/* Get the traffic, in bytes, between the given level and the one above */
uint64_t getTraffic(int from_level) const;
/* Get a mapping from scatter/gather PCs to number of accesses executed */
const std::map<uint64_t, BundleStats>& getBundleOps() const;
/* Returns a histogram of how long cache lines last in the given cache level before
* being evicted */
std::unique_ptr<std::map<uint64_t, uint64_t>> getLifetimes(int level) const;
/* Accesses*/
/* Run a single request through the cache hierarchy */
void touch(uint64_t address, int size = 1, bool is_write = false);
/* Run a single request through the cache hierarchy */
void touch(MemoryRequest request);
/* Run a sequence of requests through the cache hierarchy */
void touch(const std::vector<MemoryRequest>& requests);
};