浏览代码

[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.
tags/v0.9.4
Michael Brown 17 年前
父节点
当前提交
50810955e9
共有 1 个文件被更改,包括 8 次插入6 次删除
  1. 8
    6
      src/core/console.c

+ 8
- 6
src/core/console.c 查看文件

88
  */
88
  */
89
 int getchar ( void ) {
89
 int getchar ( void ) {
90
 	struct console_driver *console;
90
 	struct console_driver *console;
91
-	int character = 256;
91
+	int character;
92
+
93
+	while ( 1 ) {
94
+		console = has_input();
95
+		if ( console && console->getchar ) {
96
+			character = console->getchar ();
97
+			break;
98
+		}
92
 
99
 
93
-	while ( character == 256 ) {
94
 		/* Doze for a while (until the next interrupt).  This works
100
 		/* Doze for a while (until the next interrupt).  This works
95
 		 * fine, because the keyboard is interrupt-driven, and the
101
 		 * fine, because the keyboard is interrupt-driven, and the
96
 		 * timer interrupt (approx. every 50msec) takes care of the
102
 		 * timer interrupt (approx. every 50msec) takes care of the
105
 		 * input.
111
 		 * input.
106
 		 */
112
 		 */
107
 		step();
113
 		step();
108
-		
109
-		console = has_input();
110
-		if ( console && console->getchar )
111
-			character = console->getchar ();
112
 	}
114
 	}
113
 
115
 
114
 	/* CR -> LF translation */
116
 	/* CR -> LF translation */

正在加载...
取消
保存