nuttx/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
..
addrenv sched/addrenv: replace critical section with spinlock for refs protection 2026-01-20 11:29:22 +08:00
clock sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks 2026-03-03 11:01:02 -05:00
environ libc/environ: add interrupt context check to getenv 2026-01-21 10:37:55 +08:00
event sched/event: Fix uninitialized need_switch flag issue in event_post() 2025-11-04 21:43:59 +08:00
group sched: move process ID from kernel to TLS for faster access 2026-01-20 22:33:45 +08:00
hrtimer sched/hrtimer: Simplify the hrtimer. 2026-02-02 13:26:22 +08:00
init sched: add trace points during system startup and board initialization 2026-01-27 03:18:11 +08:00
instrument gprof: move gprof function from sched to libbuiltin/libgcc 2024-11-13 02:42:31 +08:00
irq sched/irq: Consolidate IRQ bounds checking into IRQ_TO_NDX macro 2026-01-28 13:35:30 +08:00
misc sched/misc: fix potential out-of-bounds access in coredump stack emission 2026-02-27 17:52:34 +08:00
module libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
mqueue sched/mqueue: Enable receiving messages on an interrupt handler 2026-02-11 13:10:31 -05:00
paging sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
pthread pthread: move pthread_cond to userspace 2026-01-26 16:26:39 +08:00
sched sched/critmon: Fix CPU load stats incorrect when using SCHED_CPULOAD_CRITMONITOR 2026-03-03 11:54:20 -05:00
semaphore sched/semaphore: Add debug assert to detect mutex recursion. 2026-02-03 11:56:24 -05:00
signal sched/signal: update nxsig_clockwait() to support disable all signals 2026-02-26 20:03:05 +08:00
task sched/cancelpt: Fix MISRA C 2012 Rule 10.4 violations 2026-02-02 21:09:40 +08:00
timer sched/timer: Fix MISRA Rule 10.3 2026-01-22 22:14:00 +08:00
tls pthread: remove tl_lock 2026-01-26 20:56:12 +08:00
wdog sched/wdog: Simplify timer expiration for hrtimer. 2026-02-02 13:26:22 +08:00
wqueue sched/wqueue: add configuring the stack of an hpwork/lpwork as static 2026-01-27 10:18:24 +08:00
CMakeLists.txt sched: migrate to SPDX identifier 2024-09-12 01:10:14 +08:00
Kconfig sched: Fix Kconfig style 2026-02-03 09:36:16 +08:00
Makefile Makefile: Remove make depend files by make distclean 2026-02-16 16:27:57 +01:00