Skip to content

Commit

Permalink
do replace update before performance hooking
Browse files Browse the repository at this point in the history
  • Loading branch information
wsong83 committed Dec 3, 2024
1 parent bc20546 commit 581d731
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
24 changes: 12 additions & 12 deletions cache/coherence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,23 @@ class OuterCohPortT : public OPUC<Policy, EnMT, Extra...>
if(sync.first) {
auto [phit, pwb] = OuterCohPortBase::inner->probe_req(addr, meta, data, sync.second, delay);
if(pwb) {
cache->hook_write(addr, ai, s, w, true, meta, data, delay);
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay);
}
}

// now we should be able to safely operate on the cache line
if constexpr (EnMT) {assert(meta->match(addr)); meta_outer->lock(); }
if((writeback = Policy::probe_need_writeback(outer_cmd, meta))) { if(data_outer) data_outer->copy(data); } // writeback if dirty
Policy::meta_after_probe(outer_cmd, meta, meta_outer, coh_id, writeback); // alway update meta
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);
cache->replace_manage(ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0));
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);
if constexpr (EnMT) { meta_outer->unlock(); meta->unlock(); cache->reset_mt_state(ai, s, XactPrio::probe); }
} else {
if constexpr (EnMT) meta_outer->lock();
Policy::meta_after_probe(outer_cmd, meta, meta_outer, coh_id, writeback); // alway update meta
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);
cache->replace_manage(ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0));
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);
if constexpr (EnMT) meta_outer->unlock();
}
return std::make_pair(hit, writeback);
Expand All @@ -227,8 +227,8 @@ class InnerCohPortUncached : public InnerCohPortBase

if (data_inner && data) data_inner->copy(data);
Policy::meta_after_grant(cmd, meta, meta_inner);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);
if(!act_as_prefetch || !hit) cache->replace_read(ai, s, w, act_as_prefetch);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);
finish_record(addr, coh::cmd_for_finish(cmd.id), !hit, meta, ai, s);
if(cmd.id == -1) finish_resp(addr, coh::cmd_for_finish(cmd.id));
}
Expand All @@ -255,16 +255,16 @@ class InnerCohPortUncached : public InnerCohPortBase
if constexpr (EnMT && Policy::sync_need_lock()) cache->set_mt_state(ai, s, XactPrio::sync);
auto [phit, pwb] = probe_req(addr, meta, data, sync.second, delay); // sync if necessary
if(pwb){
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
}
if constexpr (EnMT && Policy::sync_need_lock()) cache->reset_mt_state(ai, s, XactPrio::sync);
}
auto writeback = Policy::writeback_need_writeback(meta);
if(writeback.first) outer->writeback_req(addr, meta, data, writeback.second, delay); // writeback if dirty
Policy::meta_after_evict(meta);
cache->hook_manage(addr, ai, s, w, true, 1, writeback.first, meta, data, delay);
cache->replace_manage(ai, s, w, true, 1);
cache->hook_manage(addr, ai, s, w, true, 1, writeback.first, meta, data, delay);
}

virtual std::tuple<bool, CMMetadataBase *, CMDataBase *, uint32_t, uint32_t, uint32_t>
Expand Down Expand Up @@ -315,8 +315,8 @@ class InnerCohPortUncached : public InnerCohPortBase
if constexpr (EnMT && Policy::sync_need_lock()) { assert(prio < XactPrio::sync); cache->set_mt_state(ai, s, XactPrio::sync);}
auto [phit, pwb] = probe_req(addr, meta, data, sync.second, delay); // sync if necessary
if(pwb){
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
}
if constexpr (EnMT && Policy::sync_need_lock()) cache->reset_mt_state(ai, s, XactPrio::sync);
}
Expand All @@ -336,8 +336,8 @@ class InnerCohPortUncached : public InnerCohPortBase
if(data_inner) data->copy(data_inner);
Policy::meta_after_release(cmd, meta, meta_inner);
assert(meta_inner); // assume meta_inner is valid for all writebacks
cache->hook_write(addr, ai, s, w, hit, meta, data, delay);
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, hit, meta, data, delay);
if constexpr (EnMT) { meta->unlock(); cache->reset_mt_state(ai, s, XactPrio::release); }
}

