arch/sim: add simulated time ratio support#18801
Merged
xiaoxiang781216 merged 2 commits intoapache:masterfrom Apr 25, 2026
Merged
arch/sim: add simulated time ratio support#18801xiaoxiang781216 merged 2 commits intoapache:masterfrom
xiaoxiang781216 merged 2 commits intoapache:masterfrom
Conversation
fe1ac86 to
d087837
Compare
Add CONFIG_SIM_WALLTIME_RATIO Kconfig option and --sim-rt-ratio= command-line argument to control the ratio of simulated time to real time in percent. 100 means real-time (default), 200 means simulated time advances twice as fast, 50 means half speed. The implementation applies the ratio in host_gettime(), host_sleepuntil() and host_settimer() so both SIM_WALLTIME_SLEEP and SIM_WALLTIME_SIGNAL modes are supported. This is inspired by the --rt-ratio feature in Zephyr's native_sim board. Tested on sim:nsh with the following sleep test: $ echo -e "sleep 2\nexit" | time ./nuttx real 0m2.0xxs $ echo -e "sleep 2\nexit" | time ./nuttx --sim-rt-ratio=200 real 0m1.0xxs $ echo -e "sleep 2\nexit" | time ./nuttx --sim-rt-ratio=50 real 0m4.0xxs Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
d087837 to
0da9c1e
Compare
dispatch_walltime() expects a delta in nanoseconds from now, but the previous code subtracted CLOCK_REALTIME from a CLOCK_MONOTONIC absolute timestamp, which have different epochs and produce a meaningless result. Fix by subtracting the current CLOCK_MONOTONIC absolute time to get the correct remaining duration. Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
0da9c1e to
228ee23
Compare
anchao
approved these changes
Apr 25, 2026
xiaoxiang781216
approved these changes
Apr 25, 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.
Add CONFIG_SIM_WALLTIME_RATIO Kconfig option and --sim-rt-ratio=
command-line argument to control the ratio of simulated time to
real time in percent. 100 means real-time (default), 200 means
simulated time advances twice as fast, 50 means half speed.
The implementation applies the ratio in host_gettime(), host_sleepuntil() and host_settimer() so both SIM_WALLTIME_SLEEP and SIM_WALLTIME_SIGNAL modes are supported.
Tested on sim:nsh with the following sleep test: