1

I'm learning about the differences between Polling and Interrupts for I/O in my OS class and one of the things my teacher mentioned was that the speed of the I/O device can make a difference in which method would be better. He didn't follow up on it but I've been wracking my brain about it and I can't figure out why. I feel like using Interrupts is almost always better and I just don't see how the speed of the I/O device has anything to do with it.

jtht
  • 793
  • 2
  • 10
  • 19

2 Answers2

2

The only advantage of polling comes when you don't care about every change that occurs.

Assume you have a real-time system that measures the temperature of a vat of molten plastic used for molding. Let's also say that your device can measure to a resolution of 1/1000 of a degree and can take new temperature every 1/10,000 of a second.

However, you only need the temperature every second and you only need to know the temperature within 1/10 of a degree.

In that kind of environment, polling the device might be preferable. Make one polling request every second. If you used interrupts, you could get 10,000 interrupts a second as the temperature moved +/- 1/1000 of a degree.

Polling used to be common with certain I/O devices, such as joysticks and pointing devices.

That said, there is VERY little need for polling and it has pretty much gone away.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • Yes. Polling keyboards/keypads in a timer interrupt is not uncommon because checking to se if any key state has changed since last time is very quick and multiple reads are often necessary for debouncing. Other than that, and certain scenarios like you mention above, nobody polls because of the CPU, memory-bandwidth and energy waste. – Martin James Apr 20 '16 at 08:14
1

Generally you would want to use interrupts, because polling can waste a lot of CPU cycles. However, if the event is frequent, synchronous (and if other factors apply e.g. short polling times...) polling can be a good alternative, especially because interrupts create more overhead than polling cycles.

You might want to take a look at this thread as well for more detail: Polling or Interrupt based method

Community
  • 1
  • 1
Keiwan
  • 8,031
  • 5
  • 36
  • 49
  • 1
    It's not just CPU cycles. It's memory bandwidth, (impacting other cores), and energy waste, (a halted CPU uses much less power). – Martin James Apr 20 '16 at 08:15