Random recording (really can't context switch in interrupt)

Source: Internet
Author: User


"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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.