Expand All @@ -353,8 +353,8 @@ class InnerCohPortUncached : public InnerCohPortBase
if constexpr (EnMT && Policy::sync_need_lock()) cache->set_mt_state(ai, s, XactPrio::sync);
auto [phit, pwb] = probe_req(addr, meta, data, probe_cmd, delay); // sync if necessary
if(pwb){
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
cache->replace_write(ai, s, w, false); // a write occurred during the probe
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
}
if constexpr (EnMT && Policy::sync_need_lock()) cache->reset_mt_state(ai, s, XactPrio::sync);
}
Expand All @@ -363,8 +363,8 @@ class InnerCohPortUncached : public InnerCohPortBase
if(writeback.first) outer->writeback_req(addr, meta, data, writeback.second, delay); // writeback if dirty

Policy::meta_after_flush(cmd, meta, cache);
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0), writeback.first, meta, data, delay); // identify flush to hook_manager
cache->replace_manage(ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0)); // identify flush to hook_manager
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0), writeback.first, meta, data, delay); // identify flush to hook_manager

if constexpr (EnMT) { meta->unlock(); cache->reset_mt_state(ai, s, XactPrio::flush); }
}
Expand Down Expand Up @@ -455,12 +455,12 @@ class CoreInterface : public InnerCohPortUncached<Policy, EnMT>, public CoreInte
if(coh::is_write(cmd)) {
meta->to_dirty();
if(data) data->copy(m_data);
cache->hook_write(addr, ai, s, w, hit, meta, data, delay);
cache->replace_write(ai, s, w, true);
cache->hook_write(addr, ai, s, w, hit, meta, data, delay);
} else {
bool act_as_prefetch = coh::is_prefetch(cmd) && Policy::is_uncached(); // only tweak replace priority at the LLC accoridng to [Guo2022-MICRO]
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);
if(!act_as_prefetch || !hit) cache->replace_read(ai, s, w, act_as_prefetch);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);
}
if constexpr (EnMT) { meta->unlock(); cache->reset_mt_state(ai, s, XactPrio::acquire);}
if(!hit) outer->finish_req(addr);
Expand Down
14 changes: 5 additions & 9 deletions cache/dynamic_random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,12 @@ class InnerCohPortRemapT : public InnerCohPortT<InnerCohPortUncached, Policy, En
auto[m_meta, m_data] = cache->access_line(new_ai, new_idx, new_way);
uint64_t m_addr = m_meta->addr(new_idx);
if (m_meta->is_valid()) {
if (static_cast<MT *>(m_meta)->is_relocated()) this->evict(m_meta, m_data, new_ai, new_idx, new_way, nullptr);
else{
// cache->hook_manage(m_addr, new_ai, new_idx, new_way, true, 1, false, m_meta, m_data, nullptr);
if (static_cast<MT *>(m_meta)->is_relocated())
this->evict(m_meta, m_data, new_ai, new_idx, new_way, nullptr);
else
cache->replace_manage(new_ai, new_idx, new_way, true, 1);
}
}
static_cast<CT *>(cache)->swap(m_addr, c_addr, m_meta, c_meta, m_data, c_data);
// cache->hook_read(c_addr, new_ai, new_idx, new_way, false, m_meta, m_data, nullptr);
cache->replace_read(new_ai, new_idx, new_way, false);
static_cast<MT *>(m_meta)->to_relocated();
c_addr = m_addr;
Expand All @@ -165,12 +163,10 @@ class InnerCohPortRemapT : public InnerCohPortT<InnerCohPortUncached, Policy, En
auto c_data = data ? cache->data_copy_buffer() : nullptr;
static_cast<CT *>(cache)->relocate(c_addr, meta, c_meta, data, c_data);
static_cast<MT *>(meta)->to_relocated();
// cache->hook_manage(c_addr, ai, idx, way, true, 1, false, c_meta, c_data, nullptr);
cache->replace_manage(ai, idx, way, true, 1);

while(c_meta->is_valid()){
relocation(c_meta, c_data, c_addr);
}
while(c_meta->is_valid()) relocation(c_meta, c_data, c_addr);

cache->meta_return_buffer(c_meta);
cache->data_return_buffer(c_data);
}
Expand Down
28 changes: 14 additions & 14 deletions cache/exclusive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class ExclusiveInnerCohPortUncachedBroadcast : public InnerCohPortUncached<Polic

if (data_inner && data) data_inner->copy(data);
Policy::meta_after_grant(cmd, meta, meta_inner);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);
if(!act_as_prefetch || !hit) cache->replace_read(ai, s, w, act_as_prefetch);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);

