Fall 2014:: CSE 506:: Section 2 (PhD)
Threading
Nima Honarmand (Based on slides by Don Porter and Mike Ferdman)
Threading Nima Honarmand (Based on slides by Don Porter and Mike - - PowerPoint PPT Presentation
Fall 2014:: CSE 506:: Section 2 (PhD) Threading Nima Honarmand (Based on slides by Don Porter and Mike Ferdman) Fall 2014:: CSE 506:: Section 2 (PhD) Threading Review Multiple threads of execution in one address space Why? Exploits
Fall 2014:: CSE 506:: Section 2 (PhD)
Nima Honarmand (Based on slides by Don Porter and Mike Ferdman)
Fall 2014:: CSE 506:: Section 2 (PhD)
– Why?
descriptors, etc.
– One CR3 register and set of page tables
– One mm_struct shared by several task_structs
Fall 2014:: CSE 506:: Section 2 (PhD)
– e.g.: create new thread
– Thread management (join, cleanup, etc.) – Synchronization (mutex, condition variables, etc.) – Thread-local storage
– Between kernel and library
Fall 2014:: CSE 506:: Section 2 (PhD)
– Every application-level thread is kernel-visible
– Called 1:1
– Multiple application-level threads (m)
– Context switching can be done in user space
– Called m:n
Fall 2014:: CSE 506:: Section 2 (PhD)
– Analog of task_struct for each thread
– Stack for each thread – Some sort of run queue
Fall 2014:: CSE 506:: Section 2 (PhD)
Fall 2014:: CSE 506:: Section 2 (PhD)
– Plus cost of saving/restoring registers – Time in the scheduler counts against your timeslice
– At least in some schedulers
– Run the context switch code locally
Fall 2014:: CSE 506:: Section 2 (PhD)
– Thread 1’s quantum expired – Thread 2 spinning until its quantum expires – Can donate Thread 2’s quantum to Thread 1?
– Application’s data and synchronization unknown to kernel
Fall 2014:: CSE 506:: Section 2 (PhD)
– All other user threads in same kernel thread wait – Solvable with async I/O
Fall 2014:: CSE 506:: Section 2 (PhD)
– Working around “unfriendly” kernel API
– Second scheduler – Synchronization different
– Certain functions (locks) – Timer signals from OS
Fall 2014:: CSE 506:: Section 2 (PhD)
– Kernel ctxt switch more expensive than user ctxt switch – Kernel can’t infer application goals as well as programmer
– Better kernel interfaces needed
Fall 2014:: CSE 506:: Section 2 (PhD)
– Not available on Linux
user scheduler
– Eliminates most libc changes – Easier notification of blocking events
runnable tasks it has (via system call)
Fall 2014:: CSE 506:: Section 2 (PhD)
programmers more control over performance
– E.g., microkernels, extensible OSes, etc.
abstractions are keeping me from getting full performance of my hardware
– High-performance databases generally get direct control
Fall 2014:: CSE 506:: Section 2 (PhD)
– Correlated with efficiency of OS thread create and switch
– User-level thread packages were hot (e.g., LinuxThreads)
– Native POSIX Thread Library (NPTL) – Most JVMs abandoned user threads
Fall 2014:: CSE 506:: Section 2 (PhD)
– Correctness – Performance (Synchronization)
– Manager thread – List of all threads – etc.
Fall 2014:: CSE 506:: Section 2 (PhD)
1) The behavior of sending a signal to a multi-threaded process was not correct. And could never be implemented correctly with kernel-level tools (pre 2.6)
2) Signals were also used to implement blocking
a signal to the next blocked task to wake it up.
Fall 2014:: CSE 506:: Section 2 (PhD)
thread
– 2.4 assigned different PID to each thread
– POSIX says I should be able to send a signal to a multi- threaded program and any unmasked thread will get the signal, even if the first thread has exited
Fall 2014:: CSE 506:: Section 2 (PhD)
– Essentially a shared wait queue in the kernel
– Use an atomic instruction in user space to implement fast path for a lock (more in later lectures) – If task needs to block, ask the kernel to put you on a given futex wait queue – Task that releases the lock wakes up next task on the futex wait queue