0
votes

I understand that Linux scheduler schedules threads, not processes, but I do not understand how do threads within a process get scheduled.

Say I have a process P1 with threads T1,T2 and a process P2 with threads T1,T2,T3. Now the scheduler has to schedule 5 tasks. P1T1, P1T2, P2T1, P2T2 and P2T3. If the scheduler picks up P1T1 and then picks up P2T2, this will lead to process context switching, which defeats the purpose of threading. How does the scheduler work in this case ?

2

2 Answers

0
votes

Linux scheduler is growing so fast, and so does the algorithms. if you consider CFS scheduler , please have a look at http://www.ibm.com/developerworks/library/l-completely-fair-scheduler/.

you will find your answer at the section CFS group scheduling .

Hope this will help.

0
votes

Switching from P1T1 to P1T2 IS a context switch. The only difference between a P1T1 to P1T2 context switch and a T1P1 to a T2P1 context switch is affect on cache thrashing, mainly the TLB cache, which in modern processors is quite minimal due to the use of ASID by the MMU.

Even without ASID support, it is not obvious at all that these inter-process context switch actually cost more and when they do that it is significant. For details, see my presentation from CELF below.

In light of the above, the kernel scheduler doesn't and shouldn't care.

Slides: http://tree.celinuxforum.org/CelfPubWiki/ELCEurope2009Presentations?action=AttachFile&do=get&target=Ben-Yossef-GoodBadUgly.pdf

Video http://free-electrons.com/pub/video/2009/elce/elce2009-ben-yossef-threads-processes.ogv