-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
201 lines (179 loc) · 5.07 KB
/
cache.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* Cache simulation using a functional system simulator.
*/
#ifndef AVDARK_CACHE_H
#define AVDARK_CACHE_H
#include <stdint.h>
/** Physical address representation within the cache model */
typedef uint64_t avdc_pa_t;
typedef unsigned avdc_size_t;
typedef unsigned avdc_block_size_t;
typedef unsigned avdc_index_t;
typedef unsigned avdc_assoc_t;
typedef char* avdc_replacement_t;
typedef avdc_pa_t avdc_tag_t;
/**
* Memory access type to simulate.
*/
typedef enum {
AVDC_READ = 0, /** Single read access */
AVDC_WRITE, /** Single write access */
} avdc_access_type_t;
/**
* Forward declaration of the avdc_cache_line struct which is declared
* in cache.c. The forward declaration is needed for the
* simulator configuration struct.
*/
typedef struct avdc_cache_line avdc_cache_line_t;
/**
* Cache simulator instance variables
*/
typedef struct {
/**
* Debug printing enabled?
*/
int dbg;
long count;
char* replacement;
/**
* Name to print to prepend to debug printouts, may be NULL
*/
const char *dbg_name;
/**
* A pointer to an array of cache blocks. You will need to
* change this structure, the strucutre declaration is in
* cache.c. This pointer is initialized by
* avdc_resize().
*
* HINT: You may need to change how the internal cache state
* is stored
*/
avdc_cache_line_t *lines;
int *head;
//bool *full;
/**
* Cache parameters. Use avdc_resize() update them.
*
* @{
*/
avdc_size_t size;
avdc_block_size_t block_size;
avdc_assoc_t assoc;
/** @} */
/**
* Cached internal data. These values are computed by
* avdc_resize() and used to speedup cache lookups.
*
* @{
*/
int tag_shift;
int block_size_log2;
int number_of_sets;
/** @} */
/**
* Statistics. These values are used by the test cases and the
* simulator glue code. Do not change these unless you know
* what you are doing.
*
* @{
*/
int stat_data_write;
int stat_data_write_miss;
int stat_data_read;
int stat_data_read_miss;
/** @} */
avdc_pa_t last_victim;
int last_valid;
} avdark_cache_t;
/**
* Create a new instance of the cache simulator
*
* @param size Cache size in bytes
* @param block_size Cache block size in bytes
* @param assoc Cache associativiy
*/
avdark_cache_t *avdc_new(avdc_size_t size, avdc_block_size_t block_size,
avdc_assoc_t assoc,avdc_replacement_t replacement);
/**
* Destroy an instance of the cache simulator.
*
* @param self Simulator instance
*/
void avdc_delete(avdark_cache_t *self);
/**
* Resize the cache.
*
* Initializes the cache using the new cache size parameters. This
* function also precomputes a set of values used in various functions
* used by the cache simulator.
*
* @param self Simulator instance
* @param size Cache size in bytes
* @param block_size Cache block size in bytes
* @param assoc Cache associativiy
* @return 0 on error, 1 on success
*/
int avdc_resize(avdark_cache_t *self, avdc_size_t size,
avdc_block_size_t block_size, avdc_assoc_t assoc);
/**
* Debug printing. This function works just like printf but the first
* argument must be the avdark_cache_t structure. This function only
* prints information if debug printing is enabled, this can be
* controled with the dbg-enable and dbg-disable commands (from
* python)
*
* @param self Simulator instance
* @param msg printf formated string
*/
void avdc_dbg_log(avdark_cache_t *self, const char *msg, ...)
__attribute__((format (printf, 2, 3)));
/**
* Simulate a full cache flush
*
* @param self Simulator instance
*/
void avdc_flush_cache(avdark_cache_t *self);
/**
* Execute a cache line access
*
* @param self Simulator instance
* @param pa Physical address to access
* @param type Access type
*/
int avdc_access(avdark_cache_t *self, avdc_pa_t pa, avdc_access_type_t type);
/**
* Reset cache statistics
*
* @param self Simulator instance
*/
void avdc_reset_statistics(avdark_cache_t *self);
/**
* Print information about the cache, e.g. size and other parameters.
*
* @param self Simulator instance
*/
void avdc_print_info(avdark_cache_t *self);
/**
* Dump the internal state of the cache simulator, useful for
* debuging.
*
* @param self Simulator instance
*/
void avdc_print_internals(avdark_cache_t *self);
/**
* Revoke an address in cache
*
* @param self Simulator instance
* @param pa Physical address to access
*/
void avdc_revoke(avdark_cache_t *self, avdc_pa_t pa);
#endif
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* indent-tabs-mode: nil
* c-file-style: "linux"
* compile-command: "make -k -C ../../"
* End:
*/