X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmem%2Fcache%2Ftags%2Frandom_repl.cc;h=ab51f640770c0a9560f107e1fb2e24eab203e9c4;hb=1d4717ab7ece153206b0bd0bd8e1acc9497cbf05;hp=77b3791353622ce9d7a7fe793b6eaf45d212c1c5;hpb=a628afedade8d7b7cab108a81e714fc2755b4af3;p=gem5.git diff --git a/src/mem/cache/tags/random_repl.cc b/src/mem/cache/tags/random_repl.cc index 77b379135..ab51f6407 100644 --- a/src/mem/cache/tags/random_repl.cc +++ b/src/mem/cache/tags/random_repl.cc @@ -1,5 +1,6 @@ /* * Copyright (c) 2014 The Regents of The University of Michigan + * Copyright (c) 2016 ARM Limited * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,9 +34,10 @@ * Definitions of a random replacement tag store. */ +#include "mem/cache/tags/random_repl.hh" + #include "base/random.hh" #include "debug/CacheRepl.hh" -#include "mem/cache/tags/random_repl.hh" #include "mem/cache/base.hh" RandomRepl::RandomRepl(const Params *p) @@ -44,24 +46,32 @@ RandomRepl::RandomRepl(const Params *p) { } -BaseSetAssoc::BlkType* -RandomRepl::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id) +CacheBlk* +RandomRepl::accessBlock(Addr addr, bool is_secure, Cycles &lat) { - return BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id); + return BaseSetAssoc::accessBlock(addr, is_secure, lat); } -BaseSetAssoc::BlkType* -RandomRepl::findVictim(Addr addr) const +CacheBlk* +RandomRepl::findVictim(Addr addr) { - BlkType *blk = BaseSetAssoc::findVictim(addr); + CacheBlk *blk = BaseSetAssoc::findVictim(addr); + unsigned set = extractSet(addr); // if all blocks are valid, pick a replacement at random - if (blk->isValid()) { + if (blk && blk->isValid()) { // find a random index within the bounds of the set int idx = random_mt.random(0, assoc - 1); + blk = sets[set].blks[idx]; + // Enforce allocation limit + while (blk->way >= allocAssoc) { + idx = (idx + 1) % assoc; + blk = sets[set].blks[idx]; + } + assert(idx < assoc); assert(idx >= 0); - blk = sets[extractSet(addr)].blks[idx]; + assert(blk->way < allocAssoc); DPRINTF(CacheRepl, "set %x: selecting blk %x for replacement\n", blk->set, regenerateBlkAddr(blk->tag, blk->set)); @@ -77,7 +87,7 @@ RandomRepl::insertBlock(PacketPtr pkt, BlkType *blk) } void -RandomRepl::invalidate(BlkType *blk) +RandomRepl::invalidate(CacheBlk *blk) { BaseSetAssoc::invalidate(blk); }