Skip to content

Commit

Permalink
Merge pull request #247 from OpenXiangShan/skipperfcntcsr
Browse files Browse the repository at this point in the history
arch-riscv: skip diff when reading perfCnt CSRs
  • Loading branch information
happy-lx authored Jan 2, 2025
2 parents 0b08af4 + 8fa8f5b commit 5182ebd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
39 changes: 35 additions & 4 deletions src/cpu/difftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdio>
#include <cstdlib>

#include "arch/riscv/regs/misc.hh"
#include "base/trace.hh"
#include "cpu/nemu_common.hh"
#include "debug/ValueCommit.hh"
Expand Down Expand Up @@ -34,10 +35,36 @@ const char *reg_name[] = {
"v30", "v31"
};

const std::vector<uint64_t> skipCSRs = {
0xb0200073,
0xb0000073
};
std::vector<uint64_t> skipCSRs;

// CSR op Encoding:
// #12
// | csrName | 0000 | 0000 | 0000 | 0111 | 0011 |
#define GetCSROPInstCode(csrName) ((csrName << 20) | 0x73UL)

void
skipPerfCntCsr()
{
skipCSRs.push_back(GetCSROPInstCode(gem5::RiscvISA::CSR_MCYCLE));
skipCSRs.push_back(GetCSROPInstCode(gem5::RiscvISA::CSR_MINSTRET));

for (uint64_t counter = gem5::RiscvISA::CSR_MMHPMCOUNTER3;
counter <= gem5::RiscvISA::CSR_MMHPMCOUNTER31; counter++) {
skipCSRs.push_back(GetCSROPInstCode(counter));
}
for (uint64_t counter = gem5::RiscvISA::CSR_MHPMCOUNTER03;
counter <= gem5::RiscvISA::CSR_MHPMCOUNTER31; counter++) {
skipCSRs.push_back(GetCSROPInstCode(counter));
}
for (uint64_t counter = gem5::RiscvISA::CSR_MMCOUNTINHIBIT;
counter <= gem5::RiscvISA::CSR_MHPMEVENT31; counter++) {
skipCSRs.push_back(GetCSROPInstCode(counter));
}
for (uint64_t counter = gem5::RiscvISA::CSR_CYCLE;
counter <= gem5::RiscvISA::CSR_HPMCOUNTER31; counter++) {
skipCSRs.push_back(GetCSROPInstCode(counter));
}
}

NemuProxy::NemuProxy(int coreid, const char *ref_so, bool enable_sdcard_diff, bool enable_mem_dedup, bool multi_core)
{
Expand Down Expand Up @@ -100,6 +127,8 @@ NemuProxy::NemuProxy(int coreid, const char *ref_so, bool enable_sdcard_diff, bo
assert(sdcard_init);
}

skipPerfCntCsr();

auto nemu_init = (void (*)(void))dlsym(handle, "difftest_init");
assert(nemu_init);

Expand Down Expand Up @@ -171,6 +200,8 @@ SpikeProxy::SpikeProxy(int coreid, const char *ref_so, bool enable_sdcard_diff)

assert(!enable_sdcard_diff);

skipPerfCntCsr();

auto nemu_init = (void (*)(void))dlsym(handle, "difftest_init");
assert(nemu_init);

Expand Down
4 changes: 3 additions & 1 deletion src/cpu/difftest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ enum DiffAt
ValueDiff,
};

extern const std::vector<uint64_t> skipCSRs;
void skipPerfCntCsr();

extern std::vector<uint64_t> skipCSRs;

extern uint8_t *pmemStart;
extern uint64_t pmemSize;
Expand Down

0 comments on commit 5182ebd

Please sign in to comment.