From 0d926fb3f7271feac185dfecf846fe341cc26b4c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 16 Jun 2024 12:04:05 +0200 Subject: [PATCH] xhcid: Sleep for 2ms on every poll loop This significantly reduces cpu usage. On my laptop before this change a single core would be fully loaded while running at 3-4GHz. With this change it would only be loaded for about 50% while running at 1-2GHz. This improves battery lifetime while also preventing the fan from spinning up to a distracting level. This shouldn't noticably affect latency given that most keyboards and mice don't support polling at 500Hz anyway. --- xhcid/src/xhci/irq_reactor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xhcid/src/xhci/irq_reactor.rs b/xhcid/src/xhci/irq_reactor.rs index 45d22a0eb7..f496280ed7 100644 --- a/xhcid/src/xhci/irq_reactor.rs +++ b/xhcid/src/xhci/irq_reactor.rs @@ -105,7 +105,7 @@ impl IrqReactor { } // TODO: Configure the amount of time wait when no more work can be done (for IRQ-less polling). fn pause(&self) { - std::thread::yield_now(); + std::thread::sleep(std::time::Duration::from_millis(2)); } fn run_polling(mut self) { debug!("Running IRQ reactor in polling mode.");