Skip to content

Commit

Permalink
[cosim] feat: also count spike cycles for mcycle
Browse files Browse the repository at this point in the history
  • Loading branch information
SharzyL authored and sequencer committed Apr 14, 2024
1 parent c2abd82 commit f266b54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ipemu/csrc/vbridge_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ void VBridgeImpl::getCoverage() { return ctx->coveragep()->write(); }

std::optional<SpikeEvent> VBridgeImpl::spike_step() {
auto state = proc.get_state();
state->csrmap.at(CSR_MCYCLE)->write(get_t());

state->mcycle->write((int64_t) get_t() + spike_cycles);

auto fetch = proc.get_mmu()->load_insn(state->pc);
auto event = create_spike_event(fetch);

Expand All @@ -378,6 +380,7 @@ std::optional<SpikeEvent> VBridgeImpl::spike_step() {
.with("pc", fmt::format("{:08X}", se.pc))
.with("rs1", fmt::format("{:08X}", se.rs1_bits))
.with("rs2", fmt::format("{:08X}", se.rs2_bits))
.with("spike_cycles", spike_cycles)
.info("spike run vector insn");
se.pre_log_arch_changes();
new_pc = fetch.func(&proc, fetch.insn, state->pc);
Expand All @@ -387,6 +390,7 @@ std::optional<SpikeEvent> VBridgeImpl::spike_step() {
.with("pc", fmt::format("{:08X}", state->pc))
.with("bits", fmt::format("{:08X}", fetch.insn.bits()))
.with("disasm", proc.get_disassembler()->disassemble(fetch.insn))
.with("spike_cycles", spike_cycles)
.info("spike run scalar insn");
new_pc = fetch.func(&proc, fetch.insn, state->pc);
}
Expand All @@ -411,6 +415,9 @@ std::optional<SpikeEvent> VBridgeImpl::spike_step() {
}
}

// spike does not bump mcycle by itself, so do it manually
spike_cycles ++;

return event;
}

Expand Down
2 changes: 2 additions & 0 deletions ipemu/csrc/vbridge_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ class VBridgeImpl {
const uint64_t dump_from_cycle;
#endif

int64_t spike_cycles = 0;

std::optional<SpikeEvent> create_spike_event(insn_fetch_t fetch);

std::optional<SpikeEvent> spike_step();
Expand Down

0 comments on commit f266b54

Please sign in to comment.