Page 1 of 1

Keyboard laggy on VmWare

Posted: Tue Jun 21, 2016 4:52 am
by Ycep
Hi, since I installed VmWare Workstation I noticed that my keyboard driver misses every third key.
The keyboard is fast enough on other emulators (VirtualBox, PCem, Bochs) but not on VmWare. I tried disabling their "enhanced keyboard" but results are same.

I tried typing on MS-DOS 3.0 but it catches every key.
And yes, I updated my keyboard driver so now it uses IRQs to catch keys.
Is it because I bundled my keyboard IRQ too much?
And did anyone had similar problems with VMware?

Re: Keyboard laggy on VmWare

Posted: Tue Jun 21, 2016 5:42 am
by max
Hey lukaandjelkovic,

what do you do to the scancodes that you receive? Did you try just immediately printing it somewhere to screen to see if they come in?

Greetings

Re: Keyboard laggy on VmWare

Posted: Wed Jun 22, 2016 5:16 pm
by BrightLight
In general, for any IRQ and not only keyboard, you should do everything possible to IRET as quickly as possible. This improves general performance and stability, especially with multitasking.

Re: Keyboard laggy on VmWare

Posted: Thu Jun 23, 2016 7:07 am
by Ycep
Well yes, my IRQ is insanely big, but i'll try to reduce it's size and optimize it.
Any ideas to somehow speed up keyboard lag without optimizing my IRQ?

Re: Keyboard laggy on VmWare

Posted: Thu Jun 23, 2016 7:42 am
by iansjack
lukaandjelkovic wrote:Well yes, my IRQ is insanely big, but i'll try to reduce it's size and optimize it.
Any ideas to somehow speed up keyboard lag without optimizing my IRQ?
The interrupt part of a keyboard driver should be very small. Basically it just needs to insert raw keycodes into a queue. You need to rethink your design.

Re: Keyboard laggy on VmWare

Posted: Thu Jun 23, 2016 1:32 pm
by Ycep
max wrote:Hey lukaandjelkovic,

what do you do to the scancodes that you receive? Did you try just immediately printing it somewhere to screen to see if they come in?

Greetings
No, because the keyboard driver works, expect i need to hold keys bit longer on VmWare to read them.
My IRQ checks general key, was shift released or not, caps lock, set up the keyboard lights if required, alt key, ctrl key, numpad, etc.

Re: Keyboard laggy on VmWare

Posted: Thu Jun 23, 2016 2:53 pm
by BenLunt
iansjack wrote:
lukaandjelkovic wrote:Well yes, my IRQ is insanely big, but i'll try to reduce it's size and optimize it.
Any ideas to somehow speed up keyboard lag without optimizing my IRQ?
The interrupt part of a keyboard driver should be very small. Basically it just needs to insert raw keycodes into a queue. You need to rethink your design.
In my book, Input and Output Devices, I show that your PS2 IRQ should simply retrieve the byte from the Output Register and store it in a buffer, acknowledge the interrupt, *and* (interrupt) return. Very little to anything else should be done inside the IRQ. Then, I have a thread (or task) that monitors this buffer and when enough bytes are found to create a scan code, it retrieves them, creates the scan code, and adds it to the scan code buffer (where ironically, another thread (or task) monitors it).

This way the IRQ does so little that it uses only 10 to 30 cycles of the CPU (not counting time to acknowledge interrupt), and all of the work is done in the a kernel thread, where preemptive thread (task) switching is okay and does not hurt performance any.

Code: Select all

( pseudo code )
( using a circular buffer )
( NEXT retrieves the next position in the circular buffer )
(   i.e.: don't want the head to write on the tail )
kernel_ps2_irq:
  byte =  inp(output_buffer);
  if (NEXT(head) != tail) {
    head = NEXT(head);
    keyboard_raw_buffer[head] = byte;
  }
  acknowledge interrupt
  done....
At least something like that.

Note: some think the head and tail should be swapped. i.e.: the tail is that more recent byte read and the head is the byte that should be used first by the kernel. It all depends on how you look at it, from the IRQ point of view or the kernel thread (task) point of view. Feel free to swap the "head" and "tail" keywords. :-)

Anyway, that is all that should be in your IRQ. The way to know if the byte in the PS2's Output Buffer is from the keyboard or the mouse is simply because the keyboard and mouse each fire a different IRQ, though *both* use the same Output Buffer. Therefore you must make sure and know which irq is reading from the buffer (I/O port).

Note: The PS2 uses the names from the hardware point of view. The Output Buffer is the buffer the hardware is sending bytes to, i.e.: outputting to a buffer. The Input Buffer is the (one byte) buffer it receives bytes from. Your OS or driver should read from the Output Buffer and write to the Input Buffer.

One other error that gets a lot of new-comers is that you only get one byte per IRQ. Just because the IRQ fired, doesn't mean you can read a whole scan code from the Output Buffer. Yes, if you read the Output buffer three times for a three byte scan code, you might get all three bytes, but the PS2 will still fire two more times, even though you already read those bytes....Only read one byte per IRQ...