Skip to content

Commit 5be9f96

Browse files
committed
Reduce tickless interrupt latency
Add the function osKernelCanSleep which indicates if it is safe to call sleep (while the kernel is suspended). This patch also replaces the svcRtx* calls with os* calls since they no longer need to be called from a critical section.
1 parent 48a0489 commit 5be9f96

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

rtos/TARGET_CORTEX/mbed_rtx_idle.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,28 @@ static void default_idle_hook(void)
177177
{
178178
uint32_t elapsed_ticks = 0;
179179

180-
core_util_critical_section_enter();
181-
uint32_t ticks_to_sleep = svcRtxKernelSuspend();
182-
MBED_ASSERT(os_timer->get_tick() == svcRtxKernelGetTickCount());
180+
181+
uint32_t ticks_to_sleep = osKernelSuspend();
182+
MBED_ASSERT(os_timer->get_tick() == osKernelGetTickCount());
183183
if (ticks_to_sleep) {
184+
184185
os_timer->schedule_tick(ticks_to_sleep);
185186

187+
core_util_critical_section_enter();
186188
sleep_manager_lock_deep_sleep();
187-
sleep();
189+
if (osKernelCanSleep()) {
190+
sleep();
191+
}
188192
sleep_manager_unlock_deep_sleep();
193+
core_util_critical_section_exit();
189194

190195
os_timer->cancel_tick();
191196
// calculate how long we slept
192197
elapsed_ticks = os_timer->update_tick();
198+
193199
}
194-
svcRtxKernelResume(elapsed_ticks);
195-
core_util_critical_section_exit();
200+
osKernelResume(elapsed_ticks);
201+
196202
}
197203

198204
#else

rtos/TARGET_CORTEX/rtx5/cmsis_os2.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ uint32_t osKernelGetSysTimerCount (void);
350350
/// Get the RTOS kernel system timer frequency.
351351
/// \return frequency of the system timer.
352352
uint32_t osKernelGetSysTimerFreq (void);
353-
353+
354+
/// Check if it is safe to sleep.
355+
/// \return osOK if it is safe to sleep, otherwise osErrorTimeout.
356+
osStatus_t osKernelCanSleep (void);
357+
354358

355359
// ==== Thread Management Functions ====
356360

rtos/TARGET_CORTEX/rtx5/rtx_kernel.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,13 @@ uint32_t osKernelGetSysTimerFreq (void) {
641641
return __svcKernelGetSysTimerFreq();
642642
}
643643
}
644+
645+
/// Check if it is safe to sleep.
646+
osStatus_t osKernelCanSleep (void) {
647+
if (osRtxInfo.kernel.pendSV) {
648+
return osErrorTimeout;
649+
} else {
650+
return osOK;
651+
}
652+
}
653+

0 commit comments

Comments
 (0)