diff --git a/sched/Kconfig b/sched/Kconfig index f309a11673b..0b1b25184b4 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -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 diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 3b423275fc8..0b2dc5f8f67 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -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) diff --git a/sched/sched/sched_critmonitor.c b/sched/sched/sched_critmonitor.c index c4560fd0dad..f296d759136 100644 --- a/sched/sched/sched_critmonitor.c +++ b/sched/sched/sched_critmonitor.c @@ -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) {