[PATCH] console: usb: kbd: Limit poll frequency to improve performance

Marek Vasut marex at denx.de
Wed Dec 22 20:28:34 CET 2021


On 12/22/21 19:20, Mark Kettenis wrote:
>> From: Thomas Watson <twatson52 at icloud.com>
>> Date: Tue, 21 Dec 2021 19:36:16 -0600
>>
>> Using the XHCI driver, the function `usb_kbd_poll_for_event` takes
>> 30-40ms to run. The exact time is dependent on the polling interval the
>> keyboard requests in its descriptor, and likely cannot be significantly
>> reduced without major rework to the XHCI driver.
>>
>> The U-Boot EFI console service sets a timer to poll the keyboard every 5
>> microseconds, and this timer is checked every time a block is read off
>> disk. The net effect is that, on my system, loading a ~40MiB kernel and
>> initrd takes about 62 seconds with a slower keyboard and 53 seconds
>> with a faster one, with the vast majority of the time spent polling the
>> keyboard.
>>
>> To solve this problem, this patch adds a 20ms delay between consecutive
>> calls to `usb_kbd_poll_for_event`. This is sufficient to reduce the
>> total loading time to under half a second for both keyboards, and does
>> not impact the perceived keystroke latency.
>>
>> Signed-off-by: Thomas Watson <twatson52 at icloud.com>
>> ---
> 
> I can confirm that plugging in a usb keyboard makes loading a kernel
> annoyingly slow when booting through EFI.  And this looks like a
> reasonable approach to fix this to me.  Minor nit: I think you should
> reflow the comment you're adding such that it fits within the standard
> 80 character line limit.

That, and please make sure the patch applies on u-boot/master (currently 
it does not). Use git send-email if your mailer reformats the patches.


More information about the U-Boot mailing list