From 984eb871ee4ccb58fdea1bd4161a5804b36e94ec Mon Sep 17 00:00:00 2001 From: Wei Song Date: Sun, 24 Mar 2024 15:11:26 +0800 Subject: [PATCH 1/3] make the pointer to policy a smart pointer --- cache/coherence.hpp | 30 ++++++++++++++++-------------- cache/exclusive.hpp | 8 ++++---- cache/memory.hpp | 3 +-- cache/mirage.hpp | 2 +- util/cache_type.hpp | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/cache/coherence.hpp b/cache/coherence.hpp index f5503ee..1df668c 100644 --- a/cache/coherence.hpp +++ b/cache/coherence.hpp @@ -5,6 +5,7 @@ #include "cache/coh_policy.hpp" #include "cache/slicehash.hpp" #include +#include class OuterCohPortBase; class InnerCohPortBase; @@ -16,6 +17,8 @@ class CoherentCacheBase; typedef OuterCohPortBase CohClientBase; typedef InnerCohPortBase CohMasterBase; +typedef std::shared_ptr policy_ptr; + ///////////////////////////////// // Base interface for outer ports @@ -26,13 +29,13 @@ class OuterCohPortBase InnerCohPortBase *inner; // inner port for probe when sync CohMasterBase *coh; // hook up with the coherence hub int32_t coh_id; // the identifier used in locating this cache client by the coherence master - CohPolicyBase *policy; // the coherence policy + policy_ptr policy; // the coherence policy public: - OuterCohPortBase(CohPolicyBase *policy) : policy(policy) {} + OuterCohPortBase(policy_ptr policy) : policy(policy) {} virtual ~OuterCohPortBase() {} - void connect(CohMasterBase *h, std::pair info) { coh = h; coh_id = info.first; policy->connect(info.second); } + void connect(CohMasterBase *h, std::pair info) { coh = h; coh_id = info.first; policy->connect(info.second.get()); } virtual void acquire_req(uint64_t addr, CMMetadataBase *meta, CMDataBase *data, coh_cmd_t cmd, uint64_t *delay) = 0; virtual void writeback_req(uint64_t addr, CMMetadataBase *meta, CMDataBase *data, coh_cmd_t cmd, uint64_t *delay) = 0; @@ -52,12 +55,11 @@ class InnerCohPortBase CacheBase *cache; // reverse pointer for the cache parent OuterCohPortBase *outer; // outer port for writeback when replace std::vector coh; // hook up with the inner caches, indexed by vector index - CohPolicyBase *policy; // the coherence policy + policy_ptr policy; // the coherence policy public: - InnerCohPortBase(CohPolicyBase *policy) : policy(policy) {} - virtual ~InnerCohPortBase() { delete policy; } + InnerCohPortBase(policy_ptr policy) : policy(policy) {} - std::pair connect(CohClientBase *c, bool uncached = false) { + std::pair connect(CohClientBase *c, bool uncached = false) { if(uncached) { return std::make_pair(-1, policy); } else { @@ -79,7 +81,7 @@ class InnerCohPortBase class OuterCohPortUncached : public OuterCohPortBase { public: - OuterCohPortUncached(CohPolicyBase *policy) : OuterCohPortBase(policy) {} + OuterCohPortUncached(policy_ptr policy) : OuterCohPortBase(policy) {} virtual ~OuterCohPortUncached() {} virtual void acquire_req(uint64_t addr, CMMetadataBase *meta, CMDataBase *data, coh_cmd_t outer_cmd, uint64_t *delay) { @@ -110,7 +112,7 @@ class OuterCohPortT : public OPUC using OuterCohPortBase::inner; using OPUC::writeback_req; public: - OuterCohPortT(CohPolicyBase *policy) : OPUC(policy) {} + OuterCohPortT(policy_ptr policy) : OPUC(policy) {} virtual ~OuterCohPortT() {} virtual std::pair probe_resp(uint64_t addr, CMMetadataBase *meta_outer, CMDataBase *data_outer, coh_cmd_t outer_cmd, uint64_t *delay) { @@ -145,7 +147,7 @@ typedef OuterCohPortT OuterCohPort; class InnerCohPortUncached : public InnerCohPortBase { public: - InnerCohPortUncached(CohPolicyBase *policy) : InnerCohPortBase(policy) {} + InnerCohPortUncached(policy_ptr policy) : InnerCohPortBase(policy) {} virtual ~InnerCohPortUncached() {} virtual void acquire_resp(uint64_t addr, CMDataBase *data_inner, CMMetadataBase *meta_inner, coh_cmd_t cmd, uint64_t *delay) { @@ -263,7 +265,7 @@ class InnerCohPortT : public IPUC protected: using IPUC::coh; public: - InnerCohPortT(CohPolicyBase *policy) : IPUC(policy) {} + InnerCohPortT(policy_ptr policy) : IPUC(policy) {} virtual ~InnerCohPortT() {} virtual std::pair probe_req(uint64_t addr, CMMetadataBase *meta, CMDataBase *data, coh_cmd_t cmd, uint64_t *delay) { @@ -285,7 +287,7 @@ typedef InnerCohPortT InnerCohPort; // interface with the processing core is a special InnerCohPort class CoreInterface : public InnerCohPortUncached { public: - CoreInterface(CohPolicyBase *policy) : InnerCohPortUncached(policy) {} + CoreInterface(policy_ptr policy) : InnerCohPortUncached(policy) {} virtual ~CoreInterface() {} uint64_t normalize(uint64_t addr) const { return addr & ~0x3full; } @@ -357,7 +359,7 @@ class CoherentCacheBase OuterCohPortBase *outer; // coherence outer port, nullptr if last level InnerCohPortBase *inner; // coherence inner port, always has inner - CoherentCacheBase(CacheBase *cache, OuterCohPortBase *outer, InnerCohPortBase *inner, CohPolicyBase *policy, std::string name) + CoherentCacheBase(CacheBase *cache, OuterCohPortBase *outer, InnerCohPortBase *inner, policy_ptr policy, std::string name) : name(name), cache(cache), outer(outer), inner(inner) { // deferred assignment for the reverse pointer to cache @@ -385,7 +387,7 @@ template probe_resp(uint64_t addr, CMMetadataBase *meta_outer, CMDataBase *data_outer, coh_cmd_t outer_cmd, uint64_t *delay) { @@ -577,7 +577,7 @@ class ExclusiveOuterCohPortDirectoryT : public OPUC using OPUC::inner; using OPUC::policy; public: - ExclusiveOuterCohPortDirectoryT(CohPolicyBase *policy) : OPUC(policy) {} + ExclusiveOuterCohPortDirectoryT(policy_ptr policy) : OPUC(policy) {} virtual ~ExclusiveOuterCohPortDirectoryT() {} virtual std::pair probe_resp(uint64_t addr, CMMetadataBase *meta_outer, CMDataBase *data_outer, coh_cmd_t outer_cmd, uint64_t *delay) { diff --git a/cache/memory.hpp b/cache/memory.hpp index fe349ed..f5fb9da 100644 --- a/cache/memory.hpp +++ b/cache/memory.hpp @@ -26,13 +26,12 @@ template SimpleMemoryModel(const std::string &n) : InnerCohPortUncached(nullptr), id(UniqueID::new_id(n)), name(n) { - InnerCohPortBase::policy = new MIPolicy(); + InnerCohPortBase::policy = policy_ptr(new MIPolicy()); CacheMonitorSupport::monitors = new CacheMonitorImp(id); } virtual ~SimpleMemoryModel() { delete CacheMonitorSupport::monitors; - delete InnerCohPortBase::policy; } virtual void acquire_resp(uint64_t addr, CMDataBase *data_inner, CMMetadataBase *meta_inner, coh_cmd_t cmd, uint64_t *delay) { diff --git a/cache/mirage.hpp b/cache/mirage.hpp index c10b30a..442d4c2 100644 --- a/cache/mirage.hpp +++ b/cache/mirage.hpp @@ -237,7 +237,7 @@ template class MirageInnerPortUncached : public InnerCohPortUncached { public: - MirageInnerPortUncached(CohPolicyBase *policy) : InnerCohPortUncached(policy) {} + MirageInnerPortUncached(policy_ptr policy) : InnerCohPortUncached(policy) {} protected: virtual std::tuple replace_line(uint64_t addr, uint64_t *delay) { diff --git a/util/cache_type.hpp b/util/cache_type.hpp index 95609ed..18b6758 100644 --- a/util/cache_type.hpp +++ b/util/cache_type.hpp @@ -13,7 +13,7 @@ template inline std::vector cache_generator(int size, const std::string& name_prefix) { - auto policy = new CPT(); + policy_ptr policy(new CPT()); auto array = std::vector(size); for(int i=0; i 1 ? "-"+std::to_string(i) : "")); return array; From ec056b3e0948ec3437c98f9f98de30deff1da97c Mon Sep 17 00:00:00 2001 From: Wei Song Date: Sun, 24 Mar 2024 15:27:07 +0800 Subject: [PATCH 2/3] delete caches at the end of regression tests --- regression/c1-l1.cpp | 6 +++++- regression/c2-l2-exc-mesi.cpp | 8 +++++++- regression/c2-l2-exc-mi.cpp | 8 +++++++- regression/c2-l2-exc.cpp | 8 +++++++- regression/c2-l2-mesi.cpp | 8 +++++++- regression/c2-l2-mirage.cpp | 8 +++++++- regression/c2-l2.cpp | 8 +++++++- regression/c4-l3-exc-mesi.cpp | 9 ++++++++- regression/c4-l3-exc.cpp | 9 ++++++++- regression/c4-l3-intel.cpp | 9 ++++++++- regression/c4-l3.cpp | 9 ++++++++- util/regression.hpp | 4 ++++ 12 files changed, 83 insertions(+), 11 deletions(-) diff --git a/regression/c1-l1.cpp b/regression/c1-l1.cpp index bf3fd62..9fed04a 100644 --- a/regression/c1-l1.cpp +++ b/regression/c1-l1.cpp @@ -17,5 +17,9 @@ int main() { mem->attach_monitor(&tracer); RegressionGen<1, false, false, AddrN, 0, Data64B> tgen; - return tgen.run(TestN, core, core); + auto rv = tgen.run(TestN, core, core); + + delete_caches(cache); + delete mem; + return rv; } diff --git a/regression/c2-l2-exc-mesi.cpp b/regression/c2-l2-exc-mesi.cpp index 1b5ac78..7f6697f 100644 --- a/regression/c2-l2-exc-mesi.cpp +++ b/regression/c2-l2-exc-mesi.cpp @@ -35,5 +35,11 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete l2; + delete mem; + return rv; } diff --git a/regression/c2-l2-exc-mi.cpp b/regression/c2-l2-exc-mi.cpp index 6b44dea..90509f8 100644 --- a/regression/c2-l2-exc-mi.cpp +++ b/regression/c2-l2-exc-mi.cpp @@ -34,5 +34,11 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete l2; + delete mem; + return rv; } diff --git a/regression/c2-l2-exc.cpp b/regression/c2-l2-exc.cpp index 6d7831e..399c4f5 100644 --- a/regression/c2-l2-exc.cpp +++ b/regression/c2-l2-exc.cpp @@ -34,5 +34,11 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete l2; + delete mem; + return rv; } diff --git a/regression/c2-l2-mesi.cpp b/regression/c2-l2-mesi.cpp index e235f70..b4fe040 100644 --- a/regression/c2-l2-mesi.cpp +++ b/regression/c2-l2-mesi.cpp @@ -34,5 +34,11 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete l2; + delete mem; + return rv; } diff --git a/regression/c2-l2-mirage.cpp b/regression/c2-l2-mirage.cpp index 2f2aa29..17b2c39 100644 --- a/regression/c2-l2-mirage.cpp +++ b/regression/c2-l2-mirage.cpp @@ -37,5 +37,11 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete l2; + delete mem; + return rv; } diff --git a/regression/c2-l2.cpp b/regression/c2-l2.cpp index a462a5d..35387b1 100644 --- a/regression/c2-l2.cpp +++ b/regression/c2-l2.cpp @@ -34,5 +34,11 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete l2; + delete mem; + return rv; } diff --git a/regression/c4-l3-exc-mesi.cpp b/regression/c4-l3-exc-mesi.cpp index 2ea1774..61ceae6 100644 --- a/regression/c4-l3-exc-mesi.cpp +++ b/regression/c4-l3-exc-mesi.cpp @@ -41,5 +41,12 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete_caches(l2); + delete l3; + delete mem; + return rv; } diff --git a/regression/c4-l3-exc.cpp b/regression/c4-l3-exc.cpp index 4c61f43..91e1769 100644 --- a/regression/c4-l3-exc.cpp +++ b/regression/c4-l3-exc.cpp @@ -40,5 +40,12 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete_caches(l2); + delete l3; + delete mem; + return rv; } diff --git a/regression/c4-l3-intel.cpp b/regression/c4-l3-intel.cpp index 2beb1d8..da05002 100644 --- a/regression/c4-l3-intel.cpp +++ b/regression/c4-l3-intel.cpp @@ -43,5 +43,12 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete_caches(l2); + delete_caches(l3); + delete mem; + return rv; } diff --git a/regression/c4-l3.cpp b/regression/c4-l3.cpp index e3796b7..5ca3f1e 100644 --- a/regression/c4-l3.cpp +++ b/regression/c4-l3.cpp @@ -40,5 +40,12 @@ int main() { mem->attach_monitor(&tracer); RegressionGen tgen; - return tgen.run(TestN, core_inst, core_data); + auto rv = tgen.run(TestN, core_inst, core_data); + + delete_caches(l1d); + delete_caches(l1i); + delete_caches(l2); + delete l3; + delete mem; + return rv; } diff --git a/util/regression.hpp b/util/regression.hpp index 8821e3c..6dc6bf7 100644 --- a/util/regression.hpp +++ b/util/regression.hpp @@ -121,4 +121,8 @@ class RegressionGen } }; +inline void delete_caches(std::vector &caches) { + for(auto c : caches) delete c; +} + #endif From 4d6bbd490cbbd4905a0133eb9084216c13e1bb44 Mon Sep 17 00:00:00 2001 From: Wei Song Date: Sun, 24 Mar 2024 15:27:26 +0800 Subject: [PATCH 3/3] remove unused typedefs --- cache/exclusive.hpp | 2 -- cache/mirage.hpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/cache/exclusive.hpp b/cache/exclusive.hpp index 1b3875b..6a43e31 100644 --- a/cache/exclusive.hpp +++ b/cache/exclusive.hpp @@ -7,7 +7,6 @@ template requires C_DERIVE(MT, CMMetadataBase) class ExclusiveMSIPolicy : public MSIPolicy // always not L1 { - typedef MSIPolicy PolicyT; protected: using CohPolicyBase::is_fetch_read; using CohPolicyBase::is_fetch_write; @@ -83,7 +82,6 @@ class ExclusiveMSIPolicy : public MSIPolicy // always not L template requires C_DERIVE(MT, MetadataDirectoryBase) && EnDir class ExclusiveMESIPolicy : public ExclusiveMSIPolicy { - typedef ExclusiveMSIPolicy PolicyT; protected: using CohPolicyBase::is_fetch_read; using CohPolicyBase::is_fetch_write; diff --git a/cache/mirage.hpp b/cache/mirage.hpp index 442d4c2..55185ad 100644 --- a/cache/mirage.hpp +++ b/cache/mirage.hpp @@ -70,8 +70,6 @@ template class MirageMSIPolicy : public MSIPolicy // always LLC, always not L1 { typedef MSIPolicy PolicyT; -protected: - using PolicyT::outer; public: MirageMSIPolicy() : MSIPolicy() {} virtual ~MirageMSIPolicy() {}