1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Please come up with a better title. It does not seem as if this has anything to do with Google. $\endgroup$ – Raphael Apr 15 '17 at 8:22
  • $\begingroup$ @Raphael Paul was/is working at google at that time and the patch is often referred to as google's proposal for kernel threads. $\endgroup$ – Ashish Negi Apr 15 '17 at 14:38
2
+25
$\begingroup$

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").

$\endgroup$
  • $\begingroup$ ok, so runtime here means time ? i thought it as runtime environment. $\endgroup$ – Ashish Negi Apr 15 '17 at 14:46
  • $\begingroup$ 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 ; $\endgroup$ – Ashish Negi Apr 15 '17 at 14:49
  • $\begingroup$ @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. $\endgroup$ – PPenguin Apr 17 '17 at 2:01
  • $\begingroup$ 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". $\endgroup$ – PPenguin Apr 17 '17 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.