Hello.

The complain that dosemu hogs CPU when program is idle, appears to be
very frequent in this ML, so I decided to post my experemental patch here
in hope that someone who have this problem, will test it. I beleave that the
problem is that dosemu doesn't release time slices when the program polls
keyboard via int16 or directly via port0x60. I want some feedbacks just to
know if my guesses are correct and the problem is really with polling the
keyboard (there could be lots of other reasons).
The patch is highly UNtested, so be prepared to everything. It can even
yield rejects on "stable" dosemu, because I use devel version, but this is
unlikely.
So, everyone who wants to see this problem fixed in the near future, is
encouraged to test this and write a feedback.
--- src/base/async/int.c	Mon Oct  8 01:31:55 2001
+++ src/base/async/int.c	Mon Oct  8 13:27:20 2001
@@ -1414,6 +1414,12 @@
     else
       return NO_REVECT;
 
+  case 0x16:			/* Keyboard */
+    if (config.hogthreshold)
+      return REVECT;
+    else
+      return NO_REVECT;
+
 #if 0		/* no need to specify all */
   case 0x10:			/* BIOS video */
   case 0x13:			/* BIOS disk */
@@ -1494,13 +1500,24 @@
     return;
 }
 
-#ifndef USE_NEW_INT
 /* KEYBOARD */
 static void int16(u_char i) {
+extern Bit8u port60_buffer;
+static Bit16u oldESP;
+static int trigger = 0;
     real_run_int(0x16);
-    return;
+    if(config.hogthreshold) {
+      if((_AH==0x01 || _AH==0x11) && (port60_buffer & 0x80) &&
+        oldESP==_ESP && READ_WORD(BIOS_KEYBOARD_BUFFER_HEAD) ==
+        READ_WORD(BIOS_KEYBOARD_BUFFER_TAIL)) {
+    	  if(++trigger >= config.hogthreshold*100) {
+	    usleep(INT2F_IDLE_USECS);
+	    trigger=0;
+    	  }
+      } else trigger=0;
+      oldESP=_ESP;
+    }
 }
-#endif /* not USE_NEW_INT */
 
 /* BASIC */
 static void int18(u_char i) {
@@ -2118,9 +2135,7 @@
   interrupt_function[0x13] = int13;
   interrupt_function[0x14] = int14;
   interrupt_function[0x15] = int15;
-#ifndef USE_NEW_INT
   interrupt_function[0x16] = int16;
-#endif /* not USE_NEW_INT */
   interrupt_function[0x17] = int17;
   interrupt_function[0x18] = int18;
   interrupt_function[0x19] = int19;
--- src/base/keyboard/serv_8042.c	Fri Sep  7 00:28:13 2001
+++ src/base/keyboard/serv_8042.c	Mon Oct  8 02:08:16 2001
@@ -22,6 +22,7 @@
  *
  */
 
+#include <unistd.h>
 #include "emu.h"
 #include "iodev.h"
 #include "int.h"
@@ -272,10 +273,22 @@
 Bit8u keyb_io_read(ioport_t port)
 {
   Bit8u r = 0;
+  static Bit8u oldval = 0;
+  static int trigger = 0;
 
   switch (port) {
   case 0x60:     
       r = read_port60();
+
+      if(config.hogthreshold) {
+        if((r & 0x80) && r == oldval) trigger++;
+	else trigger=0;
+	if(trigger >= config.hogthreshold*10) {
+          usleep(INT2F_IDLE_USECS);
+          trigger=0;
+        }
+        oldval=r;
+      }
      
       /* We ought to untrigger IRQ1, in case DOS was reading port60h with interrupts off, 
        * but currently the PIC code doesn't support this. */


Reply via email to