cache->meta_return_buffer(meta);
cache->data_return_buffer(data);
Expand Down Expand Up @@ -261,8 +261,8 @@ class ExclusiveInnerCohPortUncachedBroadcast : public InnerCohPortUncached<Polic
if(mmeta->is_valid()) this->evict(mmeta, mdata, mai, ms, mw, delay);
mmeta->init(addr); mmeta->copy(meta); meta->to_invalid();
if(mdata) mdata->copy(data);
cache->hook_write(addr, mai, ms, mw, false, mmeta, mdata, delay); // a write occurred during the probe
cache->replace_write(mai, ms, mw, true);
cache->hook_write(addr, mai, ms, mw, false, mmeta, mdata, delay); // a write occurred during the probe
cache->meta_return_buffer(meta);
cache->data_return_buffer(data);
return std::make_tuple(mmeta, mdata, mai, ms, mw, hit);
Expand Down Expand Up @@ -306,8 +306,8 @@ class ExclusiveInnerCohPortUncachedBroadcast : public InnerCohPortUncached<Polic
if(meta->is_valid()) this->evict(meta, data, ai, s, w, delay);
if(data_inner && data) data->copy(data_inner);
meta->init(addr); Policy::meta_after_release(cmd, meta, meta_inner);
cache->hook_write(addr, ai, s, w, false, meta, data, delay);
cache->replace_write(ai, s, w, true);
cache->hook_write(addr, ai, s, w, false, meta, data, delay);
}
}

Expand All @@ -326,17 +326,17 @@ class ExclusiveInnerCohPortUncachedBroadcast : public InnerCohPortUncached<Polic
if(probe) {
auto [phit, pwb] = this->probe_req(addr, meta, data, probe_cmd, delay); // sync if necessary
if(pwb){
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
}
}

auto writeback = Policy::writeback_need_writeback(meta);
if(writeback.first) outer->writeback_req(addr, meta, data, writeback.second, delay); // writeback if dirty

Policy::meta_after_flush(cmd, meta, cache);
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0), writeback.first, meta, data, delay);
cache->replace_manage(ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0));
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0), writeback.first, meta, data, delay);

if(!hit) {
cache->meta_return_buffer(meta);
Expand Down Expand Up @@ -374,8 +374,8 @@ class ExclusiveInnerCohPortUncachedDirectory : public InnerCohPortUncached<Polic

if (data_inner && data) data_inner->copy(data);
Policy::meta_after_grant(cmd, meta, meta_inner);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);
if(!act_as_prefetch || !hit) cache->replace_read(ai, s, w, act_as_prefetch);
cache->hook_read(addr, ai, s, w, hit, meta, data, delay);

// difficult to know when data is borrowed from buffer, just return it.
cache->data_return_buffer(data);
Expand Down Expand Up @@ -472,8 +472,8 @@ class ExclusiveInnerCohPortUncachedDirectory : public InnerCohPortUncached<Polic
Policy::meta_after_release(cmd, meta, meta_inner);
if(meta->is_extend()) outer->writeback_req(addr, meta, data, coh::cmd_for_release_writeback(), delay); // writeback if dirty
assert(meta_inner); // assume meta_inner is valid for all writebacks
cache->hook_write(addr, ai, s, w, hit, meta, data, delay);
cache->replace_write(ai, s, w, true);
cache->hook_write(addr, ai, s, w, hit, meta, data, delay);
cache->data_return_buffer(data); // return it anyway
} else {
bool phit = false;
Expand All @@ -496,8 +496,8 @@ class ExclusiveInnerCohPortUncachedDirectory : public InnerCohPortUncached<Polic
mmeta->init(addr); mmeta->copy(meta); meta->to_invalid();
if(data_inner && mdata) mdata->copy(data);
Policy::meta_after_release(cmd, mmeta, meta_inner);
cache->hook_write(addr, mai, ms, mw, true, mmeta, mdata, delay);
cache->replace_write(mai, ms, mw, true);
cache->hook_write(addr, mai, ms, mw, true, mmeta, mdata, delay);
}
cache->data_return_buffer(data);
}
Expand All @@ -516,17 +516,17 @@ class ExclusiveInnerCohPortUncachedDirectory : public InnerCohPortUncached<Polic
if(probe) {
auto [phit, pwb] = this->probe_req(addr, meta, data, probe_cmd, delay); // sync if necessary
if(pwb){
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
}
}

auto writeback = Policy::writeback_need_writeback(meta);
if(writeback.first) outer->writeback_req(addr, meta, data, writeback.second, delay); // writeback if dirty

