I came across Paul Turner work on increasing efficiency of M:N threading model. I am not able to grasp the concept at slide 18 of LPC-User-Threading

It says : for two threads A and B :

Minimal scheduling operation. ● B inherits A’s virtual runtime. ● B was not runnable, so we don’t need to remove it from runqueues. ● B holds references on same objects as A 

What does virtual runtime mean in this case ?

Will not a random thread B inheriting A's environment and referencing same objects cause any problems ?

The video is present at video for the interested.

• Please come up with a better title. It does not seem as if this has anything to do with Google. – Raphael Apr 15 '17 at 8:22
• @Raphael Paul was/is working at google at that time and the patch is often referred to as google's proposal for kernel threads. – Ashish Negi Apr 15 '17 at 14:38
• What this operation makes possible is using a userspace scheduler to schedule kernel threads. So it's not really M:N threading but a kind of hybrid approach, with the thread being a kernel thread but not using the kernel scheduler. – JanKanis Aug 4 '20 at 10:09

This is talking about user level threads, so they should all have the same memory context (virtual memory map). So while the threads need to be careful in doing so, they can all access each other's objects directly without using inter-process communication.

The scheduler will give each thread a time slot to run in (length possibly depending on priority). He is discussing an addition to the kernel to allow a request:

pid_t switchto_switch(pid_t tid)

• Synchronously transfer control to target sibling thread, leaving the current thread unscheduled.
• Analogous to: Atomically { Resume(t1); Wait(NULL); }

So as a programmer, if you had work on a task that you need to stop and wait for information from another task before you can continue, then you could request to immediately switch to that specific thread.

Your intial thread would immediately be put in a wait state, and the other thread would resume execution using the initial thread's currently scheduled time ("B inherits A’s virtual runtime").

• ok, so runtime here means time ? i thought it as runtime environment. – Ashish Negi Apr 15 '17 at 14:46
• Your intial thread would immediately be put in a wait state, and the other thread would resume execution : but, how is this different from normal M:N model of user threads ? because user-level-scheduler that do this itself as well ; – Ashish Negi Apr 15 '17 at 14:49
• @AshishNegi Well he probably does mean more than just time when he says "runtime" (it would be the saved registers, etc. to swap in B), but the virtual memory environment should be the same for the two since they are threads. – PPenguin Apr 17 '17 at 2:01
• Regarding your second question, I think a key part here is when describing the problem they are trying to solve, in one slide he explains that in a modern cpu actual switching (to/from ring0) is fast, but "Majority of the context-switching cost attributable to the complexity of the scheduling decision by a modern SMP cpu scheduler." Here the switchto syscall allows the user thread to, in a way, override scheduling (and placement) decisions, but in a way that doesn't mess with the scheduler operation (like explicit affinity, special cases, etc.) since we are kind of just "swapping". – PPenguin Apr 17 '17 at 2:06