mem-cache: Make WeightedLRU inherit from LRU
WeightedLRU adds occupancy information to LRU, so remove the duplicated code. Change-Id: Ifec19ea59fb411a5ed7a891e8957b1ab93cdbf05 Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/47399 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
b91cfc14bd
commit
2911839c22
@@ -120,7 +120,7 @@ class TreePLRURP(BaseReplacementPolicy):
|
||||
cxx_header = "mem/cache/replacement_policies/tree_plru_rp.hh"
|
||||
num_leaves = Param.Int(Parent.assoc, "Number of leaves in each tree")
|
||||
|
||||
class WeightedLRURP(BaseReplacementPolicy):
|
||||
class WeightedLRURP(LRURP):
|
||||
type = "WeightedLRURP"
|
||||
cxx_class = "replacement_policy::WeightedLRU"
|
||||
cxx_header = "mem/cache/replacement_policies/weighted_lru_rp.hh"
|
||||
|
||||
@@ -43,24 +43,15 @@ namespace replacement_policy
|
||||
{
|
||||
|
||||
WeightedLRU::WeightedLRU(const Params &p)
|
||||
: Base(p)
|
||||
: LRU(p)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
WeightedLRU::touch(const std::shared_ptr<ReplacementData>&
|
||||
replacement_data) const
|
||||
WeightedLRU::touch(const std::shared_ptr<ReplacementData>& replacement_data,
|
||||
int occupancy) const
|
||||
{
|
||||
std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
|
||||
last_touch_tick = curTick();
|
||||
}
|
||||
|
||||
void
|
||||
WeightedLRU::touch(const std::shared_ptr<ReplacementData>&
|
||||
replacement_data, int occupancy) const
|
||||
{
|
||||
std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
|
||||
last_touch_tick = curTick();
|
||||
LRU::touch(replacement_data);
|
||||
std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
|
||||
last_occ_ptr = occupancy;
|
||||
}
|
||||
@@ -90,8 +81,8 @@ WeightedLRU::getVictim(const ReplacementCandidates& candidates) const
|
||||
} else if (candidate_replacement_data->last_occ_ptr ==
|
||||
victim_replacement_data->last_occ_ptr) {
|
||||
// Evict the block with a smaller tick.
|
||||
Tick time = candidate_replacement_data->last_touch_tick;
|
||||
if (time < victim_replacement_data->last_touch_tick) {
|
||||
Tick time = candidate_replacement_data->lastTouchTick;
|
||||
if (time < victim_replacement_data->lastTouchTick) {
|
||||
victim = candidate;
|
||||
}
|
||||
}
|
||||
@@ -105,22 +96,4 @@ WeightedLRU::instantiateEntry()
|
||||
return std::shared_ptr<ReplacementData>(new WeightedLRUReplData);
|
||||
}
|
||||
|
||||
void
|
||||
WeightedLRU::reset(const std::shared_ptr<ReplacementData>&
|
||||
replacement_data) const
|
||||
{
|
||||
// Set last touch timestamp
|
||||
std::static_pointer_cast<WeightedLRUReplData>(
|
||||
replacement_data)->last_touch_tick = curTick();
|
||||
}
|
||||
|
||||
void
|
||||
WeightedLRU::invalidate(
|
||||
const std::shared_ptr<ReplacementData>& replacement_data)
|
||||
{
|
||||
// Reset last touch timestamp
|
||||
std::static_pointer_cast<WeightedLRUReplData>(
|
||||
replacement_data)->last_touch_tick = Tick(0);
|
||||
}
|
||||
|
||||
} // namespace replacement_policy
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/types.hh"
|
||||
#include "mem/cache/replacement_policies/base.hh"
|
||||
#include "mem/cache/replacement_policies/lru_rp.hh"
|
||||
|
||||
struct WeightedLRURPParams;
|
||||
|
||||
@@ -45,58 +45,29 @@ GEM5_DEPRECATED_NAMESPACE(ReplacementPolicy, replacement_policy);
|
||||
namespace replacement_policy
|
||||
{
|
||||
|
||||
class WeightedLRU : public Base
|
||||
class WeightedLRU : public LRU
|
||||
{
|
||||
protected:
|
||||
/** Weighted LRU implementation of replacement data. */
|
||||
struct WeightedLRUReplData : ReplacementData
|
||||
struct WeightedLRUReplData : LRUReplData
|
||||
{
|
||||
/** pointer for last occupancy */
|
||||
int last_occ_ptr;
|
||||
|
||||
/** Tick on which the entry was last touched. */
|
||||
Tick last_touch_tick;
|
||||
|
||||
/**
|
||||
* Default constructor. Invalidate data.
|
||||
*/
|
||||
WeightedLRUReplData() : ReplacementData(),
|
||||
last_occ_ptr(0), last_touch_tick(0) {}
|
||||
WeightedLRUReplData() : LRUReplData(), last_occ_ptr(0) {}
|
||||
};
|
||||
public:
|
||||
typedef WeightedLRURPParams Params;
|
||||
WeightedLRU(const Params &p);
|
||||
~WeightedLRU() = default;
|
||||
|
||||
/**
|
||||
* Invalidate replacement data to set it as the next probable victim.
|
||||
* Sets its last touch tick as the starting tick.
|
||||
*
|
||||
* @param replacement_data Replacement data to be invalidated.
|
||||
*/
|
||||
void invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
|
||||
override;
|
||||
|
||||
/**
|
||||
* Touch an entry to update its replacement data.
|
||||
* Sets its last touch tick as the current tick.
|
||||
*
|
||||
* @param replacement_data Replacement data to be touched.
|
||||
*/
|
||||
void touch(const std::shared_ptr<ReplacementData>&
|
||||
replacement_data) const override;
|
||||
using Base::touch;
|
||||
void touch(const std::shared_ptr<ReplacementData>& replacement_data,
|
||||
int occupancy) const;
|
||||
|
||||
/**
|
||||
* Reset replacement data. Used when an entry is inserted.
|
||||
* Sets its last touch tick as the current tick.
|
||||
*
|
||||
* @param replacement_data Replacement data to be reset.
|
||||
*/
|
||||
void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
override;
|
||||
|
||||
/**
|
||||
* Instantiate a replacement data entry.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user