Hacker News
points by kbolino 2 days ago | 0 comments
> USB is just fundamentally adding wrapping layers that introduce latency over the direct polling PS/2 used

PS/2 did not use polling, it was entirely event-driven. On keypress, the keyboard sent a serial message to the 8042 controller [1], which then raised the appropriate interrupt line on the CPU, which caused the keyboard ISR [2] to be executed. The serial clock was a bit flexible, but usually sat around 10-16 kHz [3], and so the 11-bit serial message took at most 1 ms to send.

It is USB that uses polling. The keyboard describes itself using endpoint descriptors, and after obtaining these, the host controller periodically polls it with an IN token, to which the keyboard responds with its state changes since the last poll [4]. The earliest USB keyboards preferred fairly slow polling rates, but modern keyboards can be polled every 1 ms [5]. If directly connected to a motherboard USB port, a modern USB keyboard will have pre-software input latency on par with a PS/2 keyboard.

[1]: https://wiki.osdev.org/I8042_PS/2_Controller

[2]: https://wiki.osdev.org/Interrupt_Service_Routines

[3]: https://retrocomputing.stackexchange.com/q/15607/25565

[4]: https://threeboard.dev/documentation/threeboard/how_usb_keyb...

[5]: https://www.usb.org/sites/default/files/hid1_11.pdf pp. 68-69

[–] chowells 2 days ago
Agh. Crossed wires with PS2 as in the playstation 2. Its controllers used polling. I did this to myself...
[–] kbolino 2 days ago
Yeah, I'd say the bigger point is that the latency gap isn't really there anymore. Old keyboards, cheap keyboards, expansion ports, and external hubs can still cause problems, though.