Skip to content

Commit 1cf4d12

Browse files
committed
Add PLRU eviction to L1
Current addition is directly with FFs in the handler, not re-using tag storage.
1 parent e7c1862 commit 1cf4d12

5 files changed

Lines changed: 57 additions & 10 deletions

File tree

src/snitch_icache.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module snitch_icache #(
9999
BUFFER_LOOKUP: 0,
100100
GUARANTEE_ORDERING: 0,
101101
L0_PLRU: 1,
102+
L1_PLRU: 1,
102103

103104
FETCH_ALIGN: $clog2(FETCH_DW/8),
104105
FILL_ALIGN: $clog2(FILL_DW/8),

src/snitch_icache_handler.sv

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,62 @@ module snitch_icache_handler #(
242242
end
243243
end
244244

245-
// The cache line eviction LFSR is responsible for picking a cache line for
246-
// replacement at random. Note that we assume that the entire cache is full,
247-
// so no empty cache lines are available. This is the common case since we
248-
// do not support flushing of the cache.
249245
logic [CFG.SET_ALIGN-1:0] evict_index;
250246
logic evict_enable;
251247

252-
snitch_icache_lfsr #(CFG.SET_ALIGN) i_evict_lfsr (
253-
.clk_i ( clk_i ),
254-
.rst_ni ( rst_ni ),
255-
.value_o ( evict_index ),
256-
.enable_i ( evict_enable )
257-
);
248+
if ( CFG.L1_PLRU ) begin : gen_plru
249+
250+
logic [CFG.LINE_COUNT-1:0][CFG.SET_COUNT-1:0] used_masks;
251+
logic [CFG.LINE_COUNT-1:0][CFG.SET_COUNT-1:0] evict_masks;
252+
253+
always_comb begin
254+
used_masks = '0;
255+
if (in_req_valid_i && in_req_hit_i) begin
256+
// hit update
257+
used_masks[in_req_addr_i >> CFG.LINE_ALIGN][in_req_set_i] = 1'b1;
258+
end else if (write_valid_o) begin
259+
// refill update
260+
used_masks[write_addr_o][write_set_o] = 1'b1;
261+
end
262+
end
263+
264+
for (genvar i = 0; i < CFG.LINE_COUNT; i++) begin : gen_plru_tree
265+
266+
plru_tree #(
267+
.ENTRIES ( CFG.SET_COUNT )
268+
) i_plru_tree (
269+
.clk_i,
270+
.rst_ni,
271+
272+
.used_i ( used_masks [i] ),
273+
.plru_o ( evict_masks[i] )
274+
);
275+
276+
end
277+
278+
onehot_to_bin #(
279+
.ONEHOT_WIDTH ( CFG.SET_COUNT )
280+
) i_evict_mask_to_index (
281+
.onehot ( evict_masks[write_addr_o] ),
282+
.bin ( evict_index )
283+
);
284+
285+
end else begin : gen_lfsr
286+
287+
// The cache line eviction LFSR is responsible for picking a cache line for
288+
// replacement at random. Note that we assume that the entire cache is full,
289+
// so no empty cache lines are available. This is the common case since we
290+
// do not support flushing of the cache.
291+
snitch_icache_lfsr #(
292+
.N (CFG.SET_ALIGN)
293+
) i_evict_lfsr (
294+
.clk_i ( clk_i ),
295+
.rst_ni ( rst_ni ),
296+
.value_o ( evict_index ),
297+
.enable_i ( evict_enable )
298+
);
299+
300+
end
258301

259302
// The response handler deals with incoming refill responses. It queries and
260303
// clears the corresponding entry in the pending table, stores the data in

src/snitch_icache_pkg.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package snitch_icache_pkg;
3131
bit BUFFER_LOOKUP;
3232
bit GUARANTEE_ORDERING;
3333
bit L0_PLRU;
34+
bit L1_PLRU;
3435

3536
// Derived values.
3637
int unsigned FETCH_ALIGN;

src/snitch_read_only_cache.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ module snitch_read_only_cache #(
205205
BUFFER_LOOKUP: 1, // Mandatory here
206206
GUARANTEE_ORDERING: 1, // Mandatory here
207207
L0_PLRU: 0, // Unused here
208+
L1_PLRU: 1,
208209

209210
FETCH_ALIGN: $clog2(AxiDataWidth/8),
210211
FILL_ALIGN: $clog2(AxiDataWidth/8),

test/snitch_icache_l0_tb.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module snitch_icache_l0_tb #(
9292
BUFFER_LOOKUP: BUFFER_LOOKUP,
9393
GUARANTEE_ORDERING: GUARANTEE_ORDERING,
9494
L0_PLRU: 1'b1,
95+
L1_PLRU: 1'b1,
9596

9697
FETCH_ALIGN: $clog2(FETCH_DW/8),
9798
FILL_ALIGN: $clog2(FILL_DW/8),

0 commit comments

Comments
 (0)