Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/sysc/core2sc_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
auto cycle_incr = owner->get_last_bus_cycles();
if(cycle_incr > 1)
this->instr_if.update_last_instr_cycles(cycle_incr);
owner->sync(this->instr_if.get_total_cycles());
owner->qk_sync(this->instr_if.get_total_cycles());
}
first = false;
}
Expand Down Expand Up @@ -270,12 +270,14 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
if(is_debugger_stop_evt)
break;
}
SCCINFO(this->owner->hier_name()) << "Got WFI event";
SCCDEBUG(this->owner->hier_name()) << "Got WFI event";
auto duration = sc_core::sc_time_stamp() - start;
if(clk_if && duration > sc_core::SC_ZERO_TIME) {
auto cycles = duration.value() / clk_if->read().value();
this->reg.cycle += cycles;
SCCDEBUG(owner->hier_name()) << "Increasing cycles by " << cycles << " after WFI";
}
owner->qk_reset(this->instr_if.get_total_cycles());
};
owner->exec_on_sysc(f);
wfi_inst.store(false, std::memory_order_relaxed);
Expand Down
36 changes: 24 additions & 12 deletions src/sysc/core_complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,20 @@ bool core_complex<BUSWIDTH, QK>::read_mem(const addr_t& addr, unsigned length, u
gp.set_extension<sysc::memspace::tlm_memspace_extension<>>(nullptr);
};
auto pre_delay = delay;
auto transport_start = sc_core::sc_time_stamp();
exec_b_transport(gp, delay, is_fetch);
if(pre_delay > delay) {
quantum_keeper.reset();
} else {
auto incr = (delay - quantum_keeper.get_local_time()) / curr_clk;
if(is_fetch)
ibus_inc += incr;
else
dbus_inc += incr;
auto transport_time = sc_core::sc_time_stamp() - transport_start;
auto completion = delay + sc_core::sc_time_stamp();
auto time_taken = (completion) - (pre_delay + transport_start);
auto incr = time_taken.value() / curr_clk.read().value();
if(is_fetch)
ibus_inc += incr;
else
dbus_inc += incr;

if(transport_time.value()) {
quantum_keeper.reset(completion);
qk_preaccounted_cycles += incr;
}
SCCTRACE(this->name()) << "[local offset: +" << delay << "]: finish read_mem(0x" << std::hex << addr.val << ") : 0x"
<< (length == 4 ? *(uint32_t*)data
Expand Down Expand Up @@ -497,11 +502,18 @@ bool core_complex<BUSWIDTH, QK>::write_mem(const addr_t& addr, unsigned length,
gp.set_extension<sysc::memspace::tlm_memspace_extension<>>(nullptr);
};
auto pre_delay = delay;
auto transport_start = sc_core::sc_time_stamp();
exec_b_transport(gp, delay);
if(pre_delay > delay)
quantum_keeper.reset();
else
dbus_inc += (delay - quantum_keeper.get_local_time()) / curr_clk;
auto transport_time = sc_core::sc_time_stamp() - transport_start;
auto completion = delay + sc_core::sc_time_stamp();
auto time_taken = (completion) - (pre_delay + transport_start);
auto incr = time_taken.value() / curr_clk.read().value();
dbus_inc += incr;

if(transport_time.value()) {
quantum_keeper.reset(completion);
qk_preaccounted_cycles += incr;
}
SCCTRACE(this->name()) << "[local offset: +" << delay << "]: finish write_mem(0x" << std::hex << addr.val << ") : 0x"
<< (length == 4 ? *(uint32_t*)data
: length == 2 ? *(uint16_t*)data
Expand Down
14 changes: 12 additions & 2 deletions src/sysc/core_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <scc/tick2time.h>
#include <scc/traceable.h>
#include <scc/utilities.h>
#include <sysc/kernel/sc_simcontext.h>
#include <sysc/kernel/sc_time.h>
#include <tlm/scc/initiator_mixin.h>
#include <tlm/scc/quantum_keeper.h>
Expand Down Expand Up @@ -184,11 +185,19 @@ class core_complex : public sc_core::sc_module, public scc::traceable, public co
return mem_incr > 1 ? mem_incr : 1;
}

void sync(uint64_t cycle) override {
auto core_inc = curr_clk * (cycle - last_sync_cycle);
void qk_sync(uint64_t cycle) override {
auto cycle_delta = cycle - last_sync_cycle;
auto preaccounted = std::min(cycle_delta, qk_preaccounted_cycles);
qk_preaccounted_cycles -= preaccounted;
assert(qk_preaccounted_cycles <= cycle_delta);
auto core_inc = curr_clk * (cycle_delta - preaccounted);
quantum_keeper.check_and_sync(core_inc);
last_sync_cycle = cycle;
}
void qk_reset(uint64_t cycle) override {
quantum_keeper.reset(quantum_keeper.get_local_absolute_time());
last_sync_cycle = cycle;
}

bool read_mem(const iss::addr_t& a, unsigned length, uint8_t* const data) override;

Expand Down Expand Up @@ -300,6 +309,7 @@ class core_complex : public sc_core::sc_module, public scc::traceable, public co
//
///////////////////////////////////////////////////////////////////////////////
uint64_t last_sync_cycle = 0;
uint64_t qk_preaccounted_cycles{0};
util::range_lut<tlm_dmi_ext> fetch_lut{tlm_dmi_ext()};
util::range_lut<tlm_dmi_ext>& get_read_lut(unsigned space) {
return space < dmi_read_luts.size() ? dmi_read_luts[space] : get_lut(dmi_read_luts, space);
Expand Down
4 changes: 3 additions & 1 deletion src/sysc/core_complex_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ struct core_complex_if {
virtual unsigned get_last_bus_cycles() = 0;

//! Allow quantum keeper handling
virtual void sync(uint64_t) = 0;
virtual void qk_sync(uint64_t) = 0;

virtual void qk_reset(uint64_t) = 0;

util::delegate<void(std::function<void(void)>&)> exec_on_sysc;

Expand Down
Loading