[bvar] fix sampler interval after switch to cpuwide_time_ns#3278
Merged
chenBright merged 1 commit intoapache:masterfrom Apr 23, 2026
Merged
[bvar] fix sampler interval after switch to cpuwide_time_ns#3278chenBright merged 1 commit intoapache:masterfrom
chenBright merged 1 commit intoapache:masterfrom
Conversation
Contributor
Author
|
Hi @chenBright, when you have a moment, would you mind taking a look at this PR? It tweaks |
Contributor
|
I made a mistake before. Please use |
Contributor
Author
ok, doing |
Commit 12fb539 ("Use monotonic time instead of wall time", apache#3268) switched the three time-source calls in SamplerCollector::run() from gettimeofday_us() to cpuwide_time_ns(), but the surrounding code still treats the timestamps as microseconds: - abstime += 1000000L now represents 1 ms (not 1 s), causing the sampler to spin at ~1 kHz instead of 1 Hz; - usleep(abstime - now) receives a nanosecond delta, which usleep() interprets as microseconds. Use cpuwide_time_us() instead, which preserves the monotonic behavior from apache#3268 while keeping the existing microsecond-based arithmetic correct. Fixes apache#3277.
9e6fdd0 to
95ca976
Compare
Contributor
|
cc @ivanallen |
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.
What problem does this PR solve?
Fixes the unit-mismatch regression introduced by #3268 (commit 12fb539, "Use monotonic time instead of wall time").
Before this PR, on master / 1.17.0-rc1, the bvar sampler thread effectively runs at ~1 kHz instead of 1 Hz and spams
PR #3268 switched the three time-source calls in
SamplerCollector::run()fromgettimeofday_us()(microseconds) tocpuwide_time_ns()(nanoseconds), but left the 1-second offset constant (abstime += 1000000L) and theusleep(abstime - now)call untouched. As a result:abstime += 1000000Lnow adds 1 ms instead of 1 s, so the sampler spins at ~1 kHz instead of 1 Hz;usleep(abstime - now)is passed a nanosecond delta thatusleep()interprets as microseconds, which further distorts the sleep duration.See #3277 for the full analysis and a reproducer.
What is changed and how does it work?
src/bvar/detail/sampler.cpp::SamplerCollector::run():abstime += 1000000L(1 ms in nanoseconds) →abstime += 1000000000L(1 s in nanoseconds), restoring the intended 1-second sample period.::usleep(abstime - now)—usleep()takes microseconds, but the difference is now in nanoseconds; divide by 1000.Checklist
SamplerCollector::run()loop is not currently covered by a direct unit test. Happy to add one if reviewers can suggest a good shape (the challenge is driving the loop deterministically without sleeping wall-clock time).Fixes #3277.