diff options
author | Simon Marlow <marlowsd@gmail.com> | 2016-08-02 09:55:31 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2016-08-03 08:07:34 +0100 |
commit | 55f5aed756cd5d464942dddcb33e0bd19b05f2a4 (patch) | |
tree | f8c0acd76b0945d44cca86946bd638ceee440aa3 /rts/Capability.c | |
parent | 36565a9ba200d40e0be8407e57ada1b4a1c55814 (diff) | |
download | haskell-55f5aed756cd5d464942dddcb33e0bd19b05f2a4.tar.gz |
Track the lengths of the thread queues
Summary:
Knowing the length of the run queue in O(1) time is useful: for example
we don't have to traverse the run queue to know how many threads we have
to migrate in schedulePushWork().
Test Plan: validate
Reviewers: ezyang, erikd, bgamari, austin
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2437
Diffstat (limited to 'rts/Capability.c')
-rw-r--r-- | rts/Capability.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/rts/Capability.c b/rts/Capability.c index 7ca220fbd9..f2220f0651 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -99,7 +99,7 @@ findSpark (Capability *cap) rtsBool retry; uint32_t i = 0; - if (!emptyRunQueue(cap) || cap->returning_tasks_hd != NULL) { + if (!emptyRunQueue(cap) || cap->n_returning_tasks != 0) { // If there are other threads, don't try to run any new // sparks: sparks might be speculative, we don't want to take // resources away from the main computation. @@ -212,6 +212,7 @@ newReturningTask (Capability *cap, Task *task) cap->returning_tasks_hd = task; } cap->returning_tasks_tl = task; + cap->n_returning_tasks++; } STATIC_INLINE Task * @@ -226,6 +227,7 @@ popReturningTask (Capability *cap) cap->returning_tasks_tl = NULL; } task->next = NULL; + cap->n_returning_tasks--; return task; } #endif @@ -249,6 +251,7 @@ initCapability (Capability *cap, uint32_t i) cap->run_queue_hd = END_TSO_QUEUE; cap->run_queue_tl = END_TSO_QUEUE; + cap->n_run_queue = 0; #if defined(THREADED_RTS) initMutex(&cap->lock); @@ -256,8 +259,10 @@ initCapability (Capability *cap, uint32_t i) cap->spare_workers = NULL; cap->n_spare_workers = 0; cap->suspended_ccalls = NULL; + cap->n_suspended_ccalls = 0; cap->returning_tasks_hd = NULL; cap->returning_tasks_tl = NULL; + cap->n_returning_tasks = 0; cap->inbox = (Message*)END_TSO_QUEUE; cap->sparks = allocSparkPool(); cap->spark_stats.created = 0; @@ -507,7 +512,7 @@ releaseCapability_ (Capability* cap, // Check to see whether a worker thread can be given // the go-ahead to return the result of an external call.. - if (cap->returning_tasks_hd != NULL) { + if (cap->n_returning_tasks != 0) { giveCapabilityToTask(cap,cap->returning_tasks_hd); // The Task pops itself from the queue (see waitForCapability()) return; |