%Processes %Thadeu Cascardo # Process Context * System calls * Kernel Stack * User space memory access * current process # Interrupts * May race with a process * Usually blocks all other interrupts * Must be fast # Bottom Halves: the old way * Interrupts would work in the top halves and schedule a bottom half for execution * Bottom halves executed with interrupts enabled * They were static: drivers could not dynamically create them * Only one bottom half could execute at a time, even in SMP systems # Softirqs: scaling Linux * They were introduced to put the IRQ handling to scale * They are static as well, but two of the softirqs are dedicated to tasklets * Tasklets allow drivers to schedule some code for execution dynamically # Sleeping * There are many places in the code that will wait for an event * Waiting should release the processor to another process: that means that the current process (the waiter) will sleep * Sleep is equivalent to scheduling, that is, picking up another process to execute * Scheduling another process is prone to races # Atomic context * Contexts that cannot sleep or schedule * IRQs and softirqs are atomic * They cannot access user space * They cannot sleep # Current softirqs * High priority tasklets * Timers * Network transmit * Network receive * Block softirq * Block iopoll * Low priority tasklets * Scheduler * High Resolution Timers * RCU # SMP * Races, races, races * BKL * Scalable locking is needed * SMP-safety is what people are selling and buying * Only local IRQs are disabled # Preemption * Now, a single CPU may race with itself * Different problems, different care and approach * Some problems are the same and SMP-safety is now relevant in UP systems # Disabling IRQs * local\\_irq\\_disable * local\\_irq\\_enable * local\\_irq\\_save * local\\_irq\\_restore # Disabling Preemption * preempt\\_disable * preempt\\_enable * preempt\\_enable\\_no\\_resched # SMP functions * smp\\_processor\\_id * get\\_cpu * put\\_cpu