1

Say we have one CPU with only one core, and there are many threads that are running on this core.

Let's say that Thread A has issued a system call, now the interrupt handler for the system call will be executed.

Now while the the system call is being executed, say that the hardware timer interrupt (the one responsible for the scheduling of threads) fires. What will happen in this case, will the CPU stop running the system call and go to execute the scheduler code, or does the CPU must wait for the system call to be fully executed before switching to another thread?

user4582812
  • 591
  • 1
  • 4
  • 16

2 Answers2

2

In Linux the answer is actually dependent on a kernel build time configuration option called CONFIG_PREEMPT. There are actually three options:

If CONFIG_PREEMPT is not set, the interrupt handler will mark a flag indicating that the scheduler needs to run. The flag will be checked on return to user space upon system call termination.

If CONFIG_PREEMPT_VOLUNTARY is set, the same will occur except the flag will be checked and the scheduler run (and task possibly switched if needed) at specific static code points in the system call code

If CONFIG_PREEMPT_FULL is set, the scheduler will run in most cases on the return code path from the interrupt handler to the system call code, unless a preempt critical section is in force.

gby
  • 14,900
  • 40
  • 57
0

Unless the system call blocks interrupts, the interrupt handler will get invoked.

user3344003
  • 20,574
  • 3
  • 26
  • 62