Opened 3 years ago

Closed 2 years ago

Last modified 21 months ago

#9261 closed bug (fixed)

-S prints incorrect number of bound tasks

Reported by: edsko Owned by: thomie
Priority: low Milestone: 8.0.1
Component: Runtime System Version: 7.8.2
Keywords: Cc: simonmar
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #8124 Differential Rev(s): Phab:D746
Wiki Page:

Description (last modified by thomie)

In rts/Stats.c we have:

            statsPrintf("  TASKS: %d (%d bound, %d peak workers (%d total), using -N%d)\n",
                        taskCount, taskCount - workerCount,
                        peakWorkerCount, workerCount,
                        n_capabilities);

but I think taskCount - workerCount must be wrong, because taskCount is the _current_ number of tasks, while workerAcount is the _total_ number of workers (accumulating). I think it should be:

            statsPrintf("  TASKS: %d (%d bound, %d peak workers (%d total), using -N%d)\n",
                        taskCount, taskCount - currentWorkerCount,
                        peakWorkerCount, workerCount,
                        n_capabilities);

Change History (8)

comment:1 Changed 3 years ago by thomie

Cc: simonmar added
Component: CompilerRuntime System
Description: modified (diff)
difficulty: UnknownEasy (less than 1 hour)
Keywords: newcomer added
Owner: set to simonmar

comment:2 Changed 2 years ago by thomie

Keywords: newcomer removed
Owner: changed from simonmar to thomie

@edsko: I think the code is correct as is.

taskCount is not decremented when a worker task is stopped (i.e. from workerTaskStop), but only when freeMyTask is called, which frees the task bound to the current thread. So taskCount is the current number of bound tasks + the total number of worker tasks.

I suggest to just add a comment to the definition of taskCount: // currentBoundCount + workerCount. Do you agree?

Last edited 2 years ago by thomie (previous) (diff)

comment:3 Changed 2 years ago by thomie

Differential Rev(s): Phab:D746
Milestone: 7.12.1
Status: newpatch

comment:4 Changed 2 years ago by edsko

I'm not sure to be honest. I reported this because I (thought I) was getting incorrect numbers reported, not because I was looking at the source code. I was looking at the source code only _because_ I was getting strange numbers. But I've forgotten the details; if you're sure it's correct..

comment:5 Changed 2 years ago by thomie

Well, I've only studied the source code, I didn't actually run anything..

comment:6 Changed 2 years ago by Thomas Miedema <thomasmiedema@…>

In 5449b25d02cca0c4ae706c9152f5f2c6107fe711/ghc:

Clarify meaning of the RTS `taskCount` variable

In #9261, there was some confusion about the meaning of the taskCount
stats variable in the rts.

It turns out that taskCount is not decremented when a worker task is
stopped (i.e. from workerTaskStop), but only when freeMyTask is called,
which frees the task bound to the current thread. So taskCount is the
current number of bound tasks + the total number of worker tasks.

This makes the calculation of the current number of bound tasks in
rts/Stats.c correct _as is_.

[skip ci]

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D746

comment:7 Changed 2 years ago by thomie

Resolution: fixed
Status: patchclosed

The code seems correct to me, so I'm closing this. But if you think you really do see weird numbers reported, of course reopen.

Note that if your code doesn't explicitly call hs_thread_done (#8124), the number of bound tasks never decreases. So taskCount would be the sum of the total number of bound tasks and the total number of worker tasks ever created in that case.

comment:8 Changed 21 months ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.