sched/critmon: Fix CPU load stats incorrect when using SCHED_CPULOAD_CRITMONITOR#18485
Merged
linguini1 merged 1 commit intoapache:masterfrom Mar 3, 2026
Merged
sched/critmon: Fix CPU load stats incorrect when using SCHED_CPULOAD_CRITMONITOR#18485linguini1 merged 1 commit intoapache:masterfrom
linguini1 merged 1 commit intoapache:masterfrom
Conversation
…CRITMONITOR
Fix the abnormal CPU usage statistics issue caused by missing update
of run_start timestamp in the target task (to) TCB when the CPU load
counting mode is SCHED_CPULOAD_CRITMONITOR.
Before this fix, the to->run_start was not set when switching context,
leading to incorrect CPU usage calculation (e.g., Idle_Task showed 52.9%
CPU usage instead of 100%, and running tasks had wrong non-zero values).
After fixing, the CPU statistics return to normal: Idle_Task correctly
shows 100% usage, and non-running tasks show 0% as expected.
Enable:
+CONFIG_SCHED_CPULOAD_CRITMONITOR=y
+CONFIG_SCHED_CRITMONITOR=y
Before:
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK CPU COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0069584 52.9% Idle_Task
1 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067456 0.0% sim_loop_wq 0x7b4417a003f0 0x7b4417a00470
2 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067464 17.6% hpwork 0x4014dba0 0x4014dc20
3 3 0 100 FIFO Task - Running 0000000000000000 0067496 36.8% nsh_main
After:
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK CPU COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0069584 100.0% Idle_Task
1 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067456 0.0% sim_loop_wq 0x7646932003f0 0x764693200470
2 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067464 0.0% hpwork 0x4014dba0 0x4014dc20
3 3 0 100 FIFO Task - Running 0000000000000000 0067496 0.0% nsh_main
This issue was introduced by PR apache#17075, where the run_start update for the
target task was omitted in the SCHED_CPULOAD_CRITMONITOR branch.
Signed-off-by: chao an <anchao.archer@bytedance.com>
xiaoxiang781216
approved these changes
Mar 3, 2026
linguini1
approved these changes
Mar 3, 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
sched/critmon: Fix CPU load stats incorrect when using SCHED_CPULOAD_CRITMONITOR
Fix the abnormal CPU usage statistics issue caused by missing update
of run_start timestamp in the target task (to) TCB when the CPU load
counting mode is SCHED_CPULOAD_CRITMONITOR.
Before this fix, the to->run_start was not set when switching context,
leading to incorrect CPU usage calculation (e.g., Idle_Task showed 52.9%
CPU usage instead of 100%, and running tasks had wrong non-zero values).
After fixing, the CPU statistics return to normal: Idle_Task correctly
shows 100% usage, and non-running tasks show 0% as expected.
Enable:
Before:
After:
This issue was introduced by PR #17075, where the run_start update for the
target task was omitted in the SCHED_CPULOAD_CRITMONITOR branch.
Signed-off-by: chao an anchao.archer@bytedance.com
Impact
N/A
Testing
sim/nsh,
Enable:
Before:
After: