title: How are the system calls handled by the linux scheduler on a multicore platform
body: <p>I'm trying to understand how multithreaded scheduling is realised under linux with a preemptible kernel. And in particular how the system calls are executed in multithreaded, multicore environment.</p>
  
  <p>If I understand correctly, the linux kernel is using a one-to-one model, i.e. for every user-level thread, a dedicated kernel-thread is created. Now I am not sure if I understand correctly how the threads are treated by the scheduler.</p>
  
  <p>By means of the following example I'd like to describe my current understanding:</p>
  
  <p><a href="https://i.stack.imgur.com/tTEbg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tTEbg.jpg" alt="Corresponding figure to the following example"></a></p>
  
  <p>Lets assume we have a platform consisting of 2 CPUs, and 3 user-level threads (T1,T2,T3). Then additionally, 3 dedicated kernel threads will be created by the linux kernel (respectively kT1, kT2, kT3). </p>
  
  <p>Lets assume at time t0 the threads T1 and T2 get selected for parallel execution on the 2 available CPUs. No corresponding kernel thread is running yet, because no syscall has been mad so far.</p>
  
  <p>At time t1, thread T1 calls a syscall. Therefore the thread T1 gets suspended and the CPU1 is assigned to kernel thread kT1.</p>
  
  <p>Now lets assume at time t2 the kernel thread kT1 has to wait for some I/0. Therefore the scheduler suspends kT1 and selects user-level thread T3 for execution on CPU1.</p>
  
  <p>At time t3, thread T2 calls some syscall aswell.
  T2 gets suspended, and CPU2 is assigned to kernel thread kT2.</p>
  
  <p>At time t4 the data that kT1 has been waiting for becomes ready. The scheduler chooses (randomy) to preempt kT2 and assigns CPU2 to kT1.</p>
  
  <p>At time t5 the syscall execution of kT1 returns to user space. I.e. kT1 becomes non-runnable, and T1 is selected for execution on CPU2.</p>
  
  <p>At time t6 the user-space thread T3 terminates, and the CPU1 gets assigned to kT2.</p>
  
  <p>At time t7 the syscall execution of kT2 returns to user space.</p>
  
  <p>Is this how a execution might have happend during runtime? Is the scheduler aware of the difference between kernel and user space threads or are they treated equivalently (like in this example)?
  What about the thread priorities/nice values. Do the kernel threads inherit those properties from corresponding user-level threads?</p>