How Do Interrupts Work?

by Carson
52 views
interrupts

How do your devices deal with user input? Well, computers are able to do this because of the processing of interrupts. Let’s find out what an interrupt is and how they’re processed in this article.

The Way Interrupts Work

First, we’d explore how interrupts work, and we’ll start by discussing essential properties of the CPU. A CPU core can only process one task at a time, and it can appear to process different threads at once because it’s essentially task-switching. The process is managed by the allocations of CPU cycles, which lasts shorter than a person’s reaction time, thus not letting any users notice that the CPU is doing things one at a time. You may think this is unrelated to interrupts, but that fact is very important for understanding how interrupts work.

The operating system’s scheduler controls the distribution and allocation of CPU cycles across thousands of processes and threads, including the scheduler itself. Without outside intervention, they will conduct the computation in the arrangement that is originally anticipated. However, an interrupt occurs when it encounters some signal from the outside world or a program.

When the CPU receives an interrupt, it finishes its current execution cycle and pauses the program’s execution. The program’s state is saved for the processor to resume it quickly and without errors. Then, a specialized program called an interrupt handler steps in. It processes the interrupt, figures out the right way to process the request, and then sends out a signal to the program meant to receive it, depending on which program is in the foreground of your screen. The program will then behave according to your actions.

How To Trigger an Interrupt In a Computer?

By using your computer in a typical way, either browsing the Internet, typing out your notes, or controlling your computer, you send interrupts to the processor very frequently. In fact, one of the most common types of interrupts is user input. For instance, pressing keys on your keyboard, clicking on a button, or moving your cursor all send interrupts to your device’s processor. That’s why you can see letters arriving at your screen as you type, and you can send commands to the computer so that it can operate appropriately.

At this point, you may be curious whether interrupts can be triggered through automatic means instead of letting the user manage everything on the device. The answer is yes. Different types of interrupts can be triggered by an internal condition of the processes, or the hardware that programs run on. For example, when your RAM throws a segmentation fault, it will notify the CPU so that it stops the program before any undefined behavior steps in. Moreover, when an I/O operation is required, an I/O interrupt will be sent for the CPU to wait for the hard drive to retrieve the data value before it starts working on the current thread again.

How Are Interrupts Prioritized?

To enhance the operations of the computer, interrupts are sorted in priority. Specifically, they are classified as maskable interrupts and non-maskable interrupts, in which the former has lower priority, and the latter has a higher priority.

When the interrupt is maskable, the CPU can choose whether to process it when the current cycle finishes. This is useful in scenarios like keystrokes, as some key combinations under specific environments don’t need to trigger any action. You also don’t want a computer that’s very low on RAM to slow down even more, as handling the requests means spending a longer time fetching more data. On the other hand, in an unexpected or emergency situation, like sudden power outages or a hardware error, the processor is notified in a non-maskable interrupt. In that case, the CPU must process it immediately and cannot reject the notification.

Conclusion

In this article, we’ve talked about how interrupts work, how interrupts are created, and the types of interrupts. If you would like more information about these events happening inside your device, please visit the webpages in the references below.

References

  1. (2020, May 20). Difference between Hardware Interrupt and Software Interrupt. Retrieved September 17, 2022, from https://www.geeksforgeeks.org/difference-between-hardware-interrupt-and-software-interrupt/
  2. (2021, November 30). What are different types of interrupts? Retrieved September 17, 2022, from https://www.tutorialspoint.com/what-are-different-types-of-interrupts
  3. (n.d.). Difference between Maskable and Non-Maskable Interrupts. Retrieved September 17, 2022, from https://www.javatpoint.com/maskable-vs-non-maskable-interrupts
  4. (n.d.). Difference Between Maskable and Non-Maskable Interrupts. Retrieved September 17, 2022, from https://techdifferences.com/difference-between-maskable-and-non-maskable-interrupts.html

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.