Skip to content

Commit aecacaa

Browse files
committed
sched/sched: Support wdog/scheduler hrtimer.
This commit supported wdog/scheduler hrtimer with tickless enabled. Signed-off-by: ouyangxiangzhen <[email protected]>
1 parent 722aa9b commit aecacaa

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

sched/sched/sched_processtimer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include "sched/sched.h"
4545
#include "wdog/wdog.h"
46+
#include "hrtimer/hrtimer.h"
4647
#include "clock/clock.h"
4748

4849
/****************************************************************************
@@ -176,6 +177,8 @@ static inline void nxsched_process_scheduler(void)
176177

177178
void nxsched_process_timer(void)
178179
{
180+
clock_t ticks;
181+
179182
#ifdef CONFIG_CLOCK_TIMEKEEPING
180183
/* Process wall time */
181184

@@ -194,7 +197,13 @@ void nxsched_process_timer(void)
194197

195198
/* Process watchdogs */
196199

197-
wd_timer(clock_systime_ticks());
200+
ticks = clock_systime_ticks();
201+
202+
#ifdef CONFIG_HRTIMER
203+
hrtimer_expiry_tick(ticks, false);
204+
#endif
205+
206+
wd_timer(ticks);
198207

199208
#ifdef CONFIG_SYSTEMTICK_HOOK
200209
/* Call out to a user-provided function in order to perform board-specific,

sched/sched/sched_timerexpiration.c

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "sched/sched.h"
4141
#include "wdog/wdog.h"
42+
#include "hrtimer/hrtimer.h"
4243
#include "clock/clock.h"
4344

4445
#ifdef CONFIG_CLOCK_TIMEKEEPING
@@ -80,7 +81,8 @@ static clock_t nxsched_process_scheduler(clock_t ticks, clock_t elapsed,
8081
bool noswitches);
8182
static clock_t nxsched_timer_process(clock_t ticks, clock_t elapsed,
8283
bool noswitches);
83-
static clock_t nxsched_timer_start(clock_t ticks, clock_t interval);
84+
static inline_function
85+
clock_t nxsched_timer_update(clock_t ticks, bool noswitches);
8486

8587
/****************************************************************************
8688
* Private Data
@@ -104,6 +106,10 @@ static atomic_t g_timer_interval;
104106
static unsigned int g_timernested;
105107
#endif
106108

109+
#ifdef CONFIG_HRTIMER
110+
static hrtimer_t g_hrtimer_sched;
111+
#endif
112+
107113
/****************************************************************************
108114
* Private Functions
109115
****************************************************************************/
@@ -164,7 +170,51 @@ int up_timer_gettick(FAR clock_t *ticks)
164170
}
165171
#endif
166172

167-
#ifdef CONFIG_SCHED_TICKLESS_ALARM
173+
#ifdef CONFIG_HRTIMER
174+
static uint64_t nxsched_hrtimer_expiration(void *args, uint64_t expired)
175+
{
176+
uint64_t next_delay = 0u;
177+
clock_t ticks = div_const(expired, NSEC_PER_TICK);
178+
irqstate_t flags;
179+
clock_t interval;
180+
181+
/* Process the wdog and scheduler. */
182+
183+
flags = enter_critical_section();
184+
g_timernested++;
185+
186+
interval = nxsched_timer_update(ticks, false);
187+
188+
g_timernested--;
189+
leave_critical_section(flags);
190+
191+
/* Calculate the next delay. */
192+
193+
if (interval != CLOCK_MAX)
194+
{
195+
interval = adjust_next_interval(interval);
196+
next_delay = interval == 0u ? 1u : interval * NSEC_PER_TICK;
197+
}
198+
199+
return next_delay;
200+
}
201+
202+
static inline_function
203+
int nxsched_timer_tick_start(clock_t ticks, clock_t delay)
204+
{
205+
return hrtimer_restart_absolute(&g_hrtimer_sched,
206+
nxsched_hrtimer_expiration, NULL,
207+
(ticks + delay) * NSEC_PER_TICK);
208+
}
209+
210+
static inline_function
211+
int nxsched_timer_tick_cancel(clock_t *ticks)
212+
{
213+
hrtimer_cancel(&g_hrtimer_sched);
214+
return up_timer_gettick(ticks);
215+
}
216+
217+
#elif defined(CONFIG_SCHED_TICKLESS_ALARM)
168218
static inline_function
169219
int nxsched_timer_tick_start(clock_t ticks, clock_t delay)
170220
{
@@ -474,6 +524,7 @@ clock_t nxsched_timer_update(clock_t ticks, bool noswitches)
474524
*
475525
****************************************************************************/
476526

527+
#ifndef CONFIG_HRTIMER
477528
void nxsched_timer_expiration(void)
478529
{
479530
irqstate_t flags;
@@ -495,6 +546,12 @@ void nxsched_timer_expiration(void)
495546

496547
leave_critical_section(flags);
497548
}
549+
#else
550+
void nxsched_timer_expiration(void)
551+
{
552+
hrtimer_expiry(clock_systime_nsec(), false);
553+
}
554+
#endif
498555

499556
/****************************************************************************
500557
* Name: nxsched_reassess_timer

0 commit comments

Comments
 (0)