What is "Polling" in MIPS and how exactly do you "Poll" in Memory Mapped I/O

675 Views Asked by At

having trouble warpping my head around this topic, simple internet searches only show Interrupt Handling so im assuming its a type of interrupt? sorry if im being dense.

1

There are 1 best solutions below

0
On

Polling is an I/O approach where the user program directly manages devices.

The approach for polling involves a busy wait loop followed by a data transfer.  This approach is simple and is still used on embedded controllers where the software is simplistic and the hardware is relatively energy efficient.

A busy wait loop is very simple: consult a memory location (an MMIO location owned by a device that indicates the device's status) and repeat that in a loop if that memory location reports the device isn't ready.  When the device is ready, transfer one data byte (e.g. character) to or from the device.

Polling has the advantage of being simple.  The user program sends character to the console one at a time, busy-waiting (polling) in between each character.  Same for keyboard input, getting one key press at a time and busy-waiting in between each.

Polling has is disadvantaged for general purpose computers because it consumes excessive CPU doing virtually nothing.  If the device is the keyboard, the CPU will loop in busy-wait until the user hits a key, which could be seconds, hours, or days of running that loop.

Further, polling may loose keyboard characters if several key presses occur when the program is not taking care to look out for them.  (Some systems will loose the newer characters, others, the earlier.)

A busy-wait loop looks to the system like other ordinary and important user code: it does not specifically yield the CPU to other software on the system, nor does it allow the system to go into a lower power mode.

The busy-wait loop approach has the user program directly interacting with the device.  Sharing a console, for example, among multiple simultaneously running threads or programs would be difficult (e.g. polling is not thread safe).


Interrupts are an alternative approach to busy-waiting for device IO.  Effective use of interrupts requires buffering for input and output, which means a user program has to be written in such a way that decouples the sending and receiving of individual characters.  Typically, this kind of decoupling is what operating system "system calls" provide.  Decoupled, the user program can be suspended when devices are not ready, so as to yield the CPU to other programs or to lower the CPU's power consumption state.  Since devices are not directly accessed by user program code, steps can be taken that allow sharing of devices among multiple threads & programs.


A polled interrupt is still an interrupt-based approach, just that multiple devices may be polled at an interrupt to identify which one triggered the interrupt — this is used when the interrupt mechanisms are designed & wired so as to conflate (or fail to differentiate among) multiple devices.  There is no busy-wait loop in polled interrupts.