Repository navigation
testing/sched: fix off-by-one sample count in timerjitter - #3629
Merged
Merged
Conversation
cur_cnt++ in the loop condition increments even when the loop body doesn't run, so avg is divided by one more sample than was collected. Signed-off-by: liang.huang <liang.huang@houmo.ai>
acassis
approved these changes
Jul 11, 2026
linguini1
approved these changes
Jul 11, 2026
linguini1
left a comment
Contributor
There was a problem hiding this comment.
Could you raise issues for the other problems you spotted? If you don't want to submit patches for them then at least we have a record :)
1 task done
Contributor
Author
|
@linguini1 Done — filed BUG#3634 keep a record of the other issues I spotted while testing. Didn't include fixes for now since I'm not fully sure what the expected behavior should be in each case, but wanted to make sure they're tracked. |
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.
Summary
timerjitter()usescur_cnt++ < max_cntas the loop condition. Thepost-increment fires even on the final check that exits the loop, so
cur_cntends up one greater than the number of samples actuallycollected, and
avg = avg / cur_cntdivides by a count that's toolarge by one. Fix by incrementing
cur_cntinside the loop bodyinstead.
Impact
Only affects
apps/testing/sched/timerjitter's reportedavgvalue.No API/Kconfig/doc changes.
Testing
QEMU RISC-V (
rv-virt:knsh_romfs),CONFIG_TESTING_TIMERJITTER=y,CONFIG_USEC_PER_TICK=1000.Before:
After:
Note: this app has other pre-existing issues beyond this one, e.g.
with
CONFIG_USEC_PER_TICK=10000:and with certain argument combinations:
There are likely more such issues (a Claude-assisted scan surfaces
several). This PR intentionally only fixes the off-by-one above since
it affects basic correctness. The rest are left alone — I'm not
familiar enough with NuttX apps' design conventions to know whether
they're intentional simplicity trade-offs, so I'd rather not guess at
fixes for them here.