Files
zephyr/kernel
Nicolas Pitre b5363d5fff kernel: usage: Fix CPU stats retrieval in z_sched_cpu_usage()
The z_sched_cpu_usage() function was incorrectly using _current_cpu
instead of the requested cpu_id parameter when retrieving CPU usage
statistics. This caused it to always return stats from the current CPU
rather than the specified CPU.

This bug manifested in SMP systems when k_thread_runtime_stats_all_get()
looped through all CPUs - it would get stats from the wrong CPU for
each iteration, leading to inconsistent time values. For example, in
the times() POSIX function, this caused time to appear to move backwards:

  t0: utime: 59908
  t1: utime: 824

The fix ensures that:
1. cpu pointer is set to &_kernel.cpus[cpu_id] (the requested CPU)
2. The check for "is this the current CPU" is correctly written as
   (cpu == _current_cpu)

This fixes the portability.posix.muti_process.newlib test failure
on FVP SMP platforms where times() was reporting backwards time.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-10-22 09:04:13 +02:00
..
2025-09-08 15:51:07 -04:00
2024-09-20 09:02:38 +02:00
2025-01-10 07:49:08 +01:00
2025-01-10 07:49:08 +01:00
2025-08-25 09:12:31 +02:00
2025-01-17 19:43:44 +01:00
2025-01-10 07:49:08 +01:00
2025-01-10 07:49:08 +01:00
2025-04-21 07:45:35 +02:00
2025-09-05 17:13:05 +02:00
2025-02-03 19:51:20 +01:00
2025-01-10 07:49:08 +01:00
2025-09-05 17:13:05 +02:00