Repository navigation
Account for counted sequence contention in population estimates - #9
Merged
Merged
Conversation
This was referenced Sep 23, 2026
lhotari
force-pushed
the
population-estimate-accounted-loss
branch
from
September 23, 2026 20:27
54431cc to
9ffa73d
Compare
Every real capture so far reported the population estimate unavailable because a small, exactly counted number of kernel-selected intervals (0.17-0.70 % on Pulsar) were dropped when the correlation sequence could not be allocated under contention. Collector: the switch-in hook now retries the sequence compare-and-swap from the value the winning CPU left, up to 16 attempts, instead of dropping the interval after one lost race. Each lost attempt means another CPU made progress, so the loop is lock-free and bounded; zero stays the exhaustion sentinel and sequenceContentions still counts an interval that loses every attempt. On a 16-CPU host, 96 threads doing 20 us sleeps went from about 8 % contended drops (24k of 300k) to none. Correlator: when selectedIntervals - sequenceContentions equals the source rows and the received and written counts, and nothing else fails, the estimate is available with an accountedLoss object (intervals, fraction, reason "sequence-contention"), sourceCoverageComplete false, and the sum scaled by selected / received in the same exact fixed-point arithmetic; assumptions names the independence assumption. The stack profile's per-entry estimates take the same scale. --max-accounted-loss (default 0.01) refuses a larger loss with accounted-loss-above-limit. Any gap the counter does not explain keeps today's reasons. --max-accounted-loss is an option of the picocli correlate command: its default shows in the help, it is refused with --partial true, and a limit outside [0, 1) is a usage error (exit 64).
lhotari
force-pushed
the
population-estimate-accounted-loss
branch
from
September 23, 2026 20:43
9ffa73d to
6b33830
Compare
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.
--estimate-population truereported the estimateunavailableon every real capture. On each one,selectedIntervals - receivedObservationsequalledsequenceContentions: the kernel counted every interval it dropped because it couldn't allocate a correlation sequence, and the estimator rejected any contention at all.Collector (
jonoffcpu_cookie.bpf.c)allocate_sequencenow retries the compare-and-swap from the value the winning CPU left, up to 16 attempts. Before, it dropped the interval after one lost race. Each lost attempt means another CPU took a sequence, so the loop always makes progress and its cost is capped.epoch << 32 | sequence.sequenceContentionsstill counts an interval that loses all 16 attempts.Correlator
selected - sequenceContentions == rows == received == written, every other failure counter is zero, and nothing else is wrong. In that case the estimate isavailableand the report shows:accountedLoss {intervals, fraction, reason: "sequence-contention"}sourceCoverageComplete: falseassumptionsentry saying contention is independent of an interval's stack and durationselected / receivedin the same exact fixed-point arithmetic. The stack profile's per-entry estimates are scaled the same way, and itsestimateAvailableis now true when the estimate isavailable.--max-accounted-loss F, default0.01, allowed range 0 ≤ F < 1. A loss above it givesunavailablewithaccounted-loss-above-limit, andaccountedLossis still reported. The option is added in the current hand-parsed CLI style, kept small so the picocli migration can rebase over it.nonzero-sequenceContentions,selected-source-row-count-mismatch, …).--estimate-populationand--max-accounted-loss) and the native README.Verified
./gradlew spotlessCheck :jonoffcpu-agent:check :jonoffcpu-correlator:check -PnativeArchitectures=x86_64 -PnativeLibcs=glibcpasses. New OfflineCorrelatorTest cases cover:available,accountedLossand the 3/2 scaleestimateAvailableand the scaled profile total; a limit of 1 is rejectedcargo fmt --checkpasses. The collector builds in the pinned container (x86-64 only).Privileged kernel proofs run on Linux 7.1.5, 16 CPUs, x86-64. The verifier accepts the loop. These pass: sequence-boundary (exhaustion sentinel still ends at 0, 0 contentions), sched-exit, transport, offcpu-reason and collector-smoke.
The packaged agent smoke passes (x86-64 glibc, 1447 matched samples).
Contention stress: a throwaway variant of the sequence-boundary proof, not committed. It ran 96 threads doing 20 µs sleeps on 16 CPUs, with the sequence starting at 1.
sequenceContentionsE235 broker capture (acceptance 1):
status: available,accountedLoss.intervals = "713",fraction = 0.00169794,estimatedDurationNanos = 15378600234629,stackProfile.estimateAvailable = true. With--max-accounted-loss 0.001it isunavailablewithaccounted-loss-above-limit.Not verified
run-task-lifetime-proof.sh: not run successfully. Run on its own it exits with "runner must bind the outer PID namespace identity", because it needs therun-lifetime-gates.shsetup, which I did not run.