Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the scheduler of the GHC RTS, why should it mark a capability as free?

When I read through the GHC Wiki commentary on the scheduler I was confused about this section:

One reason behind marking a Capability as free when it is handed over is to support fast callouts. When making a safe foreign call we have to release the Capability, and therefore hand it over to another worker thread. If the foreign call is short, we don't want to incur the cost of a context switch on returning, but since we marked the Capability as free there's a good chance the returning Task will be able to re-acquire it immediately and continue. The worker that we woke up will find that the Capability is owned, and go back to sleep again (this may incur a double context switch if there are no free CPUs on which to run the worker, however).

My question:
For the bold sentence, what indeed will lead to the "Double context switch", with or without marking a capability as free. Furthermore, what are the two "switches" if they happen -- from who1 to who2, then who2 to who3?

like image 254
wuxb Avatar asked May 18 '11 14:05

wuxb


1 Answers

Partially answered here: http://www.haskell.org/pipermail/cvs-ghc/2011-May/062287.html (a copy: http://markmail.org/message/2q6fjthw2wvof244?q=switch+list:org.haskell.cvs-ghc&page=2)

like image 115
Edward Z. Yang Avatar answered Oct 01 '22 02:10

Edward Z. Yang