summaryrefslogtreecommitdiff
path: root/rts/Task.c
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2012-07-04 10:34:48 +0100
committerSimon Marlow <marlowsd@gmail.com>2012-07-04 10:34:48 +0100
commit99fd2469fba1a38b2a65b4694f337d92e559df01 (patch)
tree20491590ccb07223afd9d1f6a6546213b0f43577 /rts/Task.c
parentd260d919eef22654b1af61334feed0545f64cea5 (diff)
parent0d19922acd724991b7b97871b1404f3db5058b49 (diff)
downloadhaskell-99fd2469fba1a38b2a65b4694f337d92e559df01.tar.gz
Merge remote-tracking branch 'origin/master' into newcg
* origin/master: (756 commits) don't crash if argv[0] == NULL (#7037) -package P was loading all versions of P in GHCi (#7030) Add a Note, copying text from #2437 improve the --help docs a bit (#7008) Copy Data.HashTable's hashString into our Util module Build fix Build fixes Parse error: suggest brackets and indentation. Don't build the ghc DLL on Windows; works around trac #5987 On Windows, detect if DLLs have too many symbols; trac #5987 Add some more Integer rules; fixes #6111 Fix PA dfun construction with silent superclass args Add silent superclass parameters to the vectoriser Add silent superclass parameters (again) Mention Generic1 in the user's guide Make the GHC API a little more powerful. tweak llvm version warning message New version of the patch for #5461. Fix Word64ToInteger conversion rule. Implemented feature request on reconfigurable pretty-printing in GHCi (#5461) ... Conflicts: compiler/basicTypes/UniqSupply.lhs compiler/cmm/CmmBuildInfoTables.hs compiler/cmm/CmmLint.hs compiler/cmm/CmmOpt.hs compiler/cmm/CmmPipeline.hs compiler/cmm/CmmStackLayout.hs compiler/cmm/MkGraph.hs compiler/cmm/OldPprCmm.hs compiler/codeGen/CodeGen.lhs compiler/codeGen/StgCmm.hs compiler/codeGen/StgCmmBind.hs compiler/codeGen/StgCmmLayout.hs compiler/codeGen/StgCmmUtils.hs compiler/main/CodeOutput.lhs compiler/main/HscMain.hs compiler/nativeGen/AsmCodeGen.lhs compiler/simplStg/SimplStg.lhs
Diffstat (limited to 'rts/Task.c')
-rw-r--r--rts/Task.c104
1 files changed, 47 insertions, 57 deletions
diff --git a/rts/Task.c b/rts/Task.c
index 36dd0a94b9..125000b914 100644
--- a/rts/Task.c
+++ b/rts/Task.c
@@ -26,7 +26,12 @@
// Task lists and global counters.
// Locks required: all_tasks_mutex.
Task *all_tasks = NULL;
-static nat taskCount;
+
+nat taskCount;
+nat workerCount;
+nat currentWorkerCount;
+nat peakWorkerCount;
+
static int tasksInitialized = 0;
static void freeTask (Task *task);
@@ -64,8 +69,11 @@ void
initTaskManager (void)
{
if (!tasksInitialized) {
- taskCount = 0;
- tasksInitialized = 1;
+ taskCount = 0;
+ workerCount = 0;
+ currentWorkerCount = 0;
+ peakWorkerCount = 0;
+ tasksInitialized = 1;
#if defined(THREADED_RTS)
#if !defined(MYTASK_USE_TLV)
newThreadLocalKey(&currentTaskKey);
@@ -87,7 +95,7 @@ freeTaskManager (void)
ACQUIRE_LOCK(&all_tasks_mutex);
for (task = all_tasks; task != NULL; task = next) {
- next = task->all_link;
+ next = task->all_next;
if (task->stopped) {
freeTask(task);
} else {
@@ -164,9 +172,6 @@ freeTask (Task *task)
static Task*
newTask (rtsBool worker)
{
-#if defined(THREADED_RTS)
- Time currentElapsedTime, currentUserTime;
-#endif
Task *task;
#define ROUND_TO_CACHE_LINE(x) ((((x)+63) / 64) * 64)
@@ -186,26 +191,25 @@ newTask (rtsBool worker)
task->wakeup = rtsFalse;
#endif
-#if defined(THREADED_RTS)
- currentUserTime = getThreadCPUTime();
- currentElapsedTime = getProcessElapsedTime();
- task->mut_time = 0;
- task->mut_etime = 0;
- task->gc_time = 0;
- task->gc_etime = 0;
- task->muttimestart = currentUserTime;
- task->elapsedtimestart = currentElapsedTime;
-#endif
-
task->next = NULL;
ACQUIRE_LOCK(&all_tasks_mutex);
- task->all_link = all_tasks;
+ task->all_prev = NULL;
+ task->all_next = all_tasks;
+ if (all_tasks != NULL) {
+ all_tasks->all_prev = task;
+ }
all_tasks = task;
taskCount++;
-
+ if (worker) {
+ workerCount++;
+ currentWorkerCount++;
+ if (currentWorkerCount > peakWorkerCount) {
+ peakWorkerCount = currentWorkerCount;
+ }
+ }
RELEASE_LOCK(&all_tasks_mutex);
return task;
@@ -314,14 +318,15 @@ discardTasksExcept (Task *keep)
// Wipe the task list, except the current Task.
ACQUIRE_LOCK(&all_tasks_mutex);
for (task = all_tasks; task != NULL; task=next) {
- next = task->all_link;
+ next = task->all_next;
if (task != keep) {
- debugTrace(DEBUG_sched, "discarding task %ld", (long)TASK_ID(task));
+ debugTrace(DEBUG_sched, "discarding task %" FMT_SizeT "", (size_t)TASK_ID(task));
freeTask(task);
}
}
all_tasks = keep;
- keep->all_link = NULL;
+ keep->all_next = NULL;
+ keep->all_prev = NULL;
RELEASE_LOCK(&all_tasks_mutex);
}
@@ -337,7 +342,7 @@ void updateCapabilityRefs (void)
ACQUIRE_LOCK(&all_tasks_mutex);
- for (task = all_tasks; task != NULL; task=task->all_link) {
+ for (task = all_tasks; task != NULL; task=task->all_next) {
if (task->cap != NULL) {
task->cap = &capabilities[task->cap->no];
}
@@ -353,34 +358,6 @@ void updateCapabilityRefs (void)
}
-void
-taskTimeStamp (Task *task USED_IF_THREADS)
-{
-#if defined(THREADED_RTS)
- Time currentElapsedTime, currentUserTime;
-
- currentUserTime = getThreadCPUTime();
- currentElapsedTime = getProcessElapsedTime();
-
- task->mut_time =
- currentUserTime - task->muttimestart - task->gc_time;
- task->mut_etime =
- currentElapsedTime - task->elapsedtimestart - task->gc_etime;
-
- if (task->gc_time < 0) { task->gc_time = 0; }
- if (task->gc_etime < 0) { task->gc_etime = 0; }
- if (task->mut_time < 0) { task->mut_time = 0; }
- if (task->mut_etime < 0) { task->mut_etime = 0; }
-#endif
-}
-
-void
-taskDoneGC (Task *task, Time cpu_time, Time elapsed_time)
-{
- task->gc_time += cpu_time;
- task->gc_etime += elapsed_time;
-}
-
#if defined(THREADED_RTS)
void
@@ -391,9 +368,22 @@ workerTaskStop (Task *task)
ASSERT(task->id == id);
ASSERT(myTask() == task);
- task->cap = NULL;
- taskTimeStamp(task);
- task->stopped = rtsTrue;
+ ACQUIRE_LOCK(&all_tasks_mutex);
+
+ if (task->all_prev) {
+ task->all_prev->all_next = task->all_next;
+ } else {
+ all_tasks = task->all_next;
+ }
+ if (task->all_next) {
+ task->all_next->all_prev = task->all_prev;
+ }
+
+ currentWorkerCount--;
+
+ RELEASE_LOCK(&all_tasks_mutex);
+
+ freeTask(task);
}
#endif
@@ -403,7 +393,7 @@ workerTaskStop (Task *task)
static void *taskId(Task *task)
{
#ifdef THREADED_RTS
- return (void *)task->id;
+ return (void *)(size_t)task->id;
#else
return (void *)task;
#endif
@@ -491,7 +481,7 @@ void
printAllTasks(void)
{
Task *task;
- for (task = all_tasks; task != NULL; task = task->all_link) {
+ for (task = all_tasks; task != NULL; task = task->all_next) {
debugBelch("task %p is %s, ", taskId(task), task->stopped ? "stopped" : "alive");
if (!task->stopped) {
if (task->cap) {