testing/sched: fix invalid timerjitter results - #3675
Open
Zepp-Hanzj wants to merge 1 commit into
Open
Conversation
Signed-off-by: hanzhijian <hanzhijian@zepp.com>
xiaoxiang781216
approved these changes
Jul 29, 2026
jerpelea
approved these changes
Jul 29, 2026
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
USEC_PER_TICKon lower-resolution systemsFixes #3634
Root cause
The default interval was changed from 1000 us to
1000 * USEC_PER_TICK. With a 10 ms system tick this becomes 10 seconds, soUSEC_PER_SEC / DEFAULT_INTERVALevaluates to zero. The test then reports an uninitialized minimum and divides the accumulated latency by zero.A requested interval below
USEC_PER_TICKcannot be represented by the tick-based POSIX timer. The timer expires at tick resolution while timerjitter advances its expected timestamp by the smaller requested interval. This produces many missed frames. Printing every missed frame from the catch-up loop adds serial I/O latency and can create still more missed frames.The measured difference is an
int64_t, but the minimum and maximum fields wereunsigned long. Assigning a negative difference to these fields wrapped it to a large positive value.Hardware validation
The change was validated on real hardware with the following environment:
stm32f407zg-p1arm-none-eabi-gcc 9.2.1 20191025CONFIG_USEC_PER_TICK=10000CONFIG_TESTING_TIMERJITTER=yCONFIG_LIBC_FLOATINGPOINT=yBefore
The captured log reached 27 consecutive missed-frame messages:
After
The 10000 us values are the expected tick-resolution behavior of this configuration; this change fixes invalid statistics and runaway reporting, not the target timer resolution.
Additional checks
nxstyle testing/sched/timerjitter/timerjitter.c-Wall -Wextra -Werror