2

I have a process with multiple threads. If one of my threads invokes a system call like gettimeofday(), does the kernel only switch that thread out of context to service the system call, or does it switch the entire process (and all other threads) out of context?

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
Jay Piscean
  • 47
  • 1
  • 7
  • Linux is 1:1 threaded; see [threading models on Wikipedia](http://en.wikipedia.org/wiki/Thread_%28computing%29#Models) for others, such as N:1 where a system call switches out all threads, or M:N where 1≤some≤all may be affected. – ephemient Mar 15 '12 at 22:27

2 Answers2

2

Most system calls may involve a context switch (if other tasks are runnable) and switch the processor's state to kernel mode.

But gettimeofday (and e.g. getpid()) are unusual. with recent kernels they use VDSO to avoid it (and even to avoid the syscall or sysenter instruction to switch to kernel mode).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
1

To the linux kernel, a thread is a process. So the kernel has no interest in the other threads of your process when one of them makes a syscall.

bmargulies
  • 97,814
  • 39
  • 186
  • 310