poll HTIF occasionally
authorAndrew Waterman <waterman@eecs.berkeley.edu>
Wed, 1 Feb 2012 01:31:33 +0000 (17:31 -0800)
committerAndrew Waterman <waterman@eecs.berkeley.edu>
Wed, 1 Feb 2012 01:31:33 +0000 (17:31 -0800)
riscv/htif.cc
riscv/htif.h
riscv/riscv-isa-run.cc
riscv/sim.cc

index ab27f01d4e2fbefd2e9affa28d63103e82ac0ac5..7de27c686915a6601d7a400c135093950370555a 100644 (file)
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <stddef.h>
+#include <poll.h>
 
 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)
index d7a8c898197db39e9bb39304ef130e8e7389fc6a..805cc4ff6ed7cd69bc6c0e7e0a1b742d07205da8 100644 (file)
@@ -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;
index f73cc5504fb0ea3d566cd46104d6a8eb91a82d9b..9217be82d2550f0198addb5cd48796017dad6f12 100644 (file)
@@ -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");
 }
index f1c1b3b790f2ef76e7feb47da7ead3653d74089b..d61e60076baf7dc3ee6be140b5919f0b8f5292c6 100644 (file)
@@ -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();
   }
 }