-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache-sim.h
More file actions
104 lines (89 loc) · 2.58 KB
/
cache-sim.h
File metadata and controls
104 lines (89 loc) · 2.58 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
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <getopt.h>
#define NOT_FOUND -1
/* represents a status flag to determine what happened in cache each memory access */
typedef enum status {
MISS_AND_REPLACE = -1,
MISS = 0,
HIT = 1
}status_t;
typedef struct line
{
unsigned long long tag;
unsigned int order;
unsigned char valid;
} line_t;
typedef struct set
{
unsigned int most_recent_order;
line_t *lines;
} set_t;
typedef struct cache
{
set_t *sets;
unsigned int set_number;
unsigned int set_bits;
unsigned int lines_per_set;
unsigned int block_bits;
unsigned int block_size;
} cache_t;
int parseArguments(int argc, char **argv,
unsigned int *set_bits, unsigned int *lines_per_set, unsigned int *block_bits,
FILE **trace);
/*
* Function: parseArguments
* ------------------------
* parse the options given by the user.
*
* argc: number of arguments passed to main (main's argc)
* argv: pointer to the array of arguments (main's argv)
*
* set_bits: the number of set bits(s) that decodes (2^s) cache set(S)
* line_per_set: the number of lines per set
* block_bits: the number of block bits(b) that decodes a block
*
* trace: a pointer to the pointer of the trace file
*
* return: 1 if -v option(verbose) is set
* 0 if -v option(verbose) is not set
*/
cache_t *createCache(unsigned int s, unsigned int E, unsigned int b);
/*
* Function: createCache
* ------------------------
* Allocate and initialize memory for cache.
*
* s: set bits
* E: lines per set
* b: block bits
*
* return: a pointer to the allocated memory for the cache
*/
void accessMemory(FILE *trace, cache_t *cache_ptr, int verbose,
unsigned int *hit_count_ptr, unsigned int *miss_count_ptr, unsigned int *eviction_count_ptr);
/*
* Function: accessMemory
* ----------------------
* Simulate the memory access for each address in the trace file and updates counters depending on each access status.
*
* trace: a pointer to the trace file
* cache_ptr: a pointer to the allocated cache
* hit_count_ptr: a pointer to the hit counter
* miss_count_ptr: a pointer to the miss counter
* eviction_count_ptr: a pointer to the eviction counter
*
* return: void
*/
void deleteCache (cache_t *cache_ptr);
/*
* Function: deleteCache
* ---------------------
* Free the allocated memory for the cache
*
* cache_ptr: a pointer to the cache
*
* return: void
*/