From 50810955e97cf704548c84d38194f8ef0a45d8d4 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 11 Jun 2008 12:06:10 +0100 Subject: [console] Call cpu_nap() only if there is no input waiting Avoid calling cpu_nap() until after we have determined that there is no input ready to read. This avoids delaying for one timer interrupt (~50ms) in the case of if ( iskey() ) char = getkey() which happens to be present in monojob.c, which is where we spend most of our time looping (e.g. during any download). This should eliminate the irritating tendency of gPXE to lose keypresses. Discovered on a Dell system where the serial port seems to send in a constant stream of 0xff characters; this wouldn't be a problem in itself except that each one triggers the 50ms delay (as mentioned above), which really kills performance. --- src/core/console.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/console.c b/src/core/console.c index 6f55d558..653f689d 100644 --- a/src/core/console.c +++ b/src/core/console.c @@ -88,9 +88,15 @@ static struct console_driver * has_input ( void ) { */ int getchar ( void ) { struct console_driver *console; - int character = 256; + int character; + + while ( 1 ) { + console = has_input(); + if ( console && console->getchar ) { + character = console->getchar (); + break; + } - while ( character == 256 ) { /* Doze for a while (until the next interrupt). This works * fine, because the keyboard is interrupt-driven, and the * timer interrupt (approx. every 50msec) takes care of the @@ -105,10 +111,6 @@ int getchar ( void ) { * input. */ step(); - - console = has_input(); - if ( console && console->getchar ) - character = console->getchar (); } /* CR -> LF translation */ -- cgit v1.2.3-55-g7522