Re: Why does scheduler is called during "return of system call" ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

The scheduler is called at return from a system call /*only*/ if the need_resched flag in the process's task structure is set (you find the assembly code implementing this
logic in arch/i386/kernel/entry.S - after the ret_from_sys_call label).

The reason is to ensure fairness among the processes, while keeping the kernel non-preemptive. I.e. a process will never bee preemted while running in kernel mode, and the
need_resched flag is maintained and set (by the timer interrupt), when the process's time slice expires while it is running in kernel mode.
At return from system call the flag is checked, in order to preempt a process at the earliest moment, after it's time slice expired (while respecting the non-preemptiveness
of the Linux kernel).

When the scheduler is called during return from system call, it does the same as when it is called from elsewhere - it chooses the most suitable process to run next on the
CPU, and does the process switch.

regards
Martin

"Nirranjan.K" wrote:

> In Linux, Scheduler is invoked when
>
> * Time slice of a process expires
>
> * when the process blocks
>
> * return of system call
>
> Why does scheduler is called during "return of system call" ? What does
> scheduler do when called during return of system call.
>
> Please clarify my doubt.
>
> Thanks and regards,
> Nirranjan.K
>
> -
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> IRC Channel:   irc.openprojects.net / #kernelnewbies
> Web Page:      http://www.kernelnewbies.org/

--
Supercomputing System AG          email: maletinsky@scs.ch
Martin Maletinsky                 phone: +41 (0)1 445 16 05
Technoparkstrasse 1               fax:   +41 (0)1 445 16 10
CH-8005 Zurich


-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux