This is the 8th day of my participation in Gwen Challenge
Who interrupts who?
Peripheral interrupts CPU
Why interrupt the CPU?
If you don’t interrupt the CPU, how can you make it work for you?
Peripherals are like students, cpus are like teachers; The teacher is lecturing in class, and the students have to raise their hands to inform the teacher before they ask questions, otherwise the students will all speak freely and become a mess. The raise of hands here is an interruption. Interrupted the teacher’s normal lecture process and turned to deal with the student’s problem. After dealing with the student’s question, the teacher will pick up where he left off. The familiar voice: Ok, let’s go on.
Can’t we use polling without interrupting?
Yes, but it’s too inefficient. Given 1000 peripherals, the CPU has to poll from first to last each time to see which device has a task. Assuming that only the last peripheral has a task, then the previous 999 polls are wasted and delay a lot of time, affecting the processing speed of the last peripheral. Imagine, you are playing CF, corner suddenly and enemy encounter, at the moment you press the left mouse button, want to shoot the enemy; At the moment, the CPU is polling the other devices in a polling manner. You have to wait for the mouse to turn, and your gun won’t fire. The CPU of the opponent’s computer uses an interrupt mode. Once he presses the left mouse button, an interrupt is generated, and the CPU can immediately process the mouse event to shoot. The result is that they beat the crap out of you, and you can’t fight back. Do you still use CPU polling like this? Unless you want to look for a reason: not be my technical dish, it is computer no good 😜.
How to interrupt?
Unlike software, where statements can communicate with each other, peripherals are hardware that don’t speak the same language as the CPU or even speak (no software, pure hardware). So how does the peripheral interrupt the CPU? The answer is: with a wire. When there is a task outside, he will pass this wire, electric CPU, CPU is electric, it must hurt ah, can feel you need help, come to deal with your task. The official name of this wire is the IRQ(Interrupt ReQuest output line), but the IRQ is not strictly connected to the CPU, it’s connected to the Programmable Interrupt Controller (PIC), The programmable interrupt controller is then directly connected to the CPU through INTR pins.