-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachesim_driver.cpp
143 lines (128 loc) · 4.47 KB
/
cachesim_driver.cpp
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
#ifdef CCOMPILER
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#else
#include <cstdio>
#include <cinttypes>
#include <cstdlib>
#include <cstring>
#endif
#include <unistd.h>
#include "cachesim.hpp"
#include <cmath>
void print_help_and_exit(void) {
printf("cachesim [OPTIONS] < traces/file.trace\n");
printf("-h\t\tThis helpful output\n");
printf("L1 parameters:\n");
printf(" -c C1\t\tTotal size in bytes is 2^C1\n");
printf(" -b B1\t\tSize of each block in bytes is 2^B1\n");
printf(" -s S1\t\tNumber of blocks per set is 2^S1\n");
printf("Victim cache parameters:\n");
printf(" -v V\t\tNumber of blocks per set is V\n");
printf("L2 parameters:\n");
printf(" -C C2\t\tTotal size in bytes is 2^C2\n");
printf(" -B B2\t\tSize of each block in bytes is 2^B2\n");
printf(" -S S2\t\tNumber of blocks per set is 2^S2\n");
exit(0);
}
void print_statistics(cache_stats_t* p_stats, uint64_t c1, uint64_t b1,
uint64_t s1, uint64_t v, uint64_t c2, uint64_t b2, uint64_t s2);
int main(int argc, char* argv[]) {
int opt;
uint64_t c1 = DEFAULT_C1;
uint64_t b1 = DEFAULT_B1;
uint64_t s1 = DEFAULT_S1;
uint64_t c2 = DEFAULT_C2;
uint64_t b2 = DEFAULT_B2;
uint64_t s2 = DEFAULT_S2;
uint64_t v = DEFAULT_V;
/* Read arguments */
while(-1 != (opt = getopt(argc, argv, "c:b:s:v:C:B:S:h"))) {
switch(opt) {
case 'c':
c1 = atoi(optarg);
break;
case 'b':
b1 = atoi(optarg);
break;
case 's':
s1 = atoi(optarg);
break;
case 'v':
v = atoi(optarg);
break;
case 'C':
c2 = atoi(optarg);
break;
case 'B':
b2 = atoi(optarg);
break;
case 'S':
s2 = atoi(optarg);
break;
case 'h':
/* Fall through */
default:
print_help_and_exit();
break;
}
}
/*printf("Cache Settings\n");
printf("c: %" PRIu64 "\n", c1);
printf("b: %" PRIu64 "\n", b1);
printf("s: %" PRIu64 "\n", s1);
printf("v: %" PRIu64 "\n", v);
printf("C: %" PRIu64 "\n", c2);
printf("B: %" PRIu64 "\n", b2);
printf("S: %" PRIu64 "\n", s2);
printf("\n");*/
/* Setup the cache */
setup_cache(c1, b1, s1, v, c2, b2, s2);
/* Setup statistics */
cache_stats_t stats;
memset(&stats, 0, sizeof(cache_stats_t));
if ((8 * pow(2, c1) + pow(2, c1 - b1) * (64-(c1-s1)+2) + 8 * v * pow(2, b1) + v * (64-b1+1)) <= 393216
&& (8 * pow(2, c2) + pow(2, c2 - b2) * (64-(c2-s2)+2)) <= 1572864)
{
/* Begin reading the file */
char rw;
uint64_t address;
while (!feof(stdin)) {
int ret = fscanf(stdin, "%c %" PRIx64 "\n", &rw, &address);
if(ret == 2) {
cache_access(rw, address, &stats);
}
}
complete_cache(&stats);
//if (stats.avg_access_time_l1 <= 2.0005)
//print_statistics(&stats, c1, b1, s1, v, c2, b2, s2);
}
return 0;
}
void print_statistics(cache_stats_t* p_stats, uint64_t c1, uint64_t b1,
uint64_t s1, uint64_t v, uint64_t c2, uint64_t b2, uint64_t s2) {
/*printf("Cache Statistics\n");
printf("Accesses: %" PRIu64 "\n", p_stats->accesses);
printf("Accesses to L2: %" PRIu64 "\n", p_stats->accesses_l2);
printf("Accesses to VC: %" PRIu64 "\n", p_stats->accesses_vc);
printf("Reads: %" PRIu64 "\n", p_stats->reads);
printf("Read misses to L1: %" PRIu64 "\n", p_stats->read_misses_l1);
printf("Read misses to L2: %" PRIu64 "\n", p_stats->read_misses_l2);
printf("Writes: %" PRIu64 "\n", p_stats->writes);
printf("Write misses to L1: %" PRIu64 "\n", p_stats->write_misses_l1);
printf("Write misses to L2: %" PRIu64 "\n", p_stats->write_misses_l2);
printf("Write backs from L1: %" PRIu64 "\n", p_stats->write_back_l1);
printf("Write backs from L2: %" PRIu64 "\n", p_stats->write_back_l2);
printf("L1 victims hit in victim cache: %" PRIu64 "\n", p_stats->victim_hits);
printf("Average access time (AAT) for L1: %f\n", p_stats->avg_access_time_l1);*/
printf("\nAAT: %f, ", p_stats->avg_access_time_l1);
printf("C: %" PRIu64 ", ", c2);
printf("B: %" PRIu64 ", ", b2);
printf("S: %" PRIu64 ", ", s2);
printf("c: %" PRIu64 ", ", c1);
printf("b: %" PRIu64 ", ", b1);
printf("s: %" PRIu64 ", ", s1);
printf("v: %" PRIu64 "\n", v);
}