sched/cpuload: use perf to implement cpuload without relying on external timers

Need to enable CONFIG_SCHED_CRITMONITOR

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-04-25 17:41:44 +08:00 committed by Xiang Xiao
parent e8bf910c3d
commit 996be8f2cf
3 changed files with 17 additions and 1 deletions

View File

@ -900,6 +900,7 @@ if SCHED_CPULOAD
choice
prompt "Select CPU load clock source"
default SCHED_CPULOAD_EXTCLK if SCHED_TICKLESS
default SCHED_CPULOAD_CRITMONITOR if SCHED_CRITMONITOR
config SCHED_CPULOAD_SYSCLK
bool "Use system clock"
@ -941,6 +942,15 @@ config SCHED_CPULOAD_EXTCLK
nxsched_process_cpuload_ticks() at each timer expiration with interrupts
disabled.
config SCHED_CPULOAD_CRITMONITOR
bool "Use critical monitor"
depends on SCHED_CRITMONITOR
---help---
Use the perfcounter in the core of the chip as a counter, no need to
use an external timer. Need to depend on SCHED_CRITMONITOR.
When the task is suspended, call nxsched_critmon_cpuload_ticks to count
the recent running time of the task
endchoice
if SCHED_CPULOAD_EXTCLK

View File

@ -397,7 +397,8 @@ int nxsched_pause_cpu(FAR struct tcb_s *tcb);
/* CPU load measurement support */
#ifdef CONFIG_SCHED_CPULOAD_SYSCLK
#if defined(CONFIG_SCHED_CPULOAD_SYSCLK) || \
defined (CONFIG_SCHED_CPULOAD_CRITMONITOR)
void nxsched_process_taskload_ticks(FAR struct tcb_s *tcb, uint32_t ticks);
void nxsched_process_cpuload_ticks(uint32_t ticks);
#define nxsched_process_cpuload() nxsched_process_cpuload_ticks(1)

View File

@ -297,6 +297,11 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb)
unsigned long current = up_perf_gettime();
unsigned long elapsed = current - tcb->run_start;
#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
unsigned long tick = elapsed * CLOCKS_PER_SEC / up_perf_getfreq();
nxsched_process_taskload_ticks(tcb, tick);
#endif
tcb->run_time += elapsed;
if (elapsed > tcb->run_max)
{