The main difference between interrupt and polling is that, in the case of an interrupt, the device notifies the CPU that it requires attention while, in the case of polling, the CPU continuously checks the status of the device to find whether it requires attention.
Generally, an operating system is the layer between the hardware and user programs. Here, the CPU is the component that handles the tasks of the entire computer system. Sometimes, it is necessary to pause the currently executing task and perform immediate actions. Two such mechanisms are interrupts and polling.
Key Areas Covered
1. What is Interrupt
– Definition, Functionality
2. What is Polling
– Definition, Functionality
3. Difference Between Interrupt and Polling
– Comparison of Key Differences
Key Terms
CPU, Interrupt, Hardware Interrupt, Maskable interrupt, Non-maskable interrupt, Polling, Software Interrupt
What is Interrupt
An interrupt is an event that indicates the CPU to take immediate action. There can be an interrupt to indicate the time out of a timer. Additionally, an interrupt can notify the received data packets of a networking device. When an interrupt occurs, the CPU pauses the task it is currently executing and executes the corresponding interrupt handler, which is known as Interrupt Service Routine (ISR). After handling the interrupt, it switches back to the usual tasks it was executing.
There are mainly two types of interrupts as hardware and software interrupt.
Hardware Interrupts
Hardware interrupts are used by devices to inform that they require the attention of the operating system. For example, pressing a key on the keyboard triggers a hardware interrupt. It causes the CPU to read that keystroke. Initiating a hardware interrupt is called an interrupt request (IRQ). Each hard interrupt has an interrupt number. The number corresponds to the hardware that generates the interrupt. Therefore, the CPU can recognize the device. Furthermore, there are two types of hardware interrupts as maskable interrupt and non-maskable interrupt. The CPU can delay maskable interrupts whereas CPU cannot delay the non-maskable interrupts.
Software Interrupts
Software Interrupt is an interrupt that is caused by an exceptional condition in the processor or an executing program. Dividing a number by zero can cause an exception, and it is a software interrupt. Moreover, invalid variables and memory leaks caused by infinite loops can also generate software interrupts.
What is Polling
Polling is the mechanism that indicates the CPU that a device requires its attention. It is a continuous act to figure out whether the device is working properly. As it is mostly used with input/output (I/O), it is also called polled I/O or software driven I/O. Polling also helps to check a device continuously for readiness. For example, take a printer. If the device is busy, the CPU performs some other task. Usually, polling often involves low-level hardware.
However, there are some disadvantages to polling as well. Mainly, polling causes the wastage of many CPU cycles. Especially, if there are many devices to check, then the time taken to poll them could exceed the time available to service the I/O device.
Difference Between Interrupt and Polling
Definition
An interrupt is an event that is triggered by external components other than the CPU that alerts the CPU to perform a certain action. In contrast, polling is a synchronous activity that samples the status of an external device by a client program. Thus, this describes the main difference between interrupt and polling.
Result
When an interrupt occurs, the interrupt handler is executed. On the other hand, in polling, the CPU provides the service.
Occurrence
Another difference between interrupt and polling is that interrupt can occur at any time while polling occurs at regular intervals.
Indication
Moreover, the interrupt-request line indicates that a device needs a service whereas command-ready bit indicates the a device needs service.
CPU cycles
Interrupt does not waste many CPU cycles while polling wastes a lot of CPU cycles. Hence, this is also a difference between interrupt and polling.
Efficiency
Furthermore, in the case of interrupt, it is inefficient when the devices interrupt the CPU frequently. In contrast, polling is inefficient, when the CPU does not get much requests from the devices.
Conclusion
The main difference between interrupt and polling is that in interrupt, the device notifies the CPU that it requires attention while, in polling, the CPU continuously checks the status of the devices to find whether they require attention. In brief, an interrupt is asynchronous whereas polling is synchronous.
References:
1.“Interrupt.” Wikipedia, Wikimedia Foundation, 6 May 2019, Available here.
2.“Polling (Computer Science).” Wikipedia, Wikimedia Foundation, 12 Mar. 2019, Available here.
3.“What Is Polling? – Definition from WhatIs.com.” WhatIs.com, Available here.
4.“What Is Polling?” Computer Hope, 17 Oct. 2017, Available here.
Image Courtesy:
1.”Path of interrupts from hardware” By Jfmantis – Own work (CC BY-SA 3.0) via Commons Wikimedia
Leave a Reply