Opened 9 months ago

Closed 8 days ago

#9261 closed bug (fixed)

-S prints incorrect number of bound tasks

Reported by: edsko Owned by: thomie
Priority: low Milestone: 7.12.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 Revisions: Phab:D746

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 (7)

comment:1 Changed 5 months ago by thomie

  • Cc simonmar added
  • Component changed from Compiler to Runtime System
  • Description modified (diff)
  • difficulty changed from Unknown to Easy (less than 1 hour)
  • Keywords newcomer added
  • Owner set to simonmar

comment:2 Changed 12 days 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 12 days ago by thomie (previous) (diff)

comment:3 Changed 8 days ago by thomie

  • Differential Revisions set to Phab:D746
  • Milestone set to 7.12.1
  • Status changed from new to patch

comment:4 Changed 8 days 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 8 days ago by thomie

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

comment:6 Changed 8 days 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 8 days ago by thomie

  • Resolution set to fixed
  • Status changed from patch to closed

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.

Note: See TracTickets for help on using tickets.