April 12th Lecture ===================== Mapping of threads to kernel scheduling entities: * kernel: "1:1 mapping" * user: "N:1 mapping" * hybrid: "N:M mapping" - one option: associate groups of threads with individual kernel processes Scheduler activations: * kernel provides notifications ("upcalls") to notify a user-level scheduler of important events, but leaves their processing to user-space * no need for user-space libraries to "poll" the kernel with non-blocking IO system calls anymore * based on the idea of "virtual processors" * implementations: - FreeBSD: KSE ("Kernel Scheduled Entities") since 5.0 - Linux: VPI ("Virtual Processor Interface") 3rd party patch independent from official kernel tree Synchronization Consider (assume x starts as 0): T1 T2 == == x = x + 1 x = x + 2 What is the final value of x? 3? 2? 1? It could be any of the above. Look at the assembly generated: T1 T2 ==== ==== load R0, X load R1, X add R0, #1 add R1, #2 store X, R0 store X, R1 Remember that a context switch could occur at any time. T1 T2 ==== ==== load R0, X add R0, #1 load R1, X add R1, #2 store X, R1 store X, R0 All of T2's work is lost!