Skip to content

Commit bc1e1e1

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
sched: add nxsched_get_next_expired() support
Signed-off-by: ligd <[email protected]>
1 parent b010356 commit bc1e1e1

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

include/nuttx/arch.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,22 @@ void nxsched_alarm_expiration(FAR const struct timespec *ts);
25482548
void nxsched_alarm_tick_expiration(clock_t ticks);
25492549
#endif
25502550

2551+
/****************************************************************************
2552+
* Name: nxsched_get_next_expired
2553+
*
2554+
* Description:
2555+
* Get the time remaining until the next timer expiration.
2556+
*
2557+
* Input Parameters:
2558+
* None
2559+
*
2560+
* Returned Value:
2561+
* The time remaining until the next timer expiration.
2562+
*
2563+
****************************************************************************/
2564+
2565+
clock_t nxsched_get_next_expired(void);
2566+
25512567
/****************************************************************************
25522568
* Name: nxsched_process_cpuload_ticks
25532569
*

sched/sched/sched_timerexpiration.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,12 @@ static clock_t nxsched_timer_start(clock_t ticks, clock_t interval);
9393

9494
static clock_t g_timer_tick;
9595

96-
#ifndef CONFIG_SCHED_TICKLESS_ALARM
9796
/* This is the duration of the currently active timer or, when
9897
* nxsched_timer_expiration() is called, the duration of interval timer
9998
* that just expired. The value zero means that no timer was active.
10099
*/
101100

102101
static unsigned int g_timer_interval;
103-
#endif
104102

105103
/****************************************************************************
106104
* Private Functions
@@ -464,7 +462,7 @@ void nxsched_alarm_tick_expiration(clock_t ticks)
464462
nexttime = nxsched_timer_process(ticks, elapsed, false);
465463

466464
flags = enter_critical_section();
467-
nxsched_timer_start(ticks, nexttime);
465+
g_timer_interval = nxsched_timer_start(ticks, nexttime);
468466
leave_critical_section(flags);
469467
}
470468

@@ -593,11 +591,33 @@ void nxsched_reassess_timer(void)
593591
/* Process the timer ticks and start next timer */
594592

595593
nexttime = nxsched_timer_process(ticks, elapsed, true);
596-
elapsed = nxsched_timer_start(ticks, nexttime);
594+
g_timer_interval = nxsched_timer_start(ticks, nexttime);
595+
}
597596

598-
#ifndef CONFIG_SCHED_TICKLESS_ALARM
599-
g_timer_interval = elapsed;
600-
#endif
597+
/****************************************************************************
598+
* Name: nxsched_get_next_expired
599+
*
600+
* Description:
601+
* Get the time remaining until the next timer expiration.
602+
*
603+
* Input Parameters:
604+
* None
605+
*
606+
* Returned Value:
607+
* The time remaining until the next timer expiration.
608+
*
609+
****************************************************************************/
610+
611+
clock_t nxsched_get_next_expired(void)
612+
{
613+
irqstate_t flags;
614+
sclock_t ret;
615+
616+
flags = enter_critical_section();
617+
ret = g_timer_tick + g_timer_interval - clock_systime_ticks();
618+
leave_critical_section(flags);
619+
620+
return ret < 0 ? 0 : ret;
601621
}
602622

603623
#endif /* CONFIG_SCHED_TICKLESS */

0 commit comments

Comments
 (0)