diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-02-15 19:22:35 +0530 |
---|---|---|
committer | Chih-Min Chao <chihmin.chao@sifive.com> | 2020-02-19 18:52:50 -0800 |
commit | fbddad3d49da510f34b0b874d097b8c87d47309b (patch) | |
tree | c5412ae700a3185cc54bc50ac3a43e5d0880122a /riscv/clint.cc | |
parent | 08cf745aaab48d67fafc995663ec96757ff6b816 (diff) | |
download | spike-fbddad3d49da510f34b0b874d097b8c87d47309b.zip spike-fbddad3d49da510f34b0b874d097b8c87d47309b.tar.gz spike-fbddad3d49da510f34b0b874d097b8c87d47309b.tar.bz2 |
Add optional support for real-time clint
This patch adds optional support clint timer incrementing at
real-time rate. This can be enabled by passing command line
parameter "--real-time-clint".
This feature can be used for:
1. Checking whether any code addition to Spike is slowing down
simulation too much
2. Comparing run-time for software on Spike with other functional
simulators (such as QEMU)
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'riscv/clint.cc')
-rw-r--r-- | riscv/clint.cc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/riscv/clint.cc b/riscv/clint.cc index 20a9fca..d68f4cc 100644 --- a/riscv/clint.cc +++ b/riscv/clint.cc @@ -1,9 +1,16 @@ +#include <sys/time.h> #include "devices.h" #include "processor.h" -clint_t::clint_t(std::vector<processor_t*>& procs) - : procs(procs), mtime(0), mtimecmp(procs.size()) +clint_t::clint_t(std::vector<processor_t*>& procs, uint64_t freq_mhz, bool real_time) + : procs(procs), freq_mhz(freq_mhz), real_time(real_time), mtime(0), mtimecmp(procs.size()) { + struct timeval base; + + gettimeofday(&base, NULL); + + real_time_ref_secs = base.tv_sec; + real_time_ref_usecs = base.tv_usec; } /* 0000 msip hart 0 @@ -22,6 +29,7 @@ clint_t::clint_t(std::vector<processor_t*>& procs) bool clint_t::load(reg_t addr, size_t len, uint8_t* bytes) { + increment(0); if (addr >= MSIP_BASE && addr + len <= MSIP_BASE + procs.size()*sizeof(msip_t)) { std::vector<msip_t> msip(procs.size()); for (size_t i = 0; i < procs.size(); ++i) @@ -63,7 +71,16 @@ bool clint_t::store(reg_t addr, size_t len, const uint8_t* bytes) void clint_t::increment(reg_t inc) { - mtime += inc; + if (real_time) { + struct timeval now; + uint64_t diff_usecs; + + gettimeofday(&now, NULL); + diff_usecs = ((now.tv_sec - real_time_ref_secs) * 1000000) + (now.tv_usec - real_time_ref_usecs); + mtime = diff_usecs * freq_mhz; + } else { + mtime += inc; + } for (size_t i = 0; i < procs.size(); i++) { procs[i]->state.mip &= ~MIP_MTIP; if (mtime >= mtimecmp[i]) |