Policy::meta_after_flush(cmd, meta, cache);
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0), writeback.first, meta, data, delay);
cache->replace_manage(ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0));
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(cmd) ? 2 : 0), writeback.first, meta, data, delay);

if(meta->is_extend()) cache->data_return_buffer(data);
}
Expand Down Expand Up @@ -563,8 +563,8 @@ class ExclusiveOuterCohPortBroadcastT : public OPUC<Policy, EnMT>
data = cache->data_copy_buffer();
std::tie(probe_hit, probe_writeback) = inner->probe_req(addr, meta, data, sync.second, delay);
if(probe_writeback){
cache->hook_write(addr, ai, s, w, true, meta, data, delay);
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay);
}
}

Expand All @@ -574,8 +574,8 @@ class ExclusiveOuterCohPortBroadcastT : public OPUC<Policy, EnMT>
}

Policy::meta_after_probe(outer_cmd, meta, meta_outer, coh_id, writeback);
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);
cache->replace_manage(ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0));
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);

if(!hit) {
cache->meta_return_buffer(meta);
Expand Down Expand Up @@ -617,8 +617,8 @@ class ExclusiveOuterCohPortDirectoryT : public OPUC<Policy, EnMT>
data = cache->data_copy_buffer();
std::tie(probe_hit, probe_writeback) = inner->probe_req(addr, meta, data, sync.second, delay);
if(probe_writeback){
cache->hook_write(addr, ai, s, w, true, meta, data, delay);
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay);
}
}
}
Expand All @@ -628,8 +628,8 @@ class ExclusiveOuterCohPortDirectoryT : public OPUC<Policy, EnMT>
}

Policy::meta_after_probe(outer_cmd, meta, meta_outer, coh_id, writeback);
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);
cache->replace_manage(ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0));
cache->hook_manage(addr, ai, s, w, hit, (coh::is_evict(outer_cmd) ? 1 : 0), writeback, meta, data, delay);

if(hit && meta->is_extend()) {
cache->data_return_buffer(data);
Expand Down
11 changes: 4 additions & 7 deletions cache/mirage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,20 @@ class MirageInnerPortUncached : public InnerCohPortUncached<Policy, EnMT>, prote
auto buf_meta = cache->meta_copy_buffer();
auto addr = meta->addr(s);
cache->relocate(addr, meta, buf_meta);
// cache->hook_manage(addr, ai, s, w, true, 1, false, nullptr, nullptr, delay);
cache->replace_manage(ai, s, w, true, 1, true);
while(buf_meta->is_valid()){
relocation++;
cache->replace(addr, &m_ai, &m_s, &m_w, XactPrio::acquire, replace_for_relocate);
auto m_meta = static_cast<MT *>(cache->access(m_ai, m_s, m_w));
auto m_addr = m_meta->addr(m_s);
if (m_meta->is_valid()) {
if (relocation >= MaxRelocN || cache->pre_finish_reloc(m_addr, ai, s, m_ai)){
if (relocation >= MaxRelocN || cache->pre_finish_reloc(m_addr, ai, s, m_ai))
global_evict(m_meta, cache->get_data_data(static_cast<MT *>(m_meta)), m_ai, m_s, w, delay); // associative eviction!
}
// else cache->hook_manage(m_addr, m_ai, m_s, m_w, true, 1, false, nullptr, nullptr, delay);
else cache->replace_manage(m_ai, m_s, m_w, true, 1, true);
else
cache->replace_manage(m_ai, m_s, m_w, true, 1, true);
}
cache->swap(m_addr, addr, m_meta, buf_meta, nullptr, nullptr);
cache->get_data_meta(static_cast<MT *>(m_meta))->bind(m_ai, m_s, m_w);
// cache->hook_read(addr, m_ai, m_s, m_w, false, nullptr, nullptr, delay);
cache->replace_read(m_ai, m_s, m_w, false, true);
addr = m_addr;
}
Expand All @@ -273,8 +270,8 @@ class MirageInnerPortUncached : public InnerCohPortUncached<Policy, EnMT>, prote
if(sync.first) {
auto [phit, pwb] = this->probe_req(addr, meta, data, sync.second, delay); // sync if necessary
if(pwb){
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
cache->replace_write(ai, s, w, false);
cache->hook_write(addr, ai, s, w, true, meta, data, delay); // a write occurred during the probe
}
}
auto [promote, promote_local, promote_cmd] = Policy::access_need_promote(cmd, meta);
Expand Down

0 comments on commit 581d731

Please sign in to comment.