From: Andrew Waterman Date: Wed, 1 Feb 2012 01:31:33 +0000 (-0800) Subject: poll HTIF occasionally X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=23688da201a3b668deaa3e7cc184060b678f2058;p=riscv-isa-sim.git poll HTIF occasionally --- diff --git a/riscv/htif.cc b/riscv/htif.cc index ab27f01..7de27c6 100644 --- a/riscv/htif.cc +++ b/riscv/htif.cc @@ -7,6 +7,7 @@ #include #include #include +#include enum { @@ -79,6 +80,17 @@ void htif_t::nack(uint16_t nack_seqno) send_packet(&p); } +void htif_t::poll() +{ + struct pollfd pfd; + pfd.fd = fromhost_fd; + pfd.events = POLLIN; + pfd.revents = 0; + + if (::poll(&pfd, 1, 0) > 0) + wait_for_packet(); +} + int htif_t::wait_for_packet() { while(1) diff --git a/riscv/htif.h b/riscv/htif.h index d7a8c89..805cc4f 100644 --- a/riscv/htif.h +++ b/riscv/htif.h @@ -22,6 +22,9 @@ public: void wait_for_tohost_write(); void wait_for_fromhost_write(); + // check to see if there's a pending packet and process it if so + void poll(); + private: sim_t* sim; int tohost_fd; diff --git a/riscv/riscv-isa-run.cc b/riscv/riscv-isa-run.cc index f73cc55..9217be8 100644 --- a/riscv/riscv-isa-run.cc +++ b/riscv/riscv-isa-run.cc @@ -54,4 +54,5 @@ int main(int argc, char** argv) // initalize simulator and run to completion sim_t s(nprocs, &htif); s.run(debug); + printf("graceful\n"); } diff --git a/riscv/sim.cc b/riscv/sim.cc index f1c1b3b..d61e600 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -87,10 +87,15 @@ void sim_t::run(bool debug) for(running = true; running; ) { - if(!debug) - step_all(100,100,false); - else - interactive(); + for (int i = 0; i < 1000; i++) + { + if(!debug) + step_all(100,100,false); + else + interactive(); + } + + htif->poll(); } }