proc: Add need_resched()
authorAlan Cox <alan@linux.intel.com>
Sat, 24 Jan 2015 13:07:10 +0000 (13:07 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 24 Jan 2015 13:07:10 +0000 (13:07 +0000)
Use this to make the tty code behave better

Kernel/include/kernel.h
Kernel/tty.c

index eb1eb78..86c3b5f 100644 (file)
@@ -701,6 +701,8 @@ CODE2 void timer_interrupt(void);
 CODE2 void doexit (int16_t val, int16_t val2);
 CODE2 void panic(char *deathcry);
 CODE2 void exec_or_die(void);
+#define need_resched() (nready != 1 && runticks >= udata.u_ptab->p_priority)
+
 
 /* select.c */
 CODE2 extern void seladdwait(struct selmap *s);
index 00b9cf6..9762498 100644 (file)
@@ -379,9 +379,13 @@ void tty_putc_wait(uint8_t minor, unsigned char c)
                ptty_putc_wait(minor, c);
        else
 #endif
+        /* For slower platforms it's not worth the task switching and return
+           costs versus waiting a bit. A box with tx interrupts and sufficient
+           performance can buffer or sleep in in tty_putc instead. */
        if (!udata.u_ininterrupt) {
                while (!tty_writeready(minor))
-                       psleep(&ttydata[minor]);
+                       if (need_resched())
+                               psleep(&ttydata[minor]);
        }
        tty_putc(minor, c);
 }