sched/critmonitor: Fix context switch state tracking - #20066
Open
yushuailong wants to merge 4 commits into
Open
Conversation
Add the blank lines required between local declarations and statements so sched_critmonitor.c passes nxstyle. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
The premp_start member was renamed to preemp_start, but the old name was reintroduced when the critical monitor switch paths were merged. Use the current struct tcb_s field name so configurations with preemption monitoring enabled build successfully. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
The struct tcb_s premp_* members were renamed to preemp_*, but the GDB TCB protocol retained the old annotations. Update the annotations to match the current structure field names. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
The context-switch merge assigned the current timestamp to run_time instead of run_start. This overwrote the accumulated runtime and left the next elapsed-time calculation with a stale start value when critical-monitor CPU load accounting was disabled. Store the timestamp in run_start under the thread runtime monitor configuration, matching the former resume path. Fixes: b2a69ba ("sched: merge nxsched_suspend/resume_critmon") Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
yushuailong
requested review from
GUIDINGLI and
xiaoxiang781216
as code owners
September 6, 2026 16:03
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
Commit b2a69ba merged the critical monitor suspend and resume paths into
nxsched_switch_critmon(), but introduced two state tracking problems:premp_startfield name. The field was previously renamed topreemp_start, causing configurations with preemption monitoring enabled to fail to build.to->run_timeinstead ofto->run_start. This overwrote the accumulated runtime and left a stale start timestamp for the next context-switch calculation whenCONFIG_SCHED_CPULOAD_CRITMONITORwas disabled.This PR corrects the preemption field reference, restores the target thread's
run_starttimestamp, and updates the GDB TCB protocol annotations to match the currentstruct tcb_sfields.Impact
Bug fix only; no new features.
Testing
Host: macOS 25.6 (arm64), Apple clang version 21.0.0
Target: sim:ostest
Build: clean, no warnings/errors introduced by this change.
ostest run (5 loops, CONFIG_TESTING_OSTEST_LOOPS=5, auto poweroff):
Full log: 52364 lines, no FAILED / ASSERT / PANIC; final heap statistics
match the baseline (no leaks introduced).