Skip to content

Commit f88afa5

Browse files
Gary-Hobsonxiaoxiang781216
authored andcommitted
sched/cpuload: fix SMP situation CPULOAD statistics are inaccurate
When statistics when sched_cpuload_critMonitor, thread switching only calculates the current CPU's running time. Other CPU running threads are updated for updates Signed-off-by: yinshengkai <[email protected]>
1 parent 38f0056 commit f88afa5

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

sched/sched/sched_critmonitor.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,59 @@ static void nxsched_critmon_cpuload(FAR struct tcb_s *tcb, clock_t current,
153153
}
154154
#endif
155155

156+
/****************************************************************************
157+
* Private Functions
158+
****************************************************************************/
159+
160+
/****************************************************************************
161+
* Name: nxsched_critmon_cpuload
162+
*
163+
* Description:
164+
* Update the running time of all running threads when switching threads
165+
*
166+
* Input Parameters:
167+
* tcb - The task that we are performing the load operations on.
168+
* current - The current time
169+
* tick - The ticks that we process in this cpuload.
170+
*
171+
* Returned Value:
172+
* None
173+
*
174+
****************************************************************************/
175+
176+
#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
177+
static void nxsched_critmon_cpuload(FAR struct tcb_s *tcb, clock_t current,
178+
clock_t tick)
179+
{
180+
int i;
181+
UNUSED(i);
182+
183+
/* Update the cpuload of the thread ready to be suspended */
184+
185+
nxsched_process_taskload_ticks(tcb, tick);
186+
187+
/* Update the cpuload of threads running on other CPUs */
188+
189+
# ifdef CONFIG_SMP
190+
for (i = 0; i < CONFIG_SMP_NCPUS; i++)
191+
{
192+
FAR struct tcb_s *rtcb = current_task(i);
193+
194+
if (tcb->cpu == rtcb->cpu)
195+
{
196+
continue;
197+
}
198+
199+
nxsched_process_taskload_ticks(rtcb, tick);
200+
201+
/* Update start time, avoid repeated statistics when the next call */
202+
203+
rtcb->run_start = current;
204+
}
205+
# endif
206+
}
207+
#endif
208+
156209
/****************************************************************************
157210
* Public Functions
158211
****************************************************************************/

0 commit comments

Comments
 (0)