"Disclaimer: Copyright, welcome reprint, please do not use for commercial purposes. Contact mailbox: feixiaoxing @163.com "
Remember when reading, the operating system's teacher told us that when the CPU processing interrupt, it is not possible to do context switching. As for what the reason is, it is the impact of disruption, the impact of performance or something. A bit further down, there is no. Of course, we are convinced of the teacher's words.
Until later, when the port Ucos2 real-time system, it is possible to interrupt the context switch when the interrupt is returned. Why is it? Because the CPU has just handled the interrupt, and the original high-priority task may have just been awakened in the interrupt, it needs to be understood to be executed, so switch to this new real-time task by the necessary means before the interrupt is returned. Here, I think of the teacher said can not be interrupted context switch ah, why here again.
Later, when I was able to read the Linux code, I discovered that Linux could be context-switched before the interrupt returned to kernel mode. Ucos and Linux are widely used code, since they are in the context of the interruption of the switch, then the teacher is difficult to tell the truth wrong?
Then one evening, when I was reading, I suddenly had an epiphany. The teacher said that the interrupt can not be context-switching, should not be in the interrupt processing to half the time of the context switch. What would happen if we had to do that? I think there are a few points, first, the interrupted task will receive unwarranted involvement, because if the interruption does not occur, it would have the opportunity to continue to run, and now this switch will lead to CPU scheduling unfair, but will not be disordered; second, nested interrupts are not processed in a timely manner because of the CPU's unprovoked context switches , the performance is greatly reduced, some hardware behavior even becomes unpredictable; third, the interrupt context switch takes a long time, affecting the CPU processing other interrupts, the timeliness of loss.
That said, the teacher is not wrong, Linux and Ucos is not wrong, this is we ourselves did not find root cause just. It also tells me that learning is never just acquiring knowledge, it is a process of thinking and discriminating.
Random recording (really can't context switch in interrupt)