-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsi.c
83 lines (67 loc) · 2.12 KB
/
csi.c
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
/* EE318 Assignment 2
* Aditya Goturu <aditya18203@mechyd.ac.in>
* 18XJ1A0203
* Moriya Prateek Velagaleti <prateek18224@mechyd.ac.in>
* 18XJ1A0224
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "csim.h"
int
main(int argc, char *argv[])
{
/* attempt to stick to c89 */
/* yeah like half of this is copypasta from the branch predictor */
FILE *trace_file;
Trace *trace_root, *t;
struct sim_res sres;
char trace_line[MAX_TRACE_LINE_LEN];
int cs, bs, assoc, rpol;
if (argc != 2 || access(argv[1], R_OK)) {
goto error_out;
}
srand(LIKE_70_OR_SOMETHING);
trace_file = fopen(argv[1], "r");
trace_root = malloc(sizeof(Trace)); /* this one's a throwaway, only for the next */
t = trace_root;
while (fgets(trace_line, MAX_TRACE_LINE_LEN, trace_file)) { /* never trust fscanf */
char *tl;
t->next = malloc(sizeof(Trace));
tl = trace_line;
while (*tl == ' ')
tl++; /* trim leading whitespace */
sscanf(tl, "0x%lx", &t->next->addr);
t = t->next;
t->next = NULL; /* you never know */
}
fclose(trace_file);
for (rpol = RP_LRU; rpol <= RP_RND; rpol++)
for (cs = 0; cs <= 14; cs++)
for (bs = 0; bs <= 7; bs++)
for (assoc = 0; assoc <= 4; assoc++)
if (256 * (1L<<cs) > (1L<<assoc) * (4 * (1L<<bs))) {
fprintf(stderr, "Now simulating: %d %d %d %d\n", rpol, cs, bs, assoc);
fflush(stderr);
sres = csim(trace_root, cs, bs, assoc, rpol);
printf("%d %lu %lu %lu %lu %lu %lu %lu %lu\n", sres.replacement_policy, sres.cache_size,
sres.block_size, sres.associativity, sres.accesses,
sres.hits, sres.cold_misses, sres.conflict_misses, sres.capacity_misses);
fflush(stdout);
}
/* cleanup */
t = trace_root;
trace_root = trace_root->next;
free(t);
while(trace_root) {
t = trace_root;
trace_root = trace_root->next;
free(t);
}
return 0;
error_out:
printf("Error: invalid arguments\n"); /* enough said */
return 1;
}