nuttx/sched/sched
chao an d5b02b6954 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:
+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 #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>
2026-03-03 11:54:20 -05:00
..
CMakeLists.txt sched/wdog: Simplify timer expiration for hrtimer. 2026-02-02 13:26:22 +08:00
Make.defs sched/wdog: Simplify timer expiration for hrtimer. 2026-02-02 13:26:22 +08:00
nxsched_checkstackoverflow.c sched: Improve nxsched stack overflow checking implementation 2025-10-11 18:00:44 +08:00
queue.h sched/queue: fix typo in dq_insert_mid macro 2025-05-08 15:59:50 +08:00
sched.h sched/sched: fix typos and remove unused declarations in sched.h 2026-02-25 12:38:13 -05:00
sched_addblocked.c
sched_addreadytorun.c sched: Fix scheduler CPU selection and ready-to-run list management 2026-01-28 13:02:58 -03:00
sched_backtrace.c sched/backtrace: There is a bug in sched_backtrace(). 2026-01-22 22:11:17 +08:00
sched_cpuload.c sched_cpuload.c: misra_c_2012_rule_8_9_violation 2026-01-30 12:52:22 -03:00
sched_cpuload_oneshot.c timers/oneshot: Remove all callback and args. 2025-11-18 13:02:29 +01:00
sched_cpuload_period.c
sched_critmonitor.c sched/critmon: Fix CPU load stats incorrect when using SCHED_CPULOAD_CRITMONITOR 2026-03-03 11:54:20 -05:00
sched_dumponexit.c sched: add dump_stack() for dumponexit 2026-01-17 18:04:28 -03:00
sched_foreach.c
sched_get_stackinfo.c sched/sched/sched_get_stackinfo.c: coverity HIS_metric_violation: RETURN 2026-01-28 01:24:58 +08:00
sched_get_stateinfo.c sched_get_stateinfo.c: misra_c_2012_rule_8_9_violation 2026-01-31 02:39:19 +08:00
sched_get_tls.c sched/tls: fix uninitialized argv pointer in task info 2026-01-15 16:10:11 -03:00
sched_getaffinity.c
sched_getcpu.c
sched_getfiles.c sched_getfiles.c: coverity HIS_metric_violation: RETURN 2026-01-28 22:01:01 +08:00
sched_getparam.c sched_getparam.c: coverity HIS_metric_violation: RETURN 2026-02-02 14:54:58 +08:00
sched_getscheduler.c sched_getscheduler.c: coverity HIS_metric_violation: RETURN 2026-01-28 13:07:20 -03:00
sched_gettcb.c
sched_idletask.c Revert "sched_idletask: remove the check for whether tcb is NULL" 2025-11-27 08:26:53 -03:00
sched_lock.c sched/sched: Modify the critical section interface name. 2026-01-26 21:13:05 +08:00
sched_lockcount.c
sched_mergepending.c coverity: Dereferencing after a null check (FORWARD_NULL) 2026-01-27 22:29:17 +08:00
sched_process_delivered.c sched: Fix scheduler CPU selection and ready-to-run list management 2026-01-28 13:02:58 -03:00
sched_processtick.c sched/wdog: Simplify timer expiration for hrtimer. 2026-02-02 13:26:22 +08:00
sched_processtickless.c sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks 2026-03-03 11:01:02 -05:00
sched_profil.c sched_profil.c: coverity HIS_metric_violation: RETURN 2026-02-02 22:18:16 +08:00
sched_releasetcb.c pthread: remove tl_lock 2026-01-26 20:56:12 +08:00
sched_removeblocked.c
sched_removereadytorun.c sched: Fix scheduler CPU selection and ready-to-run list management 2026-01-28 13:02:58 -03:00
sched_reprioritize.c
sched_reprioritizertr.c
sched_roundrobin.c sched/sched_roundrobin.c: fix round-robin scheduling in SMP mode 2026-01-17 18:03:45 -03:00
sched_rrgetinterval.c sched/sched/sched_rrgetinterval.c: coverity HIS_metric_violation: RETURN 2026-01-27 22:28:59 +08:00
sched_self.c
sched_setaffinity.c sched/sched: change [FIRST|LAST]_ASSIGNED_STATE to [FIRST|LAST]_READY_TO_RUN_STATE in nxsched_set_affinity 2024-11-04 17:19:59 +08:00
sched_setparam.c sched_setparam.c: coverity HIS_metric_violation: RETURN 2026-02-03 10:20:24 +08:00
sched_setpriority.c sched_setpriority.c: coverity HIS_metric_violation: RETURN 2026-01-31 02:38:55 +08:00
sched_setscheduler.c sched_setscheduler.c: coverity HIS_metric_violation: RETURN 2026-02-03 19:22:38 +08:00
sched_sleep.c sched/sched: add nxsched_abstick_sleep() 2026-02-26 17:04:47 +08:00
sched_smp.c smpcall: we directly call the function to handle local smpcall 2024-11-07 09:25:11 +09:00
sched_sporadic.c sched/sched: Change the return value semantics. 2025-12-22 21:17:13 +08:00
sched_suspend.c sched/signal: fix the occasional issue where SIGCONT was not executed 2026-01-22 03:58:12 +08:00
sched_switchcontext.c sched: Improve nxsched stack overflow checking implementation 2025-10-11 18:00:44 +08:00
sched_sysinfo.c sched_sysinfo.c: coverity HIS_metric_violation: RETURN 2026-01-31 02:53:58 +08:00
sched_unlock.c sched/sched: Modify the critical section interface name. 2026-01-26 21:13:05 +08:00
sched_verifytcb.c
sched_wait.c
sched_waitid.c sched_waitid.c: HIS_metric_violation: CCM 2026-01-31 13:11:34 -03:00
sched_waitpid.c sched_waitpid.c: HIS_metric_violation: CCM 2026-02-04 03:04:44 +08:00
sched_yield.c