Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lazy stack: ensure next stack page dynamically if preemption enabled
This patch modifies number of critical places mostly in the scheduler code to dynamically pre-fault the stack if preemption is enabled. In all these places we can be statically sure that interrupts are enabled but not so sure about preemption (maybe in future we can prove it is enabled at least in some of the cases and replace conditional ensure_next_stack_page_if_preemptable() with cheaper single-intruction ensure_next_stack_page()). The three call sites before irq_lock is taken (interrupts are disabled) include: - cpu::schedule() before WITH_LOCK(irq_lock) - thread::pin() before WITH_LOCK(irq_lock) - thread::yield() before guard*(irq_lock) The reasoning above goes like this: the methods were designed with intention to be used when interrupts are enabled because otherwise the act of using WITH_LOCK or guard construct would imply that interrupts would be re-enabled after the block so the code does not care about restoring interrupts to the proper state it was before. If that was the intension, these methods would use irq_save_lock_type. Two other call sites in the scheduler are: - timer_base destructor before calling timer_base::cancel() which disables interrupts - thread::wake_with_from_mutex() only called from waiter::wake() follow the reasoning that interrupts are enabled most of the time except few places in scheduler and interrupt handler. Also we assume the mutex is not used when interrupts are disabled. And based on my analysis of all the code that disables/enables interrupts that seems to be the case. In any case we put invariants in these two places to verify that interrupts are enabled indeed. The last call site in abort() assumes that calling irq_disable() implies that interrupts are enabled before and we only need to check preemption status. Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
- Loading branch information