Context switch within Interrupt Service Routine
Posted: Tue Jul 22, 2014 9:43 pm
I'm currently porting ChibiOS 2.6.4 to a new platform. But I think this question is more general os related and port independent.
(This paragraph may be skipped.)
After I managed to implement port_switch(), I ran the TestThread. All tests until delayed threading passed. I figured out I must have missed enabling interrupts in PORT_IRQ_EPILOGUE(). Mutex priority inversion was the next test to fail. It was locked inside the loop of test_cpu_pulse(). I thought must be a missing interrupt enabling again, so for test purposes I directly inserted the according code right before the loop. But nothing happened. I figured out that no new timer interrupts were taking place because the old interrupt handler didn't return.
This brings me to my actual question: What should happen if chSysSwitch() is called from withing an interrupt handler?
Let me explain my problem. Assume there are two threads with same priority and TIME_QUANTUM is > 0 (so round robin scheduling is enabled). Thread A is currently running. A timer interrupt occures, chSysTimerHandler is called. In the IRQ_PORT_EPILOGUE doReschedule functions switch from thread A to thread B. Thread B does its thing, e.g. while(1);. No other interrupts will occure because the Interrupt Service Routine didn't return yet.
(This paragraph may be skipped.)
After I managed to implement port_switch(), I ran the TestThread. All tests until delayed threading passed. I figured out I must have missed enabling interrupts in PORT_IRQ_EPILOGUE(). Mutex priority inversion was the next test to fail. It was locked inside the loop of test_cpu_pulse(). I thought must be a missing interrupt enabling again, so for test purposes I directly inserted the according code right before the loop. But nothing happened. I figured out that no new timer interrupts were taking place because the old interrupt handler didn't return.
This brings me to my actual question: What should happen if chSysSwitch() is called from withing an interrupt handler?
Let me explain my problem. Assume there are two threads with same priority and TIME_QUANTUM is > 0 (so round robin scheduling is enabled). Thread A is currently running. A timer interrupt occures, chSysTimerHandler is called. In the IRQ_PORT_EPILOGUE doReschedule functions switch from thread A to thread B. Thread B does its thing, e.g. while(1);. No other interrupts will occure because the Interrupt Service Routine didn't return yet.