summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2016-08-30 12:10:47 +0100
committerSergei Trofimovich <siarheit@google.com>2016-08-30 12:11:06 +0100
commit9d175605e52fd0d85f2548896358d96ee441c7e4 (patch)
tree362e73fbf3af21ed43e997f02d5fc53a02d4dda6
parent21c2ebf2504125611eec0d24ab3ed60cd9e475be (diff)
downloadhaskell-9d175605e52fd0d85f2548896358d96ee441c7e4.tar.gz
GhcMake: limit Capability count to CPU count in parallel mode
In Trac #9221 one of problems using high --jobs=<N> is amount of mutator (or GC) threads we crate. We use userspace spinning-and-yielding (see ACQUIRE_SPIN_LOCK) to acess work stealing queues. In case of N-worker-threads > N-CPUs fraction of time when thread holding spin lock gets descheduled by kernel increases. That causes other threads to waste CPU time before giving up CPU. Signed-off-by: Sergei Trofimovich <siarheit@google.com> Test Plan: ghc --make -j8 and -j80 have comparable sys time on a 8-core system. Reviewers: austin, gintas, bgamari, simonmar Reviewed By: bgamari, simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2482 GHC Trac Issues: #9221
-rw-r--r--compiler/main/GhcMake.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index bb1c8e3f2d..9197b2c1f6 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -762,7 +762,12 @@ parUpsweep n_jobs old_hpt stable_mods cleanup sccs = do
let updNumCapabilities = liftIO $ do
n_capabilities <- getNumCapabilities
- unless (n_capabilities /= 1) $ setNumCapabilities n_jobs
+ n_cpus <- getNumProcessors
+ -- Setting number of capabilities more than
+ -- CPU count usually leads to high userspace
+ -- lock contention. Trac #9221
+ let n_caps = min n_jobs n_cpus
+ unless (n_capabilities /= 1) $ setNumCapabilities n_caps
return n_capabilities
-- Reset the number of capabilities once the upsweep ends.
let resetNumCapabilities orig_n = liftIO $ setNumCapabilities orig_n