Lazy kernel thread binding
Various technologies and techniques are disclosed for providing lazy kernel thread binding. User mode and kernel mode portions of thread scheduling are decoupled so that a particular user mode thread can be run on any one of multiple kernel mode threads. A dedicated backing thread is used whenever a user mode thread wants to perform an operation that could affect the kernel mode thread, such as a system call. For example, a notice is received that a particular user mode thread running on a particular kernel mode thread wants to make a system call. A dedicated backing thread that has been assigned to the particular user mode thread is woken. State is shuffled from the user mode thread to the dedicated backing thread using a state shuffling process. The particular kernel mode thread is put to sleep. The system call is executed using the dedicated backing thread.
1 . A computer-readable medium having computer-executable instructions for causing a computer to perform steps comprising:
decouple user mode and kernel mode portions of thread scheduling so that a particular user mode thread can be run on any one of a plurality of kernel mode threads.
2 . The computer-readable medium of claim 1 , wherein a user mode scheduler is responsible for dispatching of the particular user mode thread on a particular kernel mode thread of the plurality of kernel mode threads.
3 . The computer-readable medium of claim 1 , wherein when the particular user mode thread running on a particular kernel mode thread of the plurality of kernel mode threads wants to perform an action that could affect the particular kernel mode thread, a state shuffling process is performed to shuffle state from the particular user mode thread to a respective dedicated backing thread.
4 . The computer-readable medium of claim 3 , wherein the action is a system call.
5 . The computer-readable medium of claim 3 , wherein the state shuffling process is operable to save a register state of the particular user mode thread.
6 . The computer-readable medium of claim 5 , wherein the state shuffling process is further operable to restore the register state to the respective dedicated backing thread.
7 . The computer-readable medium of claim 6 , wherein the state shuffling process is further operable to put the particular kernel mode thread to sleep.
8 . The computer-readable medium of claim 7 , wherein the state shuffling process is further operable to wake up the respective dedicated backing thread.
9 . A method for using a dedicated backing thread for a system call for a user mode thread running on a kernel mode thread comprising the steps of:
receiving notice that a particular user mode thread running on a particular kernel mode thread wants to make a system call;
waking a dedicated backing thread that has been assigned to the particular user mode thread;
shuffling state from the user mode thread to the dedicated backing thread;
putting the particular kernel mode thread to sleep; and
executing the system call using the dedicated backing thread.
10 . The method of claim 9 , wherein the waking, shuffling, and putting stages are only performed if the user-mode thread is not already running on the dedicated backing thread.
11 . The method of claim 9 , further comprising:
waking the particular kernel mode thread so the particular kernel mode thread can regain control.
12 . The method of claim 9 , wherein the particular kernel mode thread will remain asleep until receiving a waking event so as not to preempt the backing thread.
13 . The method of claim 9 , wherein before the backing thread is woken, setting a thread affinity to a same processor core as the particular kernel mode thread.
14 . The method of claim 13 , wherein the thread affinity is set to the same processor to ensure that instruction and cache locality is maintained.
15 . The method of claim 9 , wherein on a subsequent time that a subsequent user mode thread is selected for execution, and execution is currently taking place on a particular corresponding backing thread, the particular corresponding backing thread and subsequent user mode thread are transitioned to a base state, the particular kernel mode thread is woken, and the subsequent user mode thread is run.
16 . A computer-readable medium having computer-executable instructions for causing a computer to perform the steps recited in claim 9 .
17 . A method for shuffling state from a user mode thread running on a kernel mode thread to a backing thread comprising the steps of:
receiving notice that a particular user mode thread running on a particular kernel mode thread wants to make a system call;
saving a register state of the particular user mode thread;
putting the particular kernel mode thread to sleep;
waking up a respective backing thread that was assigned to the particular user-mode thread; and
restoring the register state to the respective backing thread.
18 . The method of claim 17 , further comprising:
executing the system call using the respective backing thread.
19 . The method of claim 18 , further comprising:
waking up the particular kernel mode thread so it can regain control.
20 . A computer-readable medium having computer-executable instructions for causing a computer to perform the steps recited in claim 17 .