0
votes

The book "understanding Linux kernel" mentions several ways which will suspend a process running in kernel mode (Chapter 1, page 22). Here they are:

  1. a system call request cannot be satisfied immediately
  2. The CPU detects an exception
  3. A hardware interrupt occurs
  4. An interrupt occurs while the CPU is running with kernel preemption enabled, and a higher priority process is runnable.

It does not mention the process runs out its time-slice and the scheduler brings another same priority process to run. I think this should be one case to suspend a process running in kernel mode. Please comment.

2
Wouldn't that come under point number 4? The scheduler is usually run on a timer interrupt.tangrs
Yes, context switch doesnt occurs by itself. CS implemented in system timer interrupt handler.Alex Hoppus
number 4 is about a higher priority process is runnable. My concern is about the same or lower priority process.user1443721
man 7 sched: 'The thread to run is chosen from the static priority 0 list based on a dynamic priority that is determined only inside this list. The dynamic priority is based on the nice value (see below) and is increased for each time quantum the thread is ready to run, but denied to run by the scheduler. This ensures fair progress among all SCHED_OTHER threads.'n. 1.8e9-where's-my-share m.

2 Answers

0
votes

The end of a timeslice is detected when the scheduler runs in the timer interrupt, which falls under 3.

0
votes

In Linux Kernel, a process running out of its time slice does not automatically gets suspended. What happens is, during timer interrupt, the kernel checks whether the current's process has run long enough in check_preempt_tick() . If it has run long enough, kernel sets the TIF_NEED_RESCHED flag by calling resched_curr().

Now when returning from timer interrupt, kernel checks whether TIF_NEED_RESCHED flag is set or not for the current process. If it is set and preemption is enabled, kernel calls schedule() where a new process is selected to run.

Actually, whenever an interrupt occurs(even other than timer interrupt), the kernel checks whether current process can be preempted or not and calls schedule() accordingly.