Skip to content

Commit

Permalink
Add some checks for whether it is L1 in the policy to optimize perfor…
Browse files Browse the repository at this point in the history
…mance
  • Loading branch information
HanJinChi committed Sep 23, 2024
1 parent f79f76a commit 57dc1b4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
8 changes: 4 additions & 4 deletions cache/coh_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ struct CohPolicyBase {
}
}

// writeback due to conflict, probe, flush
static __always_inline std::pair<bool, coh_cmd_t> 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<bool, coh_cmd_t> writeback_need_sync(const CMMetadataBase *meta) {
// return std::make_pair(true, coh::cmd_for_probe_release());
// }

// static __always_inline std::pair<bool, coh_cmd_t> writeback_need_writeback(const CMMetadataBase *meta);

Expand Down
20 changes: 13 additions & 7 deletions cache/exclusive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ template<bool isL1, bool uncached, typename Outer, bool EnDir = false> requires
struct ExclusiveMSIPolicy : public MSIPolicy<false, uncached, Outer> // always not L1
{
static __always_inline std::pair<bool, coh_cmd_t> 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
Expand All @@ -34,7 +36,8 @@ struct ExclusiveMSIPolicy : public MSIPolicy<false, uncached, Outer> // alway

static __always_inline std::pair<bool, coh_cmd_t> 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) {
Expand All @@ -49,7 +52,8 @@ struct ExclusiveMSIPolicy : public MSIPolicy<false, uncached, Outer> // alway

static __always_inline std::pair<bool, coh_cmd_t> 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<bool, coh_cmd_t> inner_need_release() {
Expand All @@ -58,9 +62,11 @@ struct ExclusiveMSIPolicy : public MSIPolicy<false, uncached, Outer> // alway

static __always_inline std::pair<bool, coh_cmd_t> 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());
}
};

Expand Down
18 changes: 13 additions & 5 deletions cache/mi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, coh_cmd_t> 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<bool, bool, coh_cmd_t> access_need_promote(coh_cmd_t cmd, const CMMetadataBase *meta) {
Expand Down Expand Up @@ -74,10 +75,17 @@ struct MIPolicy : public CohPolicyBase

static __always_inline std::pair<bool, coh_cmd_t> 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<bool, coh_cmd_t> 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());
}

};
Expand Down
22 changes: 13 additions & 9 deletions cache/msi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ struct MSIPolicy : public MIPolicy<isL1, uncached, Outer>
}

static __always_inline std::pair<bool, coh_cmd_t> 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<bool, bool, coh_cmd_t> access_need_promote(coh_cmd_t cmd, const CMMetadataBase *meta) {
Expand Down Expand Up @@ -95,11 +97,13 @@ struct MSIPolicy : public MIPolicy<isL1, uncached, Outer>

static __always_inline std::pair<bool, coh_cmd_t> 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());
}
};

Expand Down

0 comments on commit 57dc1b4

Please sign in to comment.