vmm: Exit console input thread if we get EOF on stdin
authorDan Cross <crossd@gmail.com>
Mon, 14 Aug 2017 18:06:14 +0000 (14:06 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 14 Aug 2017 21:00:32 +0000 (17:00 -0400)
If we read an EOF from standard input (that is,
read() returns 0) then take that as a signal that
we should exit the console input loop, instead of
injecting console input interrupts into the guest
when there is nothing to read.

Tested by booting Linux and seeing a reduction
from a core spending approximately 85% of its time
in hardware interrupt handling down to spending
a single-digit percentage of time handling
interrupts.

Change-Id: Idb0a82ab9eab86c10f0e2169c008de236fe4e71d
Signed-off-by: Dan Cross <crossd@gmail.com>
[Added vmm:]
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/vmm/virtio_lguest_console.c

index 8178a45..fb84ae9 100644 (file)
@@ -83,6 +83,12 @@ void *cons_receiveq_fn(void *_vq) // host -> guest
                        VIRTIO_DEV_ERRX(vq->vqdev,
                                "Encountered an error trying to read input from stdin (fd 0).");
 
+               if (num_read == 0) {
+                       VIRTIO_DEV_WARNX(vq->vqdev,
+                               "Encountered EOF reading from stdin; exiting input thread.");
+                       break;
+               }
+
                // You pass the number of bytes written to virtio_add_used_desc
                virtio_add_used_desc(vq, head, num_read);