sched/sched: Remove nxsched_alarm_expiration

This commit removed nxsched_alarm_expiration to simplify the timer
expiration.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen
2025-11-12 10:38:12 +08:00
committed by Xiang Xiao
parent 3aed2485f8
commit e5db83d7db
16 changed files with 86 additions and 151 deletions
-10
View File
@@ -32,16 +32,6 @@ OS List Management APIs
**Assumptions**: Base code implementation assumes that this
function is called from interrupt handling logic with interrupts disabled.
.. c:function:: void nxsched_alarm_expiration(void);
If ``CONFIG_SCHED_TICKLESS`` is defined, then this
function is provided by the RTOS base code and called from
platform-specific code when the interval timer used to implemented
the tick-less OS expires.
**Assumptions**: Base code implementation assumes that this
function is called from interrupt handling logic with interrupts disabled.
.. c:function:: void irq_dispatch(int irq, FAR void *context)
This function must be called from the
@@ -372,7 +372,6 @@ In addition to these imported interfaces, the RTOS will export the
following interfaces for use by the platform-specific interval
timer implementation:
- ``nxsched_alarm_expiration()``: called by the platform-specific logic when the alarm expires.
- ``nxsched_timer_expiration()``: called by the platform-specific logic when the interval time expires.
.. c:function:: void archname_timer_initialize(void)
+4 -6
View File
@@ -168,7 +168,6 @@ static uint64_t imxrt_get_counter(void)
static void imxrt_interval_handler(void)
{
struct timespec tv;
uint32_t regval;
/* Disable the compare interrupt for now */
@@ -184,8 +183,7 @@ static void imxrt_interval_handler(void)
g_tickless.pending = false;
up_timer_gettime(&tv);
nxsched_alarm_expiration(&tv);
nxsched_timer_expiration();
}
/****************************************************************************
@@ -479,7 +477,7 @@ int up_timer_gettime(struct timespec *ts)
* Name: up_alarm_start
*
* Description:
* Start the alarm. nxsched_alarm_expiration() will be called when the
* Start the alarm. nxsched_timer_expiration() will be called when the
* alarm occurs (unless up_alaram_cancel is called to stop it).
*
* Provided by platform-specific code and called from the RTOS base code.
@@ -487,7 +485,7 @@ int up_timer_gettime(struct timespec *ts)
* Input Parameters:
* ts - The time in the future at the alarm is expected to occur. When
* the alarm occurs the timer logic will call
* nxsched_alarm_expiration().
* nxsched_timer_expiration().
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
@@ -555,7 +553,7 @@ int up_alarm_start(const struct timespec *ts)
* Description:
* Cancel the alarm and return the time of cancellation of the alarm.
* These two steps need to be as nearly atomic as possible.
* nxsched_alarm_expiration() will not be called unless the alarm is
* nxsched_timer_expiration() will not be called unless the alarm is
* restarted with up_alarm_start().
*
* If, as a race condition, the alarm has already expired when this
+1 -4
View File
@@ -68,7 +68,6 @@
static double sec_per_tick;
static uint64_t g_internal_timer;
static uint64_t g_alarm;
struct timespec g_ts;
/****************************************************************************
* Private Functions
@@ -87,9 +86,7 @@ static int lpc43_rit_isr(int irq, void *context, void *arg)
{
/* handle expired alarm */
g_ts.tv_sec = (uint32_t)(g_internal_timer / 1000000000);
g_ts.tv_nsec = (uint32_t)(g_internal_timer % 1000000000);
nxsched_alarm_expiration(&g_ts);
nxsched_timer_expiration();
}
leave_critical_section(flags);
@@ -496,13 +496,7 @@ static inline void lpc43_tl_alarm(uint32_t curr)
lpc43_tl_init_timer_vars();
lpc43_tl_set_default_compare(curr);
#ifdef CONFIG_SCHED_TICKLESS_ALARM
struct timespec ts;
up_timer_gettime(&ts);
nxsched_alarm_expiration(&ts);
#else
nxsched_timer_expiration();
#endif
}
/* Interrupt handler */
-6
View File
@@ -539,13 +539,7 @@ static inline void lpc54_tl_alarm(uint64_t curr)
lpc54_init_timer_vars();
lpc54_set_default_compare(curr);
#ifdef CONFIG_SCHED_TICKLESS_ALARM
struct timespec ts;
up_timer_gettime(&ts);
nxsched_alarm_expiration(&ts);
#else
nxsched_timer_expiration();
#endif
}
/* Interrupt handler */
+25 -10
View File
@@ -187,6 +187,25 @@ static void rtc_prepare_alarm(void)
}
}
/****************************************************************************
* Name: rtc_cancel_ack
****************************************************************************/
static void rtc_cancel_ack(void)
{
irqstate_t flags;
flags = enter_critical_section();
NRF52_RTC_DISABLEINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0);
NRF52_RTC_ACKINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0);
g_tickless_dev.alarm_set = false;
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Name: rtc_handler
****************************************************************************/
@@ -221,15 +240,13 @@ static int rtc_handler(int irq, void *context, void *arg)
if (NRF52_RTC_CHECKINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0))
{
struct timespec now;
/* cancel the alarm and ack the event */
/* cancel alarm and get current time */
up_alarm_cancel(&now);
rtc_cancel_ack();
/* let scheduler now of alarm firing */
nxsched_alarm_expiration(&now);
nxsched_timer_expiration();
}
leave_critical_section(flags);
@@ -254,13 +271,14 @@ int up_alarm_cancel(struct timespec *ts)
NRF52_RTC_DISABLEINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0);
NRF52_RTC_GETCOUNTER(g_tickless_dev.rtc, &counter);
rtc_counter_to_ts(counter, ts);
NRF52_RTC_ACKINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0);
g_tickless_dev.alarm_set = false;
leave_critical_section(flags);
rtc_counter_to_ts(counter, ts);
return OK;
}
@@ -310,8 +328,6 @@ int up_timer_gettime(struct timespec *ts)
void up_timer_initialize(void)
{
struct timespec ts;
memset(&g_tickless_dev, 0, sizeof(struct nrf52_tickless_dev_s));
g_tickless_dev.rtc = nrf52_rtc_init(CONFIG_NRF52_SYSTIMER_RTC_INSTANCE);
@@ -341,6 +357,5 @@ void up_timer_initialize(void)
/* kick off alarm scheduling */
ts.tv_sec = ts.tv_nsec = 0;
nxsched_alarm_expiration(&ts);
nxsched_timer_expiration();
}
+25 -10
View File
@@ -185,6 +185,25 @@ static void rtc_prepare_alarm(void)
}
}
/****************************************************************************
* Name: rtc_cancel_ack
****************************************************************************/
static void rtc_cancel_ack(void)
{
irqstate_t flags;
flags = enter_critical_section();
NRF53_RTC_DISABLEINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0);
NRF53_RTC_ACKINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0);
g_tickless_dev.alarm_set = false;
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Name: rtc_handler
****************************************************************************/
@@ -219,15 +238,13 @@ static int rtc_handler(int irq, void *context, void *arg)
if (NRF53_RTC_CHECKINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0))
{
struct timespec now;
/* cancel the alarm and ack the event */
/* cancel alarm and get current time */
up_alarm_cancel(&now);
rtc_cancel_ack();
/* let scheduler now of alarm firing */
nxsched_alarm_expiration(&now);
nxsched_timer_expiration();
}
leave_critical_section(flags);
@@ -252,13 +269,14 @@ int up_alarm_cancel(struct timespec *ts)
NRF53_RTC_DISABLEINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0);
NRF53_RTC_GETCOUNTER(g_tickless_dev.rtc, &counter);
rtc_counter_to_ts(counter, ts);
NRF53_RTC_ACKINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0);
g_tickless_dev.alarm_set = false;
leave_critical_section(flags);
rtc_counter_to_ts(counter, ts);
return OK;
}
@@ -308,8 +326,6 @@ int up_timer_gettime(struct timespec *ts)
void up_timer_initialize(void)
{
struct timespec ts;
memset(&g_tickless_dev, 0, sizeof(struct nrf53_tickless_dev_s));
g_tickless_dev.rtc = nrf53_rtc_init(CONFIG_NRF53_SYSTIMER_RTC_INSTANCE);
@@ -339,6 +355,5 @@ void up_timer_initialize(void)
/* kick off alarm scheduling */
ts.tv_sec = ts.tv_nsec = 0;
nxsched_alarm_expiration(&ts);
nxsched_timer_expiration();
}
+21 -10
View File
@@ -185,6 +185,21 @@ static void rtc_prepare_alarm(void)
}
}
static void rtc_cancel_ack(void)
{
irqstate_t flags;
flags = enter_critical_section();
NRF91_RTC_DISABLEINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0);
NRF91_RTC_ACKINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0);
g_tickless_dev.alarm_set = false;
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Name: rtc_handler
****************************************************************************/
@@ -219,15 +234,13 @@ static int rtc_handler(int irq, void *context, void *arg)
if (NRF91_RTC_CHECKINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0))
{
struct timespec now;
/* cancel the alarm and ack the event */
/* cancel alarm and get current time */
up_alarm_cancel(&now);
rtc_cancel_ack();
/* let scheduler now of alarm firing */
nxsched_alarm_expiration(&now);
nxsched_timer_expiration();
}
leave_critical_section(flags);
@@ -252,13 +265,14 @@ int up_alarm_cancel(struct timespec *ts)
NRF91_RTC_DISABLEINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0);
NRF91_RTC_GETCOUNTER(g_tickless_dev.rtc, &counter);
rtc_counter_to_ts(counter, ts);
NRF91_RTC_ACKINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0);
g_tickless_dev.alarm_set = false;
leave_critical_section(flags);
rtc_counter_to_ts(counter, ts);
return OK;
}
@@ -308,8 +322,6 @@ int up_timer_gettime(struct timespec *ts)
void up_timer_initialize(void)
{
struct timespec ts;
memset(&g_tickless_dev, 0, sizeof(struct nrf91_tickless_dev_s));
g_tickless_dev.rtc = nrf91_rtc_init(CONFIG_NRF91_SYSTIMER_RTC_INSTANCE);
@@ -339,6 +351,5 @@ void up_timer_initialize(void)
/* kick off alarm scheduling */
ts.tv_sec = ts.tv_nsec = 0;
nxsched_alarm_expiration(&ts);
nxsched_timer_expiration();
}
-8
View File
@@ -313,9 +313,6 @@ static int stm32_tickless_setchannel(uint8_t channel)
static void stm32_interval_handler(void)
{
#ifdef CONFIG_SCHED_TICKLESS_ALARM
struct timespec tv;
#endif
tmrinfo("Expired...\n");
/* Disable the compare interrupt now. */
@@ -325,12 +322,7 @@ static void stm32_interval_handler(void)
g_tickless.pending = false;
#ifndef CONFIG_SCHED_TICKLESS_ALARM
nxsched_timer_expiration();
#else
up_timer_gettime(&tv);
nxsched_alarm_expiration(&tv);
#endif
}
/****************************************************************************
-8
View File
@@ -300,9 +300,6 @@ static int stm32_tickless_setchannel(uint8_t channel)
static void stm32_interval_handler(void)
{
#ifdef CONFIG_SCHED_TICKLESS_ALARM
struct timespec tv;
#endif
tmrinfo("Expired...\n");
/* Disable the compare interrupt now. */
@@ -312,12 +309,7 @@ static void stm32_interval_handler(void)
g_tickless.pending = false;
#ifndef CONFIG_SCHED_TICKLESS_ALARM
nxsched_timer_expiration();
#else
up_timer_gettime(&tv);
nxsched_alarm_expiration(&tv);
#endif
}
/****************************************************************************
+3 -3
View File
@@ -385,7 +385,7 @@ int up_timer_gettime(struct timespec *ts)
* Name: up_alarm_start
*
* Description:
* Start the alarm. nxsched_alarm_expiration() will be called when the
* Start the alarm. nxsched_timer_expiration() will be called when the
* alarm occurs (unless up_alaram_cancel is called to stop it).
*
* Provided by platform-specific code and called from the RTOS base code.
@@ -393,7 +393,7 @@ int up_timer_gettime(struct timespec *ts)
* Input Parameters:
* ts - The time in the future at the alarm is expected to occur. When
* the alarm occurs the timer logic will call
* nxsched_alarm_expiration().
* nxsched_timer_expiration().
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
@@ -466,7 +466,7 @@ int up_timer_start(const struct timespec *ts)
* Description:
* Cancel the alarm and return the time of cancellation of the alarm.
* These two steps need to be as nearly atomic as possible.
* nxsched_alarm_expiration() will not be called unless the alarm is
* nxsched_timer_expiration() will not be called unless the alarm is
* restarted with up_alarm_start().
*
* If, as a race condition, the alarm has already expired when this
@@ -277,8 +277,7 @@ static void avrdx_check_alarm_expired(uint8_t context)
*/
avrdx_deactivate_alarm();
up_timer_gettime(&tv);
nxsched_alarm_expiration(&tv);
nxsched_timer_expiration();
}
else
{
+3 -3
View File
@@ -301,7 +301,7 @@ int weak_function up_timer_gettime(struct timespec *ts)
* Description:
* Cancel the alarm and return the time of cancellation of the alarm.
* These two steps need to be as nearly atomic as possible.
* nxsched_alarm_expiration() will not be called unless the alarm is
* nxsched_timer_expiration() will not be called unless the alarm is
* restarted with up_alarm_start().
*
* If, as a race condition, the alarm has already expired when this
@@ -348,14 +348,14 @@ int weak_function up_alarm_tick_cancel(FAR clock_t *ticks)
* Name: up_alarm_start
*
* Description:
* Start the alarm. nxsched_alarm_expiration() will be called when the
* Start the alarm. nxsched_timer_expiration() will be called when the
* alarm occurs (unless up_alaram_cancel is called to stop it).
*
* Provided by platform-specific code and called from the RTOS base code.
*
* Input Parameters:
* ts - The time in the future at the alarm is expected to occur. When the
* alarm occurs the timer logic will call nxsched_alarm_expiration().
* alarm occurs the timer logic will call nxsched_timer_expiration().
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
+3 -32
View File
@@ -1885,13 +1885,8 @@ void up_timer_initialize(void);
* The RTOS will provide the following interfaces for use by the platform-
* specific interval timer implementation:
*
* #ifdef CONFIG_SCHED_TICKLESS_ALARM
* void nxsched_alarm_expiration(FAR const struct timespec *ts): Called
* by the platform-specific logic when the alarm expires.
* #else
* void nxsched_timer_expiration(void): Called by the platform-specific
* logic when the interval timer expires.
* #endif
*
****************************************************************************/
@@ -1938,7 +1933,7 @@ void up_timer_getmask(FAR clock_t *mask);
* Description:
* Cancel the alarm and return the time of cancellation of the alarm.
* These two steps need to be as nearly atomic as possible.
* nxsched_alarm_expiration() will not be called unless the alarm is
* nxsched_timer_expiration() will not be called unless the alarm is
* restarted with up_alarm_start().
*
* If, as a race condition, the alarm has already expired when this
@@ -1978,7 +1973,7 @@ int up_alarm_tick_cancel(FAR clock_t *ticks);
* Name: up_alarm_start
*
* Description:
* Start the alarm. nxsched_alarm_expiration() will be called when the
* Start the alarm. nxsched_timer_expiration() will be called when the
* alarm occurs (unless up_alaram_cancel is called to stop it).
*
* Provided by platform-specific code and called from the RTOS base code.
@@ -1986,7 +1981,7 @@ int up_alarm_tick_cancel(FAR clock_t *ticks);
* Input Parameters:
* ts - The time in the future at the alarm is expected to occur. When
* the alarm occurs the timer logic will call
* nxsched_alarm_expiration().
* nxsched_timer_expiration().
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
@@ -2466,30 +2461,6 @@ void nxsched_process_timer(void);
void nxsched_timer_expiration(void);
#endif
/****************************************************************************
* Name: nxsched_alarm_expiration
*
* Description:
* if CONFIG_SCHED_TICKLESS is defined, then this function is provided by
* the RTOS base code and called from platform-specific code when the
* alarm used to implement the tick-less OS expires.
*
* Input Parameters:
* ts - The time that the alarm expired
*
* Returned Value:
* None
*
* Assumptions/Limitations:
* Base code implementation assumes that this function is called from
* interrupt handling logic with interrupts disabled.
*
****************************************************************************/
#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
void nxsched_alarm_expiration(FAR const struct timespec *ts);
#endif
/****************************************************************************
* Name: nxsched_get_next_expired
*
-32
View File
@@ -451,38 +451,6 @@ clock_t nxsched_timer_update(clock_t ticks, bool noswitches)
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxsched_alarm_expiration
*
* Description:
* if CONFIG_SCHED_TICKLESS is defined, then this function is provided by
* the RTOS base code and called from platform-specific code when the
* alarm used to implement the tick-less OS expires.
*
* Input Parameters:
* ts - The time that the alarm expired
*
* Returned Value:
* None
*
* Assumptions/Limitations:
* Base code implementation assumes that this function is called from
* interrupt handling logic with interrupts disabled.
*
****************************************************************************/
#ifdef CONFIG_SCHED_TICKLESS_ALARM
void nxsched_alarm_expiration(FAR const struct timespec *ts)
{
clock_t ticks;
DEBUGASSERT(ts);
ticks = clock_time2ticks_floor(ts);
nxsched_timer_update(ticks, false);
}
#endif
/****************************************************************************
* Name: nxsched_timer_expiration
*