maybe a stupid question but during review of the irq_epilogue code (for ARM v6m - chcore_v6m.c) I recognized that even in case no rescheduling is required (chSchIsPreemptionRequired() returns false) the artificial return from ISR is used, so in fact on exit of an ISR and even if no rescheduling is required, the CPU enters _port_exit_from_isr when leaving the ISR. In _port_exit_from_isr the only thing which is done is to enter exception mode again (via NMI or PendSV) to re-adjust the context. Why is this done, i don't really see a need? Why not directly returning back to the interrupted task? So the code i'm thinking of would be:
Code: Select all
void _port_irq_epilogue(regarm_t lr) {
if (lr != (regarm_t)0xFFFFFFF1U) {
struct port_extctx *ctxp;
port_lock_from_isr();
if (chSchIsPreemptionRequired()) {
/* Preemption is required we need to enforce a context switch.*/
/* The extctx structure is pointed by the PSP register.*/
ctxp = (struct port_extctx *)__get_PSP();
/* Adding an artificial exception return context, there is no need to
populate it fully.*/
ctxp--;
/* Writing back the modified PSP value.*/
__set_PSP((uint32_t)ctxp);
/* Setting up a fake XPSR register value.*/
ctxp->xpsr = (regarm_t)0x01000000;
ctxp->pc = (regarm_t)_port_switch_from_isr;
/* Note, returning without unlocking is intentional, this is done in
order to keep the rest of the context switch atomic.*/
}
else {
/* Preemption not required, we use normal ISR return.*/
port_unlock_from_isr();
}
}
}
This would make exit from ISR faster in case no re-scheduling is required.
Christian.