Skip to content

Commit 519ffe6

Browse files
wangchdoxiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent 590ea05 commit 519ffe6

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

drivers/timers/arch_alarm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void oneshot_callback(FAR struct oneshot_lowerhalf_s *lower,
5151

5252
ONESHOT_TICK_CURRENT(g_oneshot_lower, &now);
5353
#ifdef CONFIG_SCHED_TICKLESS
54-
nxsched_alarm_tick_expiration(now);
54+
nxsched_tick_expiration(now);
5555
#else
5656
/* Start the next tick first, in order to minimize latency. Ideally
5757
* the ONESHOT_TICK_START would also return the current tick so that

include/nuttx/arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,8 +2488,8 @@ void nxsched_timer_expiration(void);
24882488

24892489
#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
24902490
void nxsched_alarm_expiration(FAR const struct timespec *ts);
2491-
void nxsched_alarm_tick_expiration(clock_t ticks);
24922491
#endif
2492+
void nxsched_tick_expiration(clock_t ticks);
24932493

24942494
/****************************************************************************
24952495
* Name: nxsched_get_next_expired

sched/sched/sched_timerexpiration.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,20 @@ static clock_t nxsched_timer_start(clock_t ticks, clock_t interval)
470470
*
471471
****************************************************************************/
472472

473-
#ifdef CONFIG_SCHED_TICKLESS_ALARM
474-
void nxsched_alarm_tick_expiration(clock_t ticks)
473+
void nxsched_tick_expiration(clock_t ticks)
475474
{
476475
clock_t elapsed;
477476
clock_t nexttime;
477+
clock_t previous;
478478

479-
/* Save the time that the alarm occurred */
479+
previous = update_time_tick(ticks);
480480

481-
elapsed = ticks - update_time_tick(ticks);
481+
#ifdef CONFIG_SCHED_TICKLESS_ALARM
482+
elapsed = ticks - previous;
483+
#else
484+
UNUSED(previous);
485+
elapsed = atomic_read(&g_timer_interval);
486+
#endif
482487

483488
clock_increase_sched_ticks(elapsed);
484489

@@ -490,14 +495,15 @@ void nxsched_alarm_tick_expiration(clock_t ticks)
490495
atomic_set(&g_timer_interval, elapsed);
491496
}
492497

498+
#ifdef CONFIG_SCHED_TICKLESS_ALARM
493499
void nxsched_alarm_expiration(FAR const struct timespec *ts)
494500
{
495501
clock_t ticks;
496502

497503
DEBUGASSERT(ts);
498504

499505
ticks = clock_time2ticks_floor(ts);
500-
nxsched_alarm_tick_expiration(ticks);
506+
nxsched_tick_expiration(ticks);
501507
}
502508
#endif
503509

@@ -521,23 +527,12 @@ void nxsched_alarm_expiration(FAR const struct timespec *ts)
521527
void nxsched_timer_expiration(void)
522528
{
523529
clock_t ticks;
524-
clock_t elapsed;
525-
clock_t nexttime;
526530

527531
/* Get the interval associated with last expiration */
528532

529533
up_timer_gettick(&ticks);
530-
update_time_tick(ticks);
531-
elapsed = atomic_read(&g_timer_interval);
532-
533-
clock_increase_sched_ticks(elapsed);
534-
535-
/* Process the timer ticks and set up the next interval (or not) */
536534

537-
nexttime = nxsched_timer_process(ticks, elapsed, false);
538-
539-
elapsed = nxsched_timer_start(ticks, nexttime);
540-
atomic_set(&g_timer_interval, elapsed);
535+
nxsched_tick_expiration(ticks);
541536
}
542537
#endif
543538

0 commit comments

Comments
 (0)