cons: Clamp the amount written to the console
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 14 Aug 2017 13:45:21 +0000 (09:45 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 14 Aug 2017 21:02:20 +0000 (17:02 -0400)
Large writes to the console take a long time.  Serial writes of about a
page take O(100ms).  Our kernel is currently non-preemptive, which is
based on a model of syscalls not taking too long.

Limiting the write sizes to 80 (the width of an ancient console, which
Ron will love) cuts the syscall time down to a few ms, which is within
the quantum of a process.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/cons.c

index b2639da..90d9890 100644 (file)
@@ -1226,8 +1226,10 @@ static long conswrite(struct chan *c, void *va, long n, int64_t off)
                         * keyboard would try to print it (which it can't do yet).  The hack
                         * is even dirtier in that we only detect it if it is the first
                         * char, and we ignore everything else.  \033 is 0x1b. */
-                       if (((char*)va)[0] != '\033')
+                       if (((char*)va)[0] != '\033') {
+                               n = MIN(n, 80);
                                cputbuf(va, n);
+                       }
                        poperror();
                        px_unlock();
                        return n;