This is super tangential, but does anyone else find it sad that operating systems receive keys from USB keyboards using polling rather than interrupts? Wouldn't comprehensive use of interrupts rather than polling allow the processor to move to a lower-power state? No wonder our closed smartphones are more battery-efficient than our open PCs.
There is a common misconception that the host would be polling the keyboard state every time. It is actually polling to ask the device if it has a new packet to send. If the keyboard's state hasn't changed then there is no new packet and there isn't any input processing done by the CPU.
The host polls because it is in control of scheduling all activity on the bus. It must be scheduled because there can be multiple devices (and multiple interfaces per device) with different characteristics on the same bus, and they must be kept from interfering with one-another.
Ben Eater has one of the best channels on YouTube! If you haven’t already, check out his 8 bit bread board computer series. He explains how to make a computer, completely from scratch. Coming from the software world, I found this to be absolutely fascinating!
The USB host controller does the polling in hardware. The cpu does not get involved until a key is pressed (the host controller can interrupt the cpu, telling it that new data is available).
In this case it seems like the leak was just "accidentally keeping references to objects that we should've stopped using", as opposed to leaking truly unreachable memory.
16 comments
[ 3.8 ms ] story [ 46.9 ms ] threadFortunately he's wrong - the CPU doesn't do the polling itself.
The host polls because it is in control of scheduling all activity on the bus. It must be scheduled because there can be multiple devices (and multiple interfaces per device) with different characteristics on the same bus, and they must be kept from interfering with one-another.
Really didn't expect to suddenly want an oscilloscope.