Skip to content

Commit

Permalink
Merge pull request #56 from comparch-security/fix-flush
Browse files Browse the repository at this point in the history
Fix flush
  • Loading branch information
wsong83 authored Jan 27, 2024
2 parents 6791c22 + e8acb4d commit aa0fca9
Show file tree
Hide file tree
Showing 18 changed files with 115,531 additions and 120,408 deletions.
9 changes: 8 additions & 1 deletion cache/coherence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,19 @@ class InnerCohPortUncached : public InnerCohPortBase
if(hit) std::tie(meta, data) = cache->access_line(ai, s, w);

auto [flush, probe, probe_cmd] = policy->flush_need_sync(cmd, meta, outer->is_uncached());
if(!flush) return;
if(!flush) {
// do not handle flush at this level, and send it to the outer cache
outer->writeback_req(addr, nullptr, nullptr, policy->cmd_for_flush(), delay);
return;
}

if(!hit) return;

if(probe) {
auto [phit, pwb] = probe_req(addr, meta, data, probe_cmd, delay); // sync if necessary
if(pwb) cache->hook_write(addr, ai, s, w, true, true, meta, data, delay); // a write occurred during the probe
}

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

Expand Down
15 changes: 13 additions & 2 deletions cache/exclusive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ class ExclusiveInnerCohPortUncachedBroadcast : public InnerCohPortUncached
if(hit) std::tie(meta, data) = cache->access_line(ai, s, w);

auto [flush, probe, probe_cmd] = policy->flush_need_sync(cmd, meta, outer->is_uncached());
if(!flush) return;
if(!flush) {
// do not handle flush at this level, and send it to the outer cache
outer->writeback_req(addr, nullptr, nullptr, policy->cmd_for_flush(), delay);
return;
}

if(!hit) {
meta = cache->meta_copy_buffer(); meta->init(addr); meta->get_outer_meta()->to_invalid();
Expand Down Expand Up @@ -485,7 +489,14 @@ class ExclusiveInnerCohPortUncachedDirectory : public InnerCohPortUncached
if(hit) std::tie(meta, data) = cache->access_line(ai, s, w);

auto [flush, probe, probe_cmd] = policy->flush_need_sync(cmd, meta, outer->is_uncached());
if(!flush || !hit) return;
if(!flush) {
// do not handle flush at this level, and send it to the outer cache
outer->writeback_req(addr, nullptr, nullptr, policy->cmd_for_flush(), delay);
return;
}

if(!hit) return;

if(meta->is_extend()) data = cache->data_copy_buffer();

if(probe) {
Expand Down
8 changes: 5 additions & 3 deletions cache/mi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ class MIPolicy : public CohPolicyBase
}

virtual std::tuple<bool, bool, coh_cmd_t> flush_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta, bool uncached) const {
if (isLLC || (uncached && meta)) {
if(is_evict(cmd)) return std::make_tuple(true, true, cmd_for_probe_release());
else return std::make_tuple(true, true, cmd_for_probe_writeback());
if (isLLC || uncached) {
if(meta){
if(is_evict(cmd)) return std::make_tuple(true, true, cmd_for_probe_release());
else return std::make_tuple(true, true, cmd_for_probe_writeback());
} else return std::make_tuple(true, false, cmd_for_null());
} else
return std::make_tuple(false, false, cmd_for_null());
}
Expand Down
13 changes: 8 additions & 5 deletions cache/msi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ template<typename MT, bool isL1, bool isLLC> requires C_DERIVE(MT, MetadataBroad
}

virtual std::tuple<bool, bool, coh_cmd_t> flush_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta, bool uncached) const {
if (isLLC || (uncached && meta)) {
if(is_evict(cmd)) return std::make_tuple(true, true, cmd_for_probe_release());
else if(meta && meta->is_shared())
if (isLLC || uncached) {
if(meta) {
if(is_evict(cmd)) return std::make_tuple(true, true, cmd_for_probe_release());
else if(meta->is_shared())
return std::make_tuple(true, false, cmd_for_null());
else
return std::make_tuple(true, true, cmd_for_probe_writeback());
} else
return std::make_tuple(true, false, cmd_for_null());
else
return std::make_tuple(true, true, cmd_for_probe_writeback());
} else
return std::make_tuple(false, false, cmd_for_null());
}
Expand Down
2 changes: 1 addition & 1 deletion regression/c1-l1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ int main() {
l1d->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<1, false, AddrN, 0, Data64B> tgen;
RegressionGen<1, false, false, AddrN, 0, Data64B> tgen;
return tgen.run(TestN, core, core);
}
2 changes: 1 addition & 1 deletion regression/c2-l2-exc-mesi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ int main() {
l2->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, false, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
2 changes: 1 addition & 1 deletion regression/c2-l2-exc-mi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ int main() {
l2->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, false, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
2 changes: 1 addition & 1 deletion regression/c2-l2-exc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ int main() {
l2->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, false, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
2 changes: 1 addition & 1 deletion regression/c2-l2-mesi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ int main() {
l2->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, false, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
2 changes: 1 addition & 1 deletion regression/c2-l2-mirage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ int main() {
l2->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, false, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
2 changes: 1 addition & 1 deletion regression/c2-l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ int main() {
l2->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, false, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
2 changes: 1 addition & 1 deletion regression/c4-l3-exc-mesi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ int main() {
l3->attach_monitor(&tracer);
mem->attach_monitor(&tracer);

RegressionGen<NCore, true, PAddrN, SAddrN, Data64B> tgen;
RegressionGen<NCore, true, true, PAddrN, SAddrN, Data64B> tgen;
return tgen.run(TestN, core_inst, core_data);
}
Loading

0 comments on commit aa0fca9

Please sign in to comment.