From: Andrew Waterman Date: Wed, 13 Feb 2013 06:59:14 +0000 (-0800) Subject: make HTIF interactions deterministic; fix race X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d58ee30d172f6848edb1b3b225cc90c2143dc750;p=riscv-isa-sim.git make HTIF interactions deterministic; fix race --- diff --git a/riscv/htif.cc b/riscv/htif.cc index c7ba8fc..64ef40a 100644 --- a/riscv/htif.cc +++ b/riscv/htif.cc @@ -1,5 +1,4 @@ #include "htif.h" -#include "common.h" #include "sim.h" #include #include @@ -84,8 +83,9 @@ void htif_isasim_t::tick_once() memcpy(&val, p.get_payload(), sizeof(val)); if (regno == PCR_RESET) { - reset = val & 1; - sim->procs[coreid]->reset(reset); + if (reset && !(val & 1)) + reset = false; + sim->procs[coreid]->reset(val & 1); } else { @@ -100,8 +100,12 @@ void htif_isasim_t::tick_once() seqno++; } -void htif_isasim_t::stop() +bool htif_isasim_t::done() { - htif_t::stop(); - exit(exit_code()); + if (reset) + return false; + for (size_t i = 0; i < sim->num_cores(); i++) + if (sim->procs[i]->running()) + return false; + return true; } diff --git a/riscv/htif.h b/riscv/htif.h index 0d8d1b7..034743a 100644 --- a/riscv/htif.h +++ b/riscv/htif.h @@ -16,7 +16,7 @@ class htif_isasim_t : public htif_pthread_t public: htif_isasim_t(sim_t* _sim, const std::vector& args); void tick(); - void stop(); + bool done(); private: sim_t* sim; diff --git a/riscv/sim.cc b/riscv/sim.cc index 31c91ae..6d98d8e 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -49,7 +49,6 @@ sim_t::~sim_t() delete procs[i]; delete pmmu; } - delete htif; delete mmu; munmap(mem, memsz); } @@ -72,10 +71,10 @@ reg_t sim_t::get_scr(int which) void sim_t::run(bool debug) { - while (1) + while (!htif->done()) { if(!debug) - step_all(1000, 1000, false); + step_all(10000, 1000, false); else interactive(); }