From 57dc1b4d691470d620a10e1f85f3ba3a2aab0ec6 Mon Sep 17 00:00:00 2001 From: hanjinchi <1104722561@qq.com> Date: Mon, 23 Sep 2024 14:09:39 +0800 Subject: [PATCH] Add some checks for whether it is L1 in the policy to optimize performance --- cache/coh_policy.hpp | 8 ++++---- cache/exclusive.hpp | 20 +++++++++++++------- cache/mi.hpp | 18 +++++++++++++----- cache/msi.hpp | 22 +++++++++++++--------- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/cache/coh_policy.hpp b/cache/coh_policy.hpp index a441110..19b1691 100644 --- a/cache/coh_policy.hpp +++ b/cache/coh_policy.hpp @@ -118,10 +118,10 @@ struct CohPolicyBase { } } - // writeback due to conflict, probe, flush - static __always_inline std::pair writeback_need_sync(const CMMetadataBase *meta) { - return std::make_pair(true, coh::cmd_for_probe_release()); - } + // // writeback due to conflict, probe, flush + // static __always_inline std::pair writeback_need_sync(const CMMetadataBase *meta) { + // return std::make_pair(true, coh::cmd_for_probe_release()); + // } // static __always_inline std::pair writeback_need_writeback(const CMMetadataBase *meta); diff --git a/cache/exclusive.hpp b/cache/exclusive.hpp index 960253e..c2d5e9e 100644 --- a/cache/exclusive.hpp +++ b/cache/exclusive.hpp @@ -8,8 +8,10 @@ template requires struct ExclusiveMSIPolicy : public MSIPolicy // always not L1 { static __always_inline std::pair access_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) { - if(coh::is_fetch_write(cmd)) return std::make_pair(true, coh::cmd_for_probe_release(cmd.id)); - else return std::make_pair(true, coh::cmd_for_probe_downgrade(cmd.id)); + if constexpr (!isL1){ + if(coh::is_fetch_write(cmd)) return std::make_pair(true, coh::cmd_for_probe_release(cmd.id)); + else return std::make_pair(true, coh::cmd_for_probe_downgrade(cmd.id)); + } else return std::make_pair(false, coh::cmd_for_null()); } static __always_inline void meta_after_grant(coh_cmd_t cmd, CMMetadataBase *meta, CMMetadataBase *meta_inner) { // after grant to inner @@ -34,7 +36,8 @@ struct ExclusiveMSIPolicy : public MSIPolicy // alway static __always_inline std::pair writeback_need_sync(const CMMetadataBase *meta) { // for exclusive cache, no sync is needed for normal way, always sync for extended way - return meta->is_extend() ? std::make_pair(true, coh::cmd_for_probe_release()) : std::make_pair(false, coh::cmd_for_null()); + if constexpr (isL1) return std::make_pair(false, coh::cmd_for_null()); + else return meta->is_extend() ? std::make_pair(true, coh::cmd_for_probe_release()) : std::make_pair(false, coh::cmd_for_null()); } static __always_inline void meta_after_release(coh_cmd_t cmd, CMMetadataBase *meta, CMMetadataBase* meta_inner) { @@ -49,7 +52,8 @@ struct ExclusiveMSIPolicy : public MSIPolicy // alway static __always_inline std::pair release_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta, const CMMetadataBase* meta_inner) { // if the inner cache is not exclusive (M/O/E), probe to see whether there are other copies - return std::make_pair(!meta_inner->allow_write(), coh::cmd_for_probe_writeback(cmd.id)); + if constexpr (isL1) return std::make_pair(false, coh::cmd_for_null()); + else return std::make_pair(!meta_inner->allow_write(), coh::cmd_for_probe_writeback(cmd.id)); } static __always_inline std::pair inner_need_release() { @@ -58,9 +62,11 @@ struct ExclusiveMSIPolicy : public MSIPolicy // alway static __always_inline std::pair flush_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) { assert(uncached); - if(coh::is_evict(cmd)) return std::make_pair(true, coh::cmd_for_probe_release()); - else if(meta && meta->is_shared()) return std::make_pair(false, coh::cmd_for_null()); - else return std::make_pair(true, coh::cmd_for_probe_writeback()); + if constexpr (!isL1){ + if(coh::is_evict(cmd)) return std::make_pair(true, coh::cmd_for_probe_release()); + else if(meta && meta->is_shared()) return std::make_pair(false, coh::cmd_for_null()); + else return std::make_pair(true, coh::cmd_for_probe_writeback()); + } else return std::make_pair(false, coh::cmd_for_null()); } }; diff --git a/cache/mi.hpp b/cache/mi.hpp index 0a4c08d..400e438 100644 --- a/cache/mi.hpp +++ b/cache/mi.hpp @@ -26,7 +26,8 @@ struct MIPolicy : public CohPolicyBase static __always_inline coh_cmd_t cmd_for_outer_acquire(coh_cmd_t cmd) { return coh::cmd_for_write(); } static __always_inline std::pair access_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) { - return std::make_pair(true, coh::cmd_for_probe_release(cmd.id)); + if constexpr (isL1) return std::make_pair(false, coh::cmd_for_null()); + else return std::make_pair(true, coh::cmd_for_probe_release(cmd.id)); } static __always_inline std::tuple access_need_promote(coh_cmd_t cmd, const CMMetadataBase *meta) { @@ -74,10 +75,17 @@ struct MIPolicy : public CohPolicyBase static __always_inline std::pair flush_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) { assert(uncached); - if(meta){ - if(coh::is_evict(cmd)) return std::make_pair(true, coh::cmd_for_probe_release()); - else return std::make_pair(true, coh::cmd_for_probe_writeback()); - } else return std::make_pair(false, coh::cmd_for_null()); + if constexpr (!isL1){ + if(meta){ + if(coh::is_evict(cmd)) return std::make_pair(true, coh::cmd_for_probe_release()); + else return std::make_pair(true, coh::cmd_for_probe_writeback()); + } else return std::make_pair(false, coh::cmd_for_null()); + } else return std::make_pair(false, coh::cmd_for_null()); + } + + static __always_inline std::pair writeback_need_sync(const CMMetadataBase *meta) { + if constexpr (isL1) return std::make_pair(false, coh::cmd_for_null()); + else return std::make_pair(true, coh::cmd_for_probe_release()); } }; diff --git a/cache/msi.hpp b/cache/msi.hpp index 8d1bb89..c683bc6 100644 --- a/cache/msi.hpp +++ b/cache/msi.hpp @@ -30,10 +30,12 @@ struct MSIPolicy : public MIPolicy } static __always_inline std::pair access_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) { - if(coh::is_release(cmd)) return std::make_pair(false, coh::cmd_for_null()); // for inclusive cache, release is always hit and exclusive/modified - if(coh::is_fetch_write(cmd)) return std::make_pair(true, coh::cmd_for_probe_release(cmd.id)); - if(meta->is_shared()) return std::make_pair(false, coh::cmd_for_null()); - return std::make_pair(true, coh::cmd_for_probe_downgrade(cmd.id)); + if constexpr (!isL1){ + if(coh::is_release(cmd)) return std::make_pair(false, coh::cmd_for_null()); // for inclusive cache, release is always hit and exclusive/modified + if(coh::is_fetch_write(cmd)) return std::make_pair(true, coh::cmd_for_probe_release(cmd.id)); + if(meta->is_shared()) return std::make_pair(false, coh::cmd_for_null()); + return std::make_pair(true, coh::cmd_for_probe_downgrade(cmd.id)); + } else return std::make_pair(false, coh::cmd_for_null()); } static __always_inline std::tuple access_need_promote(coh_cmd_t cmd, const CMMetadataBase *meta) { @@ -95,11 +97,13 @@ struct MSIPolicy : public MIPolicy static __always_inline std::pair flush_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) { assert(uncached); - if(meta) { - if(coh::is_evict(cmd)) return std::make_pair(true, coh::cmd_for_probe_release()); - else if(meta->is_shared()) return std::make_pair(false, coh::cmd_for_null()); - else return std::make_pair(true, coh::cmd_for_probe_writeback()); - } else return std::make_pair(false, coh::cmd_for_null()); + if constexpr (!isL1){ + if(meta) { + if(coh::is_evict(cmd)) return std::make_pair(true, coh::cmd_for_probe_release()); + else if(meta->is_shared()) return std::make_pair(false, coh::cmd_for_null()); + else return std::make_pair(true, coh::cmd_for_probe_writeback()); + } else return std::make_pair(false, coh::cmd_for_null()); + } else return std::make_pair(false, coh::cmd_for_null()); } };