Skip to content

Commit 900df04

Browse files
committed
fixes mcycle to increase while core is in WFI (in SystemC)
1 parent 6cf6914 commit 900df04

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if(NOT TARGET dbt-rise-core)
4444
FetchContent_Declare(
4545
dbt_rise_core_git
4646
GIT_REPOSITORY "https://github.com/Minres/DBT-RISE-Core.git"
47-
GIT_TAG 7cd010c
47+
GIT_TAG 29e97c02
4848
GIT_SHALLOW OFF
4949
UPDATE_DISCONNECTED NOT ${UPDATE_EXTERNAL_PROJECT} # When enabled, this option causes the update step to be skipped.
5050
)

src/sysc/core2sc_adapter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <scc/async_event.h>
4848
#include <scc/report.h>
4949
#include <shared_mutex>
50+
#include <sysc/kernel/sc_simcontext.h>
5051
#include <sysc/kernel/sc_time.h>
5152
#include <util/instance_logger.h>
5253
#include <util/ities.h>
@@ -262,13 +263,19 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
262263
SCCDEBUG(owner->hier_name()) << "Sleeping until interrupt";
263264
wfi_inst.store(true, std::memory_order_relaxed);
264265
std::function<void(void)> f = [this]() {
266+
auto start = sc_core::sc_time_stamp();
265267
while((this->mip_csr & this->mie_csr) == 0) {
266268
sc_core::wait(this->wfi_evt | this->debugger_stop_evt);
267269
bool is_debugger_stop_evt = this->debugger_stop_evt.triggered();
268270
if(is_debugger_stop_evt)
269271
break;
270272
}
271273
SCCINFO(this->owner->hier_name()) << "Got WFI event";
274+
auto duration = sc_core::sc_time_stamp() - start;
275+
if(clk_if && duration > sc_core::SC_ZERO_TIME) {
276+
auto cycles = duration.value() / clk_if->read().value();
277+
this->reg.cycle += cycles;
278+
}
272279
};
273280
owner->exec_on_sysc(f);
274281
wfi_inst.store(false, std::memory_order_relaxed);

src/sysc/core_complex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void core_complex<BUSWIDTH, QK>::create_cpu(std::string const& type, std::string
170170
SCCFATAL() << "Could not create vm for isa " << type << " and backend " << backend;
171171
} else {
172172
core->set_hartid(hart_id);
173+
core->set_clk_if(clk_i.get_interface(0));
173174
core->set_clint_irq_count(clint_irq_i.size());
174175
auto* srv = debugger::server<debugger::gdb_session>::get();
175176
if(srv)

src/sysc/sc2core_if.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ struct sc2core_if {
6666
util::delegate<void(unsigned, wr_csr_f)> register_csr_wr;
6767
virtual void register_unknown_instr_handler(util::delegate<iss::arch_if::unknown_instr_cb_t>) = 0;
6868
virtual void set_clint_irq_count(size_t) = 0;
69+
void set_clk_if(sc_core::sc_signal_in_if<sc_core::sc_time>* clk_if) { this->clk_if = clk_if; };
70+
71+
protected:
72+
sc_core::sc_signal_in_if<sc_core::sc_time>* clk_if{nullptr};
6973
};
7074
} // namespace sysc
7175
#endif /* _SYSC_SC2CORE_IF_H_ */

0 commit comments

Comments
 (0)