triple fault
triple fault

Reputation: 14146

The use of need_resched flag and schedule() routine within Linux kernel [2.4]

As per my understanding when the kernel finds out that the current running process should be striped of the CPU, it enables the need_resched flag. The flag is then checked before returning to user space, and if the flag enabled the kernel initiates call for schedule(). However I have noticed that within sys_sched_yield() routine we don't use the need_resched flag but explicitly call the schedule() routine. Why?

Upvotes: 1

Views: 4034

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66298

As described here, need_resched flag is used for mark process externally: within interrupt by scheduler_tick() or when process is awoken by other process with try_to_wake_up(). Flag is needed, because the process itself may be not ready for rescheduling, so rescheduling is deffered until safe quiescent state.

If the process itself requests rescheduling, via schedule() call in kernel space, or via sched_yield() system call in user space, kernel performs request immediately. It is assumed that the process knows what it does. In the last case(when sched_yield() is called in user space), kernel knows that it is always safe to rescheduling while process in the user space.

Upvotes: 3

Related Questions