From e8bf910c3d3e06cce52c641d4d5cd093e9f70ddb Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Wed, 26 Apr 2023 21:43:22 +0800 Subject: [PATCH] sched: rename nxsched_cpu_process_cpuload put nxsched_process_cpuload_ticks partial implementation into nxsched_task_process_cpuload Signed-off-by: yinshengkai --- sched/sched/sched.h | 1 + sched/sched/sched_cpuload.c | 90 +++++++++++++++---------------------- 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 36525fef18..3b423275fc 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -398,6 +398,7 @@ int nxsched_pause_cpu(FAR struct tcb_s *tcb); /* CPU load measurement support */ #ifdef CONFIG_SCHED_CPULOAD_SYSCLK +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) #endif diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index 2ae78238af..f5128e36c8 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -62,7 +62,7 @@ CPULOAD_TICKSPERSEC) /**************************************************************************** - * Private Data + * Public Data ****************************************************************************/ /* This is the total number of clock tick counts. Essentially the @@ -81,46 +81,58 @@ volatile uint32_t g_cpuload_total; /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: nxsched_cpu_process_cpuload + * Name: nxsched_process_taskload_ticks * * Description: - * Collect data that can be used for CPU load measurements. + * Collect data that can be used for task load measurements. * * Input Parameters: - * cpu - The CPU that we are performing the load operations on. + * tcb - The task that we are performing the load operations on. * ticks - The ticks that we process in this cpuload. * * Returned Value: * None * - * Assumptions/Limitations: - * This function is called from a timer interrupt handler with all - * interrupts disabled. - * ****************************************************************************/ -static inline void nxsched_cpu_process_cpuload(int cpu, uint32_t ticks) +void nxsched_process_taskload_ticks(FAR struct tcb_s *tcb, uint32_t ticks) { - FAR struct tcb_s *rtcb = current_task(cpu); + irqstate_t flags; - /* Increment the count on the currently executing thread */ - - rtcb->ticks += ticks; - - /* Increment tick count. NOTE that the count is increment once for each - * CPU on each sample interval. - */ + flags = enter_critical_section(); + tcb->ticks += ticks; g_cpuload_total += ticks; -} -/**************************************************************************** - * Public Functions - ****************************************************************************/ + if (g_cpuload_total > CPULOAD_TIMECONSTANT) + { + uint32_t total = 0; + int i; + + /* Divide the tick count for every task by two and recalculate the + * total. + */ + + for (i = 0; i < g_npidhash; i++) + { + if (g_pidhash[i]) + { + g_pidhash[i]->ticks >>= 1; + total += g_pidhash[i]->ticks; + } + } + + /* Save the new total. */ + + g_cpuload_total = total; + } + + leave_critical_section(flags); +} /**************************************************************************** * Name: nxsched_process_cpuload_ticks @@ -146,44 +158,14 @@ static inline void nxsched_cpu_process_cpuload(int cpu, uint32_t ticks) void nxsched_process_cpuload_ticks(uint32_t ticks) { int i; - irqstate_t flags; /* Perform scheduler operations on all CPUs. */ - flags = enter_critical_section(); - for (i = 0; i < CONFIG_SMP_NCPUS; i++) { - nxsched_cpu_process_cpuload(i, ticks); + FAR struct tcb_s *rtcb = current_task(i); + nxsched_process_taskload_ticks(rtcb, ticks); } - - /* If the accumulated tick value exceed a time constant, then shift the - * accumulators and recalculate the total. - */ - - if (g_cpuload_total > CPULOAD_TIMECONSTANT) - { - uint32_t total = 0; - - /* Divide the tick count for every task by two and recalculate the - * total. - */ - - for (i = 0; i < g_npidhash; i++) - { - if (g_pidhash[i]) - { - g_pidhash[i]->ticks >>= 1; - total += g_pidhash[i]->ticks; - } - } - - /* Save the new total. */ - - g_cpuload_total = total; - } - - leave_critical_section(flags); } /****************************************************************************