From 23688da201a3b668deaa3e7cc184060b678f2058 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Tue, 31 Jan 2012 17:31:33 -0800 Subject: [PATCH] poll HTIF occasionally --- riscv/htif.cc | 12 ++++++++++++ riscv/htif.h | 3 +++ riscv/riscv-isa-run.cc | 1 + riscv/sim.cc | 13 +++++++++---- 4 files changed, 25 insertions(+), 4 deletions(-) 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(); } } -- 2.30.2