schedulePushWork: avoid unnecessary wakeups
authorSimon Marlow <marlowsd@gmail.com>
Sun, 24 Apr 2016 20:31:55 +0000 (21:31 +0100)
committerSimon Marlow <smarlow@fb.com>
Wed, 4 May 2016 12:30:30 +0000 (05:30 -0700)
commit1fa92ca9b1ed4cf44e2745830c9e9ccc2bee12d5
tree767363253d30e007c1d78441b7caa7d83c193802
parentf703fd6b50f0ae58bc5f5ddb927a2ce28eeaddf6
schedulePushWork: avoid unnecessary wakeups

This function had some pathalogically bad behaviour: if we had 2 threads
on the current capability and 23 other idle capabilities, we would

* grab all 23 capabilities
* migrate one Haskell thread to one of them
* wake up a worker on *all* 23 other capabilities.

This lead to a lot of unnecessary wakeups when using large -N values.

Now, we

* Count how many capabilities we need to wake up
* Start from cap->no+1, so that we don't overload low-numbered capabilities
* Only wake up capabilities that we migrated a thread to (unless we have
  sparks to steal)

This results in a pretty dramatic improvement in our production system.
rts/Schedule.c