2014年6月9日 星期一

LKD notes

1. types of exceptions:  divided by 0; page fault; system call
2. Why interrupt can not sleep?  Interrupt do not have task_info structure and therefore can not trace through the rbtree to find the next runnable process to run. Though current macro points to the interrupted process, but there is no way to find the interrupt handler that sleeps and to continue execution.
3. When do_IRQ() finished the isr, the entry code will then call ret_from_intr() and it checks is a reshcedule is pending(need_resched is set). If the reschedule is pending and the kernel is returning to user-space(that is, the interrupt interrupted a user process), schedule() is called. If the kernel is returning to kernel-space(that is, the interrupt interrupted the kernel itself), schedule() is called only if the preempt_count is zero. After schedule() returns, or if there is no work pending, the initial registers are restored and the kernel resumes whatever was interrupted. (do_IRQ() corresponds to handle_IRQ() under arch/arm/kernel/irq.c for ARM)
4. Sometimes we see spin_lock_irqsave()/spin_unlock_irqrestore() and mutex_lock()/mutex_unlock() pairs and the first is to provide protection against concurrent access from a possible interrupt handler and the later is to provide protection against concurrent access from another processor.
5. Interrupt handlers run asynchronously with at least the current interrupt line disabled.