-
Notifications
You must be signed in to change notification settings - Fork 4
/
cache_controller.sv
121 lines (102 loc) · 2.46 KB
/
cache_controller.sv
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
//-----------------------------------------------------------------------------
//
// Title : cache controller
// Author : kundan vanama <[email protected]>
// vinod sake <[email protected]>
// Company : PSU
//
//-----------------------------------------------------------------------------
//
// File : cache_controller.sv
// Generated : 28 Feb 2017
// Last Updated: 21 Mar 2017
//-----------------------------------------------------------------------------
//
// Description : Sends CPU & SNOOP commands to cache and display statistics
// at the end of trace file
//
//-----------------------------------------------------------------------------
import cache_pkg::*;
module cache_controller(
input [commandsize - 1:0]command,
input [ADR_BITS-1:0]address,
input eof
);
logic [commandsize - 1:0]cmnd;
logic [ADR_BITS-1:0]addr;
// Statistics variables
real read=0,write=0,cache_hit=0,cache_miss=0;
real total,prfmnc;
// Statistics file
integer statistics;
cache l3cache(
.cmnd(cmnd),
.addr(addr),
.cache_hit(cache_hit),
.cache_miss(cache_miss),
.write(write),
.read(read)
);
assign total = cache_hit + cache_miss;
always @(cache_hit or cache_miss) begin
prfmnc = cache_hit/total;
end
always @(posedge eof) begin
$display("STATSITICS:");
$display("\nCACHE READS|CACHE WRITES|CACHE HITS|CACHE MISSES|CACHE HIT RATIO\n");
$display("%d |\t%d |\t%d |\t%d |\t%f%%\t",read,write,cache_hit,cache_miss, prfmnc*100);
statistics = $fopen("statistics.csv","w");
$fwrite(statistics,"\nCACHE READS,CACHE WRITES,CACHE HITS,CACHE MISSES,CACHE HIT RATIO\n");
$fwrite(statistics,"%d,%d,%d,%d,%f%%\n",read,write,cache_hit,cache_miss, prfmnc*100);
$fclose(statistics);
end
always@(command) begin
case(command)
CPU_READ_DATA :
begin
cmnd = CPU_READ;
addr = address;
end
CPU_WRITE_DATA :
begin
cmnd = CPU_WRITE;
addr = address;
end
CPU_READ_INSTRUCTION :
begin
cmnd = CPU_READ;
addr = address;
end
SNOOP_INVALIDATE :
begin
cmnd = SNOOP_INVALIDATE;
addr = address;
end
SNOOP_READ :
begin
cmnd = SNOOP_READ;
addr = address;
end
SNOOP_WRITE :
begin
cmnd = SNOOP_WRITE;
addr = address;
end
SNOOP_RWIM :
begin
cmnd = SNOOP_RWIM;
addr = address;
end
PRINT :
begin
cmnd = PRINT;
addr = address;
end
default :
begin
cmnd = command;
addr = address;
end
endcase
end
endmodule