mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
sched/sched: Replace nxsched_alarm_tick_expiration()
Introduce a new function nxsched_tick_expiration() to replace
nxsched_alarm_tick_expiration(). The new function provides a
common implementation that can be shared by both the alarm
and timer architectures.
This change reduces code duplication and provides a unified
function that can be directly reused.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
This commit is contained in:
committed by
Xiang Xiao
parent
590ea0567d
commit
519ffe66d0
@@ -51,7 +51,7 @@ static void oneshot_callback(FAR struct oneshot_lowerhalf_s *lower,
|
||||
|
||||
ONESHOT_TICK_CURRENT(g_oneshot_lower, &now);
|
||||
#ifdef CONFIG_SCHED_TICKLESS
|
||||
nxsched_alarm_tick_expiration(now);
|
||||
nxsched_tick_expiration(now);
|
||||
#else
|
||||
/* Start the next tick first, in order to minimize latency. Ideally
|
||||
* the ONESHOT_TICK_START would also return the current tick so that
|
||||
|
||||
@@ -2488,8 +2488,8 @@ void nxsched_timer_expiration(void);
|
||||
|
||||
#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
|
||||
void nxsched_alarm_expiration(FAR const struct timespec *ts);
|
||||
void nxsched_alarm_tick_expiration(clock_t ticks);
|
||||
#endif
|
||||
void nxsched_tick_expiration(clock_t ticks);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxsched_get_next_expired
|
||||
|
||||
@@ -470,15 +470,20 @@ static clock_t nxsched_timer_start(clock_t ticks, clock_t interval)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SCHED_TICKLESS_ALARM
|
||||
void nxsched_alarm_tick_expiration(clock_t ticks)
|
||||
void nxsched_tick_expiration(clock_t ticks)
|
||||
{
|
||||
clock_t elapsed;
|
||||
clock_t nexttime;
|
||||
clock_t previous;
|
||||
|
||||
/* Save the time that the alarm occurred */
|
||||
previous = update_time_tick(ticks);
|
||||
|
||||
elapsed = ticks - update_time_tick(ticks);
|
||||
#ifdef CONFIG_SCHED_TICKLESS_ALARM
|
||||
elapsed = ticks - previous;
|
||||
#else
|
||||
UNUSED(previous);
|
||||
elapsed = atomic_read(&g_timer_interval);
|
||||
#endif
|
||||
|
||||
clock_increase_sched_ticks(elapsed);
|
||||
|
||||
@@ -490,6 +495,7 @@ void nxsched_alarm_tick_expiration(clock_t ticks)
|
||||
atomic_set(&g_timer_interval, elapsed);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SCHED_TICKLESS_ALARM
|
||||
void nxsched_alarm_expiration(FAR const struct timespec *ts)
|
||||
{
|
||||
clock_t ticks;
|
||||
@@ -497,7 +503,7 @@ void nxsched_alarm_expiration(FAR const struct timespec *ts)
|
||||
DEBUGASSERT(ts);
|
||||
|
||||
ticks = clock_time2ticks_floor(ts);
|
||||
nxsched_alarm_tick_expiration(ticks);
|
||||
nxsched_tick_expiration(ticks);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -521,23 +527,12 @@ void nxsched_alarm_expiration(FAR const struct timespec *ts)
|
||||
void nxsched_timer_expiration(void)
|
||||
{
|
||||
clock_t ticks;
|
||||
clock_t elapsed;
|
||||
clock_t nexttime;
|
||||
|
||||
/* Get the interval associated with last expiration */
|
||||
|
||||
up_timer_gettick(&ticks);
|
||||
update_time_tick(ticks);
|
||||
elapsed = atomic_read(&g_timer_interval);
|
||||
|
||||
clock_increase_sched_ticks(elapsed);
|
||||
|
||||
/* Process the timer ticks and set up the next interval (or not) */
|
||||
|
||||
nexttime = nxsched_timer_process(ticks, elapsed, false);
|
||||
|
||||
elapsed = nxsched_timer_start(ticks, nexttime);
|
||||
atomic_set(&g_timer_interval, elapsed);
|
||||
nxsched_tick_expiration(ticks);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user