Encapsulate the replacement policy classes in their own namespace.
As a side effect these classes have been renamed to drop the RP
suffix in the C++ code.
Change-Id: Ibb65dfb584a1413492fcf11833cf91a859cbff4e
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35795
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
/** Pointer to the indexing policy */
BaseIndexingPolicy* const indexingPolicy;
/** Pointer to the replacement policy */
- BaseReplacementPolicy* const replacementPolicy;
+ ReplacementPolicy::Base* const replacementPolicy;
/** Vector containing the entries of the container */
std::vector<Entry> entries;
* of sets can be calculated dividing this balue by the 'assoc' value
* @param idx_policy indexing policy
* @param rpl_policy replacement policy
- * @param initial value of the elements of the set
+ * @param init_val initial value of the elements of the set
*/
AssociativeSet(int assoc, int num_entries, BaseIndexingPolicy *idx_policy,
- BaseReplacementPolicy *rpl_policy, Entry const &init_value =
- Entry());
+ ReplacementPolicy::Base *rpl_policy, Entry const &init_val = Entry());
/**
* Find an entry within the set
template<class Entry>
AssociativeSet<Entry>::AssociativeSet(int assoc, int num_entries,
- BaseIndexingPolicy *idx_policy, BaseReplacementPolicy *rpl_policy,
+ BaseIndexingPolicy *idx_policy, ReplacementPolicy::Base *rpl_policy,
Entry const &init_value)
: associativity(assoc), numEntries(num_entries), indexingPolicy(idx_policy),
replacementPolicy(rpl_policy), entries(numEntries, init_value)
#include "params/StridePrefetcherHashedSetAssociative.hh"
class BaseIndexingPolicy;
-class BaseReplacementPolicy;
+namespace ReplacementPolicy {
+ class Base;
+}
struct StridePrefetcherParams;
namespace Prefetcher {
const int numEntries;
BaseIndexingPolicy* const indexingPolicy;
- BaseReplacementPolicy* const replacementPolicy;
+ ReplacementPolicy::Base* const replacementPolicy;
PCTableInfo(int assoc, int num_entries,
BaseIndexingPolicy* indexing_policy,
- BaseReplacementPolicy* replacement_policy)
+ ReplacementPolicy::Base* replacement_policy)
: assoc(assoc), numEntries(num_entries),
indexingPolicy(indexing_policy),
replacementPolicy(replacement_policy)
-# Copyright (c) 2018 Inria
+# Copyright (c) 2018-2020 Inria
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
class BaseReplacementPolicy(SimObject):
type = 'BaseReplacementPolicy'
abstract = True
+ cxx_class = 'ReplacementPolicy::Base'
cxx_header = "mem/cache/replacement_policies/base.hh"
class FIFORP(BaseReplacementPolicy):
type = 'FIFORP'
- cxx_class = 'FIFORP'
+ cxx_class = 'ReplacementPolicy::FIFO'
cxx_header = "mem/cache/replacement_policies/fifo_rp.hh"
class SecondChanceRP(FIFORP):
type = 'SecondChanceRP'
- cxx_class = 'SecondChanceRP'
+ cxx_class = 'ReplacementPolicy::SecondChance'
cxx_header = "mem/cache/replacement_policies/second_chance_rp.hh"
class LFURP(BaseReplacementPolicy):
type = 'LFURP'
- cxx_class = 'LFURP'
+ cxx_class = 'ReplacementPolicy::LFU'
cxx_header = "mem/cache/replacement_policies/lfu_rp.hh"
class LRURP(BaseReplacementPolicy):
type = 'LRURP'
- cxx_class = 'LRURP'
+ cxx_class = 'ReplacementPolicy::LRU'
cxx_header = "mem/cache/replacement_policies/lru_rp.hh"
class BIPRP(LRURP):
type = 'BIPRP'
- cxx_class = 'BIPRP'
+ cxx_class = 'ReplacementPolicy::BIP'
cxx_header = "mem/cache/replacement_policies/bip_rp.hh"
btp = Param.Percent(3, "Percentage of blocks to be inserted as MRU")
class MRURP(BaseReplacementPolicy):
type = 'MRURP'
- cxx_class = 'MRURP'
+ cxx_class = 'ReplacementPolicy::MRU'
cxx_header = "mem/cache/replacement_policies/mru_rp.hh"
class RandomRP(BaseReplacementPolicy):
type = 'RandomRP'
- cxx_class = 'RandomRP'
+ cxx_class = 'ReplacementPolicy::Random'
cxx_header = "mem/cache/replacement_policies/random_rp.hh"
class BRRIPRP(BaseReplacementPolicy):
type = 'BRRIPRP'
- cxx_class = 'BRRIPRP'
+ cxx_class = 'ReplacementPolicy::BRRIP'
cxx_header = "mem/cache/replacement_policies/brrip_rp.hh"
num_bits = Param.Int(2, "Number of bits per RRPV")
hit_priority = Param.Bool(False,
class TreePLRURP(BaseReplacementPolicy):
type = 'TreePLRURP'
- cxx_class = 'TreePLRURP'
+ cxx_class = 'ReplacementPolicy::TreePLRU'
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):
type = "WeightedLRURP"
- cxx_class = "WeightedLRUPolicy"
+ cxx_class = "ReplacementPolicy::WeightedLRU"
cxx_header = "mem/cache/replacement_policies/weighted_lru_rp.hh"
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
typedef std::vector<ReplaceableEntry*> ReplacementCandidates;
+namespace ReplacementPolicy {
+
/**
* A common base class of cache replacement policy objects.
*/
-class BaseReplacementPolicy : public SimObject
+class Base : public SimObject
{
public:
- /**
- * Convenience typedef.
- */
typedef BaseReplacementPolicyParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- BaseReplacementPolicy(const Params *p) : SimObject(p) {}
-
- /**
- * Destructor.
- */
- virtual ~BaseReplacementPolicy() {}
+ Base(const Params *p) : SimObject(p) {}
+ virtual ~Base() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
virtual std::shared_ptr<ReplacementData> instantiateEntry() = 0;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "params/BIPRP.hh"
#include "sim/core.hh"
-BIPRP::BIPRP(const Params *p)
- : LRURP(p), btp(p->btp)
+namespace ReplacementPolicy {
+
+BIP::BIP(const Params *p)
+ : LRU(p), btp(p->btp)
{
}
void
-BIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+BIP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
std::shared_ptr<LRUReplData> casted_replacement_data =
std::static_pointer_cast<LRUReplData>(replacement_data);
}
}
-BIPRP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::BIP*
BIPRPParams::create()
{
- return new BIPRP(this);
+ return new ReplacementPolicy::BIP(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct BIPRPParams;
-class BIPRP : public LRURP
+namespace ReplacementPolicy {
+
+class BIP : public LRU
{
protected:
/**
const unsigned btp;
public:
- /** Convenience typedef. */
typedef BIPRPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- BIPRP(const Params *p);
-
- /**
- * Destructor.
- */
- ~BIPRP() {}
+ BIP(const Params *p);
+ ~BIP() = default;
/**
* Reset replacement data for an entry. Used when an entry is inserted.
override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BIP_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "base/random.hh"
#include "params/BRRIPRP.hh"
-BRRIPRP::BRRIPRP(const Params *p)
- : BaseReplacementPolicy(p),
- numRRPVBits(p->num_bits), hitPriority(p->hit_priority), btp(p->btp)
+namespace ReplacementPolicy {
+
+BRRIP::BRRIP(const Params *p)
+ : Base(p), numRRPVBits(p->num_bits), hitPriority(p->hit_priority),
+ btp(p->btp)
{
fatal_if(numRRPVBits <= 0, "There should be at least one bit per RRPV.\n");
}
void
-BRRIPRP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+BRRIP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
std::shared_ptr<BRRIPReplData> casted_replacement_data =
}
void
-BRRIPRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+BRRIP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
{
std::shared_ptr<BRRIPReplData> casted_replacement_data =
std::static_pointer_cast<BRRIPReplData>(replacement_data);
}
void
-BRRIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+BRRIP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
std::shared_ptr<BRRIPReplData> casted_replacement_data =
std::static_pointer_cast<BRRIPReplData>(replacement_data);
}
ReplaceableEntry*
-BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
+BRRIP::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-BRRIPRP::instantiateEntry()
+BRRIP::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new BRRIPReplData(numRRPVBits));
}
-BRRIPRP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::BRRIP*
BRRIPRPParams::create()
{
- return new BRRIPRP(this);
+ return new ReplacementPolicy::BRRIP(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct BRRIPRPParams;
-class BRRIPRP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class BRRIP : public Base
{
protected:
/** BRRIP-specific implementation of replacement data. */
const unsigned btp;
public:
- /** Convenience typedef. */
typedef BRRIPRPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- BRRIPRP(const Params *p);
-
- /**
- * Destructor.
- */
- ~BRRIPRP() {}
+ BRRIP(const Params *p);
+ ~BRRIP() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "params/FIFORP.hh"
#include "sim/core.hh"
-FIFORP::FIFORP(const Params *p)
- : BaseReplacementPolicy(p)
+namespace ReplacementPolicy {
+
+FIFO::FIFO(const Params *p)
+ : Base(p)
{
}
void
-FIFORP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+FIFO::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// Reset insertion tick
}
void
-FIFORP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+FIFO::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// A touch does not modify the insertion tick
}
void
-FIFORP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+FIFO::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Set insertion tick
std::static_pointer_cast<FIFOReplData>(
}
ReplaceableEntry*
-FIFORP::getVictim(const ReplacementCandidates& candidates) const
+FIFO::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-FIFORP::instantiateEntry()
+FIFO::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new FIFOReplData());
}
-FIFORP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::FIFO*
FIFORPParams::create()
{
- return new FIFORP(this);
+ return new ReplacementPolicy::FIFO(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct FIFORPParams;
-class FIFORP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class FIFO : public Base
{
protected:
/** FIFO-specific implementation of replacement data. */
};
public:
- /** Convenience typedef. */
typedef FIFORPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- FIFORP(const Params *p);
-
- /**
- * Destructor.
- */
- ~FIFORP() {}
+ FIFO(const Params *p);
+ ~FIFO() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "params/LFURP.hh"
-LFURP::LFURP(const Params *p)
- : BaseReplacementPolicy(p)
+namespace ReplacementPolicy {
+
+LFU::LFU(const Params *p)
+ : Base(p)
{
}
void
-LFURP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+LFU::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// Reset reference count
}
void
-LFURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+LFU::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Update reference count
std::static_pointer_cast<LFUReplData>(replacement_data)->refCount++;
}
void
-LFURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+LFU::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Reset reference count
std::static_pointer_cast<LFUReplData>(replacement_data)->refCount = 1;
}
ReplaceableEntry*
-LFURP::getVictim(const ReplacementCandidates& candidates) const
+LFU::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-LFURP::instantiateEntry()
+LFU::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new LFUReplData());
}
-LFURP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::LFU*
LFURPParams::create()
{
- return new LFURP(this);
+ return new ReplacementPolicy::LFU(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct LFURPParams;
-class LFURP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class LFU : public Base
{
protected:
/** LFU-specific implementation of replacement data. */
};
public:
- /** Convenience typedef. */
typedef LFURPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- LFURP(const Params *p);
-
- /**
- * Destructor.
- */
- ~LFURP() {}
+ LFU(const Params *p);
+ ~LFU() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_LFU_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "params/LRURP.hh"
#include "sim/core.hh"
-LRURP::LRURP(const Params *p)
- : BaseReplacementPolicy(p)
+namespace ReplacementPolicy {
+
+LRU::LRU(const Params *p)
+ : Base(p)
{
}
void
-LRURP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+LRU::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// Reset last touch timestamp
}
void
-LRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+LRU::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Update last touch timestamp
std::static_pointer_cast<LRUReplData>(
}
void
-LRURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+LRU::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Set last touch timestamp
std::static_pointer_cast<LRUReplData>(
}
ReplaceableEntry*
-LRURP::getVictim(const ReplacementCandidates& candidates) const
+LRU::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-LRURP::instantiateEntry()
+LRU::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new LRUReplData());
}
-LRURP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::LRU*
LRURPParams::create()
{
- return new LRURP(this);
+ return new ReplacementPolicy::LRU(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct LRURPParams;
-class LRURP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class LRU : public Base
{
protected:
/** LRU-specific implementation of replacement data. */
};
public:
- /** Convenience typedef. */
typedef LRURPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- LRURP(const Params *p);
-
- /**
- * Destructor.
- */
- ~LRURP() {}
+ LRU(const Params *p);
+ ~LRU() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_LRU_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "params/MRURP.hh"
#include "sim/core.hh"
-MRURP::MRURP(const Params *p)
- : BaseReplacementPolicy(p)
+namespace ReplacementPolicy {
+
+MRU::MRU(const Params *p)
+ : Base(p)
{
}
void
-MRURP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+MRU::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// Reset last touch timestamp
}
void
-MRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+MRU::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Update last touch timestamp
std::static_pointer_cast<MRUReplData>(
}
void
-MRURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+MRU::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Set last touch timestamp
std::static_pointer_cast<MRUReplData>(
}
ReplaceableEntry*
-MRURP::getVictim(const ReplacementCandidates& candidates) const
+MRU::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-MRURP::instantiateEntry()
+MRU::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new MRUReplData());
}
-MRURP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::MRU*
MRURPParams::create()
{
- return new MRURP(this);
+ return new ReplacementPolicy::MRU(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct MRURPParams;
-class MRURP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class MRU : public Base
{
protected:
/** MRU-specific implementation of replacement data. */
};
public:
- /** Convenience typedef. */
typedef MRURPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- MRURP(const Params *p);
-
- /**
- * Destructor.
- */
- ~MRURP() {}
+ MRU(const Params *p);
+ ~MRU() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_MRU_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "base/random.hh"
#include "params/RandomRP.hh"
-RandomRP::RandomRP(const Params *p)
- : BaseReplacementPolicy(p)
+namespace ReplacementPolicy {
+
+Random::Random(const Params *p)
+ : Base(p)
{
}
void
-RandomRP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+Random::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// Unprioritize replacement data victimization
}
void
-RandomRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+Random::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
{
}
void
-RandomRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+Random::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Unprioritize replacement data victimization
std::static_pointer_cast<RandomReplData>(
}
ReplaceableEntry*
-RandomRP::getVictim(const ReplacementCandidates& candidates) const
+Random::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-RandomRP::instantiateEntry()
+Random::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new RandomReplData());
}
-RandomRP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::Random*
RandomRPParams::create()
{
- return new RandomRP(this);
+ return new ReplacementPolicy::Random(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct RandomRPParams;
-class RandomRP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class Random : public Base
{
protected:
- /** MRU-specific implementation of replacement data. */
+ /** Random-specific implementation of replacement data. */
struct RandomReplData : ReplacementData
{
/**
};
public:
- /** Convenience typedef. */
typedef RandomRPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- RandomRP(const Params *p);
-
- /**
- * Destructor.
- */
- ~RandomRP() {}
+ Random(const Params *p);
+ ~Random() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "base/cprintf.hh"
+namespace ReplacementPolicy {
+
/**
* The replacement data needed by replacement policies. Each replacement policy
* should have its own implementation of replacement data.
*/
struct ReplacementData {};
+} // namespace ReplacementPolicy
+
/**
* A replaceable entry is a basic entry in a 2d table-like structure that needs
* to have replacement functionality. This entry is located in a specific row
* Replacement data associated to this entry.
* It must be instantiated by the replacement policy before being used.
*/
- std::shared_ptr<ReplacementData> replacementData;
+ std::shared_ptr<ReplacementPolicy::ReplacementData> replacementData;
/**
* Set both the set and way. Should be called only once.
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "params/SecondChanceRP.hh"
-SecondChanceRP::SecondChanceRP(const Params *p)
- : FIFORP(p)
+namespace ReplacementPolicy {
+
+SecondChance::SecondChance(const Params *p)
+ : FIFO(p)
{
}
void
-SecondChanceRP::useSecondChance(
+SecondChance::useSecondChance(
const std::shared_ptr<SecondChanceReplData>& replacement_data) const
{
// Reset FIFO data
- FIFORP::reset(replacement_data);
+ FIFO::reset(replacement_data);
// Use second chance
replacement_data->hasSecondChance = false;
}
void
-SecondChanceRP::invalidate(
+SecondChance::invalidate(
const std::shared_ptr<ReplacementData>& replacement_data) const
{
- FIFORP::invalidate(replacement_data);
+ FIFO::invalidate(replacement_data);
// Do not give a second chance to invalid entries
std::static_pointer_cast<SecondChanceReplData>(
}
void
-SecondChanceRP::touch(const std::shared_ptr<ReplacementData>&
- replacement_data) const
+SecondChance::touch(
+ const std::shared_ptr<ReplacementData>& replacement_data) const
{
- FIFORP::touch(replacement_data);
+ FIFO::touch(replacement_data);
// Whenever an entry is touched, it is given a second chance
std::static_pointer_cast<SecondChanceReplData>(
}
void
-SecondChanceRP::reset(const std::shared_ptr<ReplacementData>&
- replacement_data) const
+SecondChance::reset(
+ const std::shared_ptr<ReplacementData>& replacement_data) const
{
- FIFORP::reset(replacement_data);
+ FIFO::reset(replacement_data);
// Entries are inserted with a second chance
std::static_pointer_cast<SecondChanceReplData>(
}
ReplaceableEntry*
-SecondChanceRP::getVictim(const ReplacementCandidates& candidates) const
+SecondChance::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
bool search_victim = true;
while (search_victim) {
// Do a FIFO victim search
- victim = FIFORP::getVictim(candidates);
+ victim = FIFO::getVictim(candidates);
// Cast victim's replacement data for code readability
std::shared_ptr<SecondChanceReplData> victim_replacement_data =
}
std::shared_ptr<ReplacementData>
-SecondChanceRP::instantiateEntry()
+SecondChance::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new SecondChanceReplData());
}
-SecondChanceRP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::SecondChance*
SecondChanceRPParams::create()
{
- return new SecondChanceRP(this);
+ return new ReplacementPolicy::SecondChance(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct SecondChanceRPParams;
-class SecondChanceRP : public FIFORP
+namespace ReplacementPolicy {
+
+class SecondChance : public FIFO
{
protected:
/** Second-Chance-specific implementation of replacement data. */
/**
* This is different from isTouched because isTouched accounts only
* for insertion, while this bit is reset every new re-insertion.
- * @sa SecondChanceRP.
+ * @sa SecondChance.
*/
bool hasSecondChance;
const std::shared_ptr<SecondChanceReplData>& replacement_data) const;
public:
- /** Convenience typedef. */
typedef SecondChanceRPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- SecondChanceRP(const Params *p);
-
- /**
- * Destructor.
- */
- ~SecondChanceRP() {}
+ SecondChance(const Params *p);
+ ~SecondChance() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_SECOND_CHANCE_RP_HH__
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "base/logging.hh"
#include "params/TreePLRURP.hh"
+namespace ReplacementPolicy {
+
/**
* Get the index of the parent of the given indexed subtree.
*
return index%2 == 0;
}
-TreePLRURP::TreePLRUReplData::TreePLRUReplData(
+TreePLRU::TreePLRUReplData::TreePLRUReplData(
const uint64_t index, std::shared_ptr<PLRUTree> tree)
- : index(index), tree(tree)
+ : index(index), tree(tree)
{
}
-TreePLRURP::TreePLRURP(const Params *p)
- : BaseReplacementPolicy(p), numLeaves(p->num_leaves), count(0),
- treeInstance(nullptr)
+TreePLRU::TreePLRU(const Params *p)
+ : Base(p), numLeaves(p->num_leaves), count(0), treeInstance(nullptr)
{
fatal_if(!isPowerOf2(numLeaves),
"Number of leaves must be non-zero and a power of 2");
}
void
-TreePLRURP::invalidate(
+TreePLRU::invalidate(
const std::shared_ptr<ReplacementData>& replacement_data) const
{
// Cast replacement data
}
void
-TreePLRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data)
+TreePLRU::touch(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// Cast replacement data
}
void
-TreePLRURP::reset(const std::shared_ptr<ReplacementData>& replacement_data)
+TreePLRU::reset(const std::shared_ptr<ReplacementData>& replacement_data)
const
{
// A reset has the same functionality of a touch
}
ReplaceableEntry*
-TreePLRURP::getVictim(const ReplacementCandidates& candidates) const
+TreePLRU::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-TreePLRURP::instantiateEntry()
+TreePLRU::instantiateEntry()
{
// Generate a tree instance every numLeaves created
if (count % numLeaves == 0) {
return std::shared_ptr<ReplacementData>(treePLRUReplData);
}
-TreePLRURP*
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::TreePLRU*
TreePLRURPParams::create()
{
- return new TreePLRURP(this);
+ return new ReplacementPolicy::TreePLRU(this);
}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018-2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct TreePLRURPParams;
-class TreePLRURP : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class TreePLRU : public Base
{
private:
/**
};
public:
- /** Convenience typedef. */
typedef TreePLRURPParams Params;
-
- /**
- * Construct and initiliaze this replacement policy.
- */
- TreePLRURP(const Params *p);
-
- /**
- * Destructor.
- */
- ~TreePLRURP() {}
+ TreePLRU(const Params *p);
+ ~TreePLRU() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
std::shared_ptr<ReplacementData> instantiateEntry() override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_TREE_PLRU_RP_HH__
#include "params/WeightedLRURP.hh"
#include "sim/core.hh"
-WeightedLRUPolicy::WeightedLRUPolicy(const Params* p)
- : BaseReplacementPolicy(p)
-{
-}
+namespace ReplacementPolicy {
-WeightedLRUPolicy *
-WeightedLRURPParams::create()
+WeightedLRU::WeightedLRU(const Params* p)
+ : Base(p)
{
- return new WeightedLRUPolicy(this);
}
void
-WeightedLRUPolicy::touch(const std::shared_ptr<ReplacementData>&
+WeightedLRU::touch(const std::shared_ptr<ReplacementData>&
replacement_data) const
{
std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
}
void
-WeightedLRUPolicy::touch(const std::shared_ptr<ReplacementData>&
+WeightedLRU::touch(const std::shared_ptr<ReplacementData>&
replacement_data, int occupancy) const
{
std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
}
ReplaceableEntry*
-WeightedLRUPolicy::getVictim(const ReplacementCandidates& candidates) const
+WeightedLRU::getVictim(const ReplacementCandidates& candidates) const
{
assert(candidates.size() > 0);
}
std::shared_ptr<ReplacementData>
-WeightedLRUPolicy::instantiateEntry()
+WeightedLRU::instantiateEntry()
{
return std::shared_ptr<ReplacementData>(new WeightedLRUReplData);
}
void
-WeightedLRUPolicy::reset(const std::shared_ptr<ReplacementData>&
+WeightedLRU::reset(const std::shared_ptr<ReplacementData>&
replacement_data) const
{
// Set last touch timestamp
}
void
-WeightedLRUPolicy::invalidate(const std::shared_ptr<ReplacementData>&
+WeightedLRU::invalidate(const std::shared_ptr<ReplacementData>&
replacement_data) const
{
// Reset last touch timestamp
std::static_pointer_cast<WeightedLRUReplData>(
replacement_data)->last_touch_tick = Tick(0);
}
+
+} // namespace ReplacementPolicy
+
+ReplacementPolicy::WeightedLRU*
+WeightedLRURPParams::create()
+{
+ return new ReplacementPolicy::WeightedLRU(this);
+}
struct WeightedLRURPParams;
-class WeightedLRUPolicy : public BaseReplacementPolicy
+namespace ReplacementPolicy {
+
+class WeightedLRU : public Base
{
protected:
/** Weighted LRU implementation of replacement data. */
};
public:
typedef WeightedLRURPParams Params;
- WeightedLRUPolicy(const Params* p);
- ~WeightedLRUPolicy() {}
+ WeightedLRU(const Params* p);
+ ~WeightedLRU() = default;
/**
* Invalidate replacement data to set it as the next probable victim.
candidates) const override;
};
+} // namespace ReplacementPolicy
+
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_WEIGHTED_LRU_RP_HH__
const bool sequentialAccess;
/** Replacement policy */
- BaseReplacementPolicy *replacementPolicy;
+ ReplacementPolicy::Base *replacementPolicy;
public:
/** Convenience typedef. */
#include "mem/packet.hh"
#include "params/SectorTags.hh"
-class BaseReplacementPolicy;
+namespace ReplacementPolicy {
+ class Base;
+}
class ReplaceableEntry;
/**
const bool sequentialAccess;
/** Replacement policy */
- BaseReplacementPolicy *replacementPolicy;
+ ReplacementPolicy::Base *replacementPolicy;
/** Number of data blocks per sector. */
const unsigned numBlocksPerSector;
m_is_instruction_only_cache = p->is_icache;
m_resource_stalls = p->resourceStalls;
m_block_size = p->block_size; // may be 0 at this point. Updated in init()
- m_use_occupancy = dynamic_cast<WeightedLRUPolicy*>(
+ m_use_occupancy = dynamic_cast<ReplacementPolicy::WeightedLRU*>(
m_replacementPolicy_ptr) ? true : false;
}
// replacement policy. Depending on different replacement policies,
// use different touch() function.
if (m_use_occupancy) {
- static_cast<WeightedLRUPolicy*>(m_replacementPolicy_ptr)->touch(
+ static_cast<ReplacementPolicy::WeightedLRU*>(
+ m_replacementPolicy_ptr)->touch(
entry->replacementData, occupancy);
} else {
m_replacementPolicy_ptr->touch(entry->replacementData);
{
public:
typedef RubyCacheParams Params;
- typedef std::shared_ptr<ReplacementData> ReplData;
+ typedef std::shared_ptr<ReplacementPolicy::ReplacementData> ReplData;
CacheMemory(const Params *p);
~CacheMemory();
std::unordered_map<Addr, int> m_tag_index;
std::vector<std::vector<AbstractCacheEntry*> > m_cache;
- /**
- * We use BaseReplacementPolicy from Classic system here, hence we can use
- * different replacement policies from Classic system in Ruby system.
- */
- BaseReplacementPolicy *m_replacementPolicy_ptr;
+ /** We use the replacement policies from the Classic memory system. */
+ ReplacementPolicy::Base *m_replacementPolicy_ptr;
BankedArray dataArray;
BankedArray tagArray;