Repository navigation
Count tasks, not process leaders - #9
Merged
Merged
Conversation
The interference field merged an hour ago counted processes, and `/proc/<pid>/stat` reports the state of the thread group leader. A run of membench on an idle box reported `runnable: 0` while its own worker threads were the busiest things on the machine, because the leader of a benchmark that pins workers and joins on them is asleep for most of the run. That is the exact shape of the thing the field was added for. A process with a sleeping leader and eight memory-hungry threads is what "nothing was running" looks like from a leader-only scan, and the complaint in issue #5 was that a cell moved 25% with nothing apparently running. So the scan walks /proc/<pid>/task/<tid>/stat and the count is tasks. RunningProcess is RunningTask; the pid in each entry stays the process id because the comm already says which thread it was, and a reader follows it up with `ps -p`. Ten runs of a tiny grid on a 113-process box: 656 ms before, 679 ms after, against a binary built before this feature existed at all, so the whole instrument costs about 25 ms of a run that spends most of its time starting up. Twice per run, outside every timed region. A test spins a named thread and requires the sample to count it, so this cannot regress back to leaders unnoticed. It asks for the name only when the capped list was not full: on a busy machine our thread may fairly miss the cap, and a test that failed for that reason would be blaming the wrong thing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #8, and it is a correction to it rather than an addition.
The
interferencefield I merged an hour ago counted processes./proc/<pid>/statreports the state of the thread group leader, so it said what the leader was doing and nothing about the threads underneath it. On an idle box a run of membench reported:while its own worker threads were the busiest things on the machine. I noticed because the number looked wrong on a machine where nothing else was running, and it was: the leader of a benchmark that pins worker threads and joins on them is asleep for most of the run.
That inverts the one thing the field was for. The complaint in issue #5 was that a cell moved by 25% and nothing looked like it was running. A process with a sleeping leader and eight memory-hungry threads is precisely what the leader-only scan reports as an idle machine, and it is what most of the interference anyone has complained about actually looks like from
/proc.The scan now walks
/proc/<pid>/task/<tid>/stat, so the count is tasks.RunningProcessbecameRunningTask; thepidin each entry stays the process id, because the comm already says which thread it was and a reader follows it up withps -p. The list stays capped at eight and the README now says "tasks", which the previous paragraph did not.After the change, on the same idle box:
including the run's own worker, still runnable at the end sample because the end sample is taken before the last of them has been joined.
Cost. A thousand small reads is not free:
656 ms → 679 msper tiny run (ten runs, one process, against a binary built before this feature existed at all) on a box with 113 processes. Both figures are dominated by process startup, so the honest statement is that the whole feature lands inside about 25 ms of a run that does nearly half a second of work. On a machine with far more threads than this one it will cost more, and it happens twice per run, outside every timed region.A test spins a named thread inside the test process and requires the sample to count it and to name it, so this cannot quietly regress to leaders again. It asserts the name only when the capped list was not full, because on a busy machine our thread may fairly miss the cap — a test that failed for that reason would be blaming the wrong thing.
scripts/ci.shis green end to end, including the AArch64 clippy step from #8. 117 core + 23 binary tests.