Hardware Interrupts

 


Image Source: https://www.canstockphoto.com/android-operating-system-logo-on-12761409.html


Introduction

A hardware interrupt or external interrupt is a mechanism in computers that allows external hardware devices to inform the central processing unit (CPU) that an interrupt routine must be performed to complete a specific task required by it and interrupt its normal execution of instructions. This happens when an external event, called an interrupt request, requires immediate attention from the CPU. These events can range from a user entering data through a keyboard to a hardware drive signalling that it has completed a data transfer. In this blog post, we will explain two methods of hardware interrupts: polling and vectored interrupt.

Polling

During the polling process, the processor looks at every interrupt source starting from the highest priority source and observes if the interrupt signal for that source is enabled. If so, the interrupt service routine executes for that source. Otherwise, the CPU looks at the next highest priority interrupt source and repeats the same. 

To understand this concept further, consider that you are in a gathering and everyone is seated to have lunch. The people are served according to their age so the eldest person will have the highest priority. A person comes to serve some food and first goes to the eldest person and asks if they should serve them. If the person they go to wants the food they will serve them and move on to the next eldest person. Even if someone does not want the food they will ask them and if they don't want it they will move on to the next person. The polling mechanism in computers works in the same way.

The limitation of this method is that the system tests every hardware source even though an interrupt is not required for that source at that moment. This is a waste of CPU time, especially when there are a lot of interrupt sources. Another disadvantage is that the source that needs to interrupt has to wait for the CPU.

Vectored Interrupt

In the vectored interrupt mechanism, each interrupt source notifies the CPU for an interrupt by itself. Each source has its interrupt vector in the interrupt vector table(IVT). When a source interrupts the CPU, it obtains the address of the interrupt service routine(ISR) corresponding to the interrupt source's vector from the IVT. If multiple sources interrupt the CPU at once, the CPU first services the highest priority source. In this way, we can prevent CPU cycles from getting wasted.

Consider that in a gathering everyone has to go up to a table to get food served to them. No one will come to every seat. Anyone who requires food will go up to the table and a person will serve them. If multiple guests go to the table at once, the serving people will first give the food to the eldest person who comes there and then to the younger people. 

Conclusion

In modern computing systems, the preference for vectored interrupts is evident due to their ability to handle multiple devices effectively. They help avoid the drawbacks of hardware polling, such as increased power consumption, decreased responsiveness, and limited scalability.

However, it's important to note that the choice between hardware polling and vectored interrupts may depend on the specific requirements of a system. Certain applications or embedded systems with minimal hardware resources might find hardware polling more feasible. In contrast, high-performance systems that demand rapid responses and efficient resource utilization would benefit significantly from vectored interrupts.

Comments