mem-cache: Create ReplacementPolicy namespace
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>
This commit is contained in:
committed by
Daniel Carvalho
parent
0d5a80cb46
commit
523d42d1ce
7
src/mem/cache/prefetch/associative_set.hh
vendored
7
src/mem/cache/prefetch/associative_set.hh
vendored
@@ -54,7 +54,7 @@ class AssociativeSet {
|
||||
/** 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;
|
||||
|
||||
@@ -66,11 +66,10 @@ class AssociativeSet {
|
||||
* 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
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
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)
|
||||
|
||||
8
src/mem/cache/prefetch/stride.hh
vendored
8
src/mem/cache/prefetch/stride.hh
vendored
@@ -61,7 +61,9 @@
|
||||
#include "params/StridePrefetcherHashedSetAssociative.hh"
|
||||
|
||||
class BaseIndexingPolicy;
|
||||
class BaseReplacementPolicy;
|
||||
namespace ReplacementPolicy {
|
||||
class Base;
|
||||
}
|
||||
struct StridePrefetcherParams;
|
||||
|
||||
namespace Prefetcher {
|
||||
@@ -107,11 +109,11 @@ class Stride : public Queued
|
||||
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)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2018 Inria
|
||||
# Copyright (c) 2018-2020 Inria
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,31 +31,32 @@ from m5.SimObject import SimObject
|
||||
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")
|
||||
|
||||
@@ -64,17 +65,17 @@ class LIPRP(BIPRP):
|
||||
|
||||
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,
|
||||
@@ -91,11 +92,11 @@ class NRURP(BRRIPRP):
|
||||
|
||||
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"
|
||||
|
||||
23
src/mem/cache/replacement_policies/base.hh
vendored
23
src/mem/cache/replacement_policies/base.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,26 +40,17 @@
|
||||
*/
|
||||
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.
|
||||
@@ -102,4 +93,6 @@ class BaseReplacementPolicy : public SimObject
|
||||
virtual std::shared_ptr<ReplacementData> instantiateEntry() = 0;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
|
||||
|
||||
16
src/mem/cache/replacement_policies/bip_rp.cc
vendored
16
src/mem/cache/replacement_policies/bip_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,13 +34,15 @@
|
||||
#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);
|
||||
@@ -54,8 +56,10 @@ BIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
}
|
||||
|
||||
BIPRP*
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
ReplacementPolicy::BIP*
|
||||
BIPRPParams::create()
|
||||
{
|
||||
return new BIPRP(this);
|
||||
return new ReplacementPolicy::BIP(this);
|
||||
}
|
||||
|
||||
21
src/mem/cache/replacement_policies/bip_rp.hh
vendored
21
src/mem/cache/replacement_policies/bip_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,7 +46,9 @@
|
||||
|
||||
struct BIPRPParams;
|
||||
|
||||
class BIPRP : public LRURP
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class BIP : public LRU
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
@@ -56,18 +58,9 @@ class BIPRP : public LRURP
|
||||
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.
|
||||
@@ -80,4 +73,6 @@ class BIPRP : public LRURP
|
||||
override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BIP_RP_HH__
|
||||
|
||||
26
src/mem/cache/replacement_policies/brrip_rp.cc
vendored
26
src/mem/cache/replacement_policies/brrip_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,15 +35,17 @@
|
||||
#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 =
|
||||
@@ -54,7 +56,7 @@ const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -70,7 +72,7 @@ BRRIPRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -88,7 +90,7 @@ BRRIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -137,13 +139,15 @@ BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
21
src/mem/cache/replacement_policies/brrip_rp.hh
vendored
21
src/mem/cache/replacement_policies/brrip_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -57,7 +57,9 @@
|
||||
|
||||
struct BRRIPRPParams;
|
||||
|
||||
class BRRIPRP : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class BRRIP : public Base
|
||||
{
|
||||
protected:
|
||||
/** BRRIP-specific implementation of replacement data. */
|
||||
@@ -106,18 +108,9 @@ class BRRIPRP : public BaseReplacementPolicy
|
||||
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.
|
||||
@@ -162,4 +155,6 @@ class BRRIPRP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
|
||||
|
||||
24
src/mem/cache/replacement_policies/fifo_rp.cc
vendored
24
src/mem/cache/replacement_policies/fifo_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,13 +34,15 @@
|
||||
#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
|
||||
@@ -49,13 +51,13 @@ const
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -63,7 +65,7 @@ FIFORP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -84,13 +86,15 @@ FIFORP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
21
src/mem/cache/replacement_policies/fifo_rp.hh
vendored
21
src/mem/cache/replacement_policies/fifo_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,7 +41,9 @@
|
||||
|
||||
struct FIFORPParams;
|
||||
|
||||
class FIFORP : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class FIFO : public Base
|
||||
{
|
||||
protected:
|
||||
/** FIFO-specific implementation of replacement data. */
|
||||
@@ -57,18 +59,9 @@ class FIFORP : public BaseReplacementPolicy
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -114,4 +107,6 @@ class FIFORP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_FIFO_RP_HH__
|
||||
|
||||
24
src/mem/cache/replacement_policies/lfu_rp.cc
vendored
24
src/mem/cache/replacement_policies/lfu_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,13 +33,15 @@
|
||||
|
||||
#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
|
||||
@@ -47,21 +49,21 @@ const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -82,13 +84,15 @@ LFURP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
21
src/mem/cache/replacement_policies/lfu_rp.hh
vendored
21
src/mem/cache/replacement_policies/lfu_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,7 +41,9 @@
|
||||
|
||||
struct LFURPParams;
|
||||
|
||||
class LFURP : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class LFU : public Base
|
||||
{
|
||||
protected:
|
||||
/** LFU-specific implementation of replacement data. */
|
||||
@@ -57,18 +59,9 @@ class LFURP : public BaseReplacementPolicy
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -114,4 +107,6 @@ class LFURP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_LFU_RP_HH__
|
||||
|
||||
24
src/mem/cache/replacement_policies/lru_rp.cc
vendored
24
src/mem/cache/replacement_policies/lru_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,13 +34,15 @@
|
||||
#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
|
||||
@@ -49,7 +51,7 @@ const
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -57,7 +59,7 @@ LRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -65,7 +67,7 @@ LRURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -86,13 +88,15 @@ LRURP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
21
src/mem/cache/replacement_policies/lru_rp.hh
vendored
21
src/mem/cache/replacement_policies/lru_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,7 +39,9 @@
|
||||
|
||||
struct LRURPParams;
|
||||
|
||||
class LRURP : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class LRU : public Base
|
||||
{
|
||||
protected:
|
||||
/** LRU-specific implementation of replacement data. */
|
||||
@@ -55,18 +57,9 @@ class LRURP : public BaseReplacementPolicy
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -112,4 +105,6 @@ class LRURP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_LRU_RP_HH__
|
||||
|
||||
24
src/mem/cache/replacement_policies/mru_rp.cc
vendored
24
src/mem/cache/replacement_policies/mru_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,13 +34,15 @@
|
||||
#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
|
||||
@@ -49,7 +51,7 @@ const
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -57,7 +59,7 @@ MRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -65,7 +67,7 @@ MRURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -91,13 +93,15 @@ MRURP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
21
src/mem/cache/replacement_policies/mru_rp.hh
vendored
21
src/mem/cache/replacement_policies/mru_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,7 +41,9 @@
|
||||
|
||||
struct MRURPParams;
|
||||
|
||||
class MRURP : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class MRU : public Base
|
||||
{
|
||||
protected:
|
||||
/** MRU-specific implementation of replacement data. */
|
||||
@@ -57,18 +59,9 @@ class MRURP : public BaseReplacementPolicy
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -114,4 +107,6 @@ class MRURP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_MRU_RP_HH__
|
||||
|
||||
24
src/mem/cache/replacement_policies/random_rp.cc
vendored
24
src/mem/cache/replacement_policies/random_rp.cc
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,13 +34,15 @@
|
||||
#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
|
||||
@@ -49,12 +51,12 @@ const
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -62,7 +64,7 @@ RandomRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -85,13 +87,15 @@ RandomRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
23
src/mem/cache/replacement_policies/random_rp.hh
vendored
23
src/mem/cache/replacement_policies/random_rp.hh
vendored
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,10 +39,12 @@
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
@@ -58,18 +60,9 @@ class RandomRP : public BaseReplacementPolicy
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -115,4 +108,6 @@ class RandomRP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_RANDOM_RP_HH__
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,12 +34,16 @@
|
||||
|
||||
#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
|
||||
@@ -71,7 +75,7 @@ class ReplaceableEntry
|
||||
* 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,27 +32,29 @@
|
||||
|
||||
#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>(
|
||||
@@ -60,10 +62,10 @@ SecondChanceRP::invalidate(
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -71,10 +73,10 @@ SecondChanceRP::touch(const std::shared_ptr<ReplacementData>&
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -82,7 +84,7 @@ SecondChanceRP::reset(const std::shared_ptr<ReplacementData>&
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -106,7 +108,7 @@ SecondChanceRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
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 =
|
||||
@@ -126,13 +128,15 @@ SecondChanceRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,7 +43,9 @@
|
||||
|
||||
struct SecondChanceRPParams;
|
||||
|
||||
class SecondChanceRP : public FIFORP
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class SecondChance : public FIFO
|
||||
{
|
||||
protected:
|
||||
/** Second-Chance-specific implementation of replacement data. */
|
||||
@@ -52,7 +54,7 @@ class SecondChanceRP : public FIFORP
|
||||
/**
|
||||
* 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;
|
||||
|
||||
@@ -71,18 +73,9 @@ class SecondChanceRP : public FIFORP
|
||||
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.
|
||||
@@ -130,4 +123,6 @@ class SecondChanceRP : public FIFORP
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_SECOND_CHANCE_RP_HH__
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "base/logging.hh"
|
||||
#include "params/TreePLRURP.hh"
|
||||
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
/**
|
||||
* Get the index of the parent of the given indexed subtree.
|
||||
*
|
||||
@@ -89,22 +91,21 @@ isRightSubtree(const uint64_t index)
|
||||
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
|
||||
@@ -130,7 +131,7 @@ TreePLRURP::invalidate(
|
||||
}
|
||||
|
||||
void
|
||||
TreePLRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data)
|
||||
TreePLRU::touch(const std::shared_ptr<ReplacementData>& replacement_data)
|
||||
const
|
||||
{
|
||||
// Cast replacement data
|
||||
@@ -156,7 +157,7 @@ const
|
||||
}
|
||||
|
||||
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
|
||||
@@ -164,7 +165,7 @@ const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -192,7 +193,7 @@ TreePLRURP::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
std::shared_ptr<ReplacementData>
|
||||
TreePLRURP::instantiateEntry()
|
||||
TreePLRU::instantiateEntry()
|
||||
{
|
||||
// Generate a tree instance every numLeaves created
|
||||
if (count % numLeaves == 0) {
|
||||
@@ -210,8 +211,10 @@ TreePLRURP::instantiateEntry()
|
||||
return std::shared_ptr<ReplacementData>(treePLRUReplData);
|
||||
}
|
||||
|
||||
TreePLRURP*
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
ReplacementPolicy::TreePLRU*
|
||||
TreePLRURPParams::create()
|
||||
{
|
||||
return new TreePLRURP(this);
|
||||
return new ReplacementPolicy::TreePLRU(this);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2018-2020 Inria
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -77,7 +77,9 @@
|
||||
|
||||
struct TreePLRURPParams;
|
||||
|
||||
class TreePLRURP : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class TreePLRU : public Base
|
||||
{
|
||||
private:
|
||||
/**
|
||||
@@ -149,18 +151,9 @@ class TreePLRURP : public BaseReplacementPolicy
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -212,4 +205,6 @@ class TreePLRURP : public BaseReplacementPolicy
|
||||
std::shared_ptr<ReplacementData> instantiateEntry() override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_TREE_PLRU_RP_HH__
|
||||
|
||||
@@ -38,19 +38,15 @@
|
||||
#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)->
|
||||
@@ -58,7 +54,7 @@ WeightedLRUPolicy::touch(const std::shared_ptr<ReplacementData>&
|
||||
}
|
||||
|
||||
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)->
|
||||
@@ -68,7 +64,7 @@ WeightedLRUPolicy::touch(const std::shared_ptr<ReplacementData>&
|
||||
}
|
||||
|
||||
ReplaceableEntry*
|
||||
WeightedLRUPolicy::getVictim(const ReplacementCandidates& candidates) const
|
||||
WeightedLRU::getVictim(const ReplacementCandidates& candidates) const
|
||||
{
|
||||
assert(candidates.size() > 0);
|
||||
|
||||
@@ -102,13 +98,13 @@ WeightedLRUPolicy::getVictim(const ReplacementCandidates& candidates) const
|
||||
}
|
||||
|
||||
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
|
||||
@@ -117,10 +113,18 @@ WeightedLRUPolicy::reset(const std::shared_ptr<ReplacementData>&
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@
|
||||
|
||||
struct WeightedLRURPParams;
|
||||
|
||||
class WeightedLRUPolicy : public BaseReplacementPolicy
|
||||
namespace ReplacementPolicy {
|
||||
|
||||
class WeightedLRU : public Base
|
||||
{
|
||||
protected:
|
||||
/** Weighted LRU implementation of replacement data. */
|
||||
@@ -61,8 +63,8 @@ class WeightedLRUPolicy : public BaseReplacementPolicy
|
||||
};
|
||||
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.
|
||||
@@ -109,4 +111,6 @@ class WeightedLRUPolicy : public BaseReplacementPolicy
|
||||
candidates) const override;
|
||||
};
|
||||
|
||||
} // namespace ReplacementPolicy
|
||||
|
||||
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_WEIGHTED_LRU_RP_HH__
|
||||
|
||||
2
src/mem/cache/tags/base_set_assoc.hh
vendored
2
src/mem/cache/tags/base_set_assoc.hh
vendored
@@ -82,7 +82,7 @@ class BaseSetAssoc : public BaseTags
|
||||
const bool sequentialAccess;
|
||||
|
||||
/** Replacement policy */
|
||||
BaseReplacementPolicy *replacementPolicy;
|
||||
ReplacementPolicy::Base *replacementPolicy;
|
||||
|
||||
public:
|
||||
/** Convenience typedef. */
|
||||
|
||||
6
src/mem/cache/tags/sector_tags.hh
vendored
6
src/mem/cache/tags/sector_tags.hh
vendored
@@ -44,7 +44,9 @@
|
||||
#include "mem/packet.hh"
|
||||
#include "params/SectorTags.hh"
|
||||
|
||||
class BaseReplacementPolicy;
|
||||
namespace ReplacementPolicy {
|
||||
class Base;
|
||||
}
|
||||
class ReplaceableEntry;
|
||||
|
||||
/**
|
||||
@@ -71,7 +73,7 @@ class SectorTags : public BaseTags
|
||||
const bool sequentialAccess;
|
||||
|
||||
/** Replacement policy */
|
||||
BaseReplacementPolicy *replacementPolicy;
|
||||
ReplacementPolicy::Base *replacementPolicy;
|
||||
|
||||
/** Number of data blocks per sector. */
|
||||
const unsigned numBlocksPerSector;
|
||||
|
||||
@@ -82,7 +82,7 @@ CacheMemory::CacheMemory(const Params *p)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,8 @@ CacheMemory::setMRU(Addr address, int occupancy)
|
||||
// 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);
|
||||
|
||||
@@ -64,7 +64,7 @@ class CacheMemory : public SimObject
|
||||
{
|
||||
public:
|
||||
typedef RubyCacheParams Params;
|
||||
typedef std::shared_ptr<ReplacementData> ReplData;
|
||||
typedef std::shared_ptr<ReplacementPolicy::ReplacementData> ReplData;
|
||||
CacheMemory(const Params *p);
|
||||
~CacheMemory();
|
||||
|
||||
@@ -200,11 +200,8 @@ class CacheMemory : public SimObject
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user