-
Notifications
You must be signed in to change notification settings - Fork 1.4k
sched/hrtimer: introduce scheduler support with hrtimer #17573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2031,7 +2031,8 @@ int up_alarm_tick_cancel(FAR clock_t *ticks); | |||||
| * | ||||||
| ****************************************************************************/ | ||||||
|
|
||||||
| #if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM) | ||||||
| #if defined(CONFIG_HRTIMER)|| \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| (defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)) | ||||||
| int up_alarm_start(FAR const struct timespec *ts); | ||||||
| int up_alarm_tick_start(clock_t ticks); | ||||||
| #endif | ||||||
|
|
@@ -2461,10 +2462,7 @@ void up_ndelay(unsigned long nanoseconds); | |||||
| * | ||||||
| ****************************************************************************/ | ||||||
|
|
||||||
| #ifndef CONFIG_SCHED_TICKLESS | ||||||
| void nxsched_process_timer(void); | ||||||
| #endif | ||||||
|
|
||||||
| /**************************************************************************** | ||||||
| * Name: nxsched_timer_expiration | ||||||
| * | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,108 @@ | |
| #include "sched/sched.h" | ||
| #include "wdog/wdog.h" | ||
| #include "clock/clock.h" | ||
| #include "hrtimer/hrtimer.h" | ||
|
|
||
| /**************************************************************************** | ||
| * Private Data | ||
| ****************************************************************************/ | ||
|
|
||
| #ifdef CONFIG_HRTIMER | ||
|
|
||
| /* Scheduler-owned high-resolution timer instance. | ||
| * | ||
| * This timer acts as the time source for scheduler-related events: | ||
| * | ||
| * - Periodic scheduler ticks in non-tickless mode | ||
| * - Dynamic expiration points in tickless mode | ||
| * | ||
| * The timer is initialized lazily to avoid unnecessary setup when | ||
| * CONFIG_HRTIMER is enabled but not used immediately. | ||
| */ | ||
|
|
||
| static hrtimer_t g_nxsched_hrtimer; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's init to func directly and remove g_sched_hrtimer_inited
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| /**************************************************************************** | ||
| * Private Functions | ||
| ****************************************************************************/ | ||
|
|
||
| static void nxsched_process_tick(void); | ||
|
|
||
| /**************************************************************************** | ||
| * Name: nxsched_hrtimer_callback | ||
| * | ||
| * Description: | ||
| * Callback invoked by the high-resolution timer framework when the | ||
| * scheduler timer expires. | ||
| * | ||
| * Behavior depends on scheduler configuration: | ||
| * | ||
| * CONFIG_SCHED_TICKLESS: | ||
| * - Query current high-resolution time | ||
| * - Convert time to scheduler ticks | ||
| * - Notify scheduler via nxsched_tick_expiration() | ||
| * | ||
| * !CONFIG_SCHED_TICKLESS: | ||
| * - Re-arm the next periodic tick | ||
| * - Process a single scheduler tick | ||
| * | ||
| * Input Parameters: | ||
| * hrtimer - Pointer to the expired high-resolution timer | ||
| * | ||
| * Returned Value: | ||
| * In non-tickless mode, returns the interval until the next expiration. | ||
| * In tickless mode, the return value is ignored. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| static uint64_t | ||
| nxsched_hrtimer_callback(FAR hrtimer_t *hrtimer, uint64_t expired) | ||
| { | ||
| UNUSED(hrtimer); | ||
| UNUSED(expired); | ||
|
|
||
| #ifdef CONFIG_SCHED_TICKLESS | ||
| nxsched_timer_expiration(); | ||
| #else | ||
| nxsched_process_tick(); | ||
| return NSEC_PER_TICK; | ||
| #endif | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
| * Name: nxsched_process_hrtimer | ||
| * | ||
| * Description: | ||
| * Entry point for scheduler-related high-resolution timer processing. | ||
| * | ||
| * Responsibilities: | ||
| * - Process expired hrtimer events | ||
| * - Perform one-time initialization of the scheduler hrtimer | ||
| * - Arm the initial scheduler timer event | ||
| * | ||
| * This function is expected to be called from architecture-specific | ||
| * timer interrupt handling code. | ||
| * | ||
| * Input Parameters: | ||
| * None | ||
| * | ||
| * Returned Value: | ||
| * None | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| static void nxsched_process_hrtimer(void) | ||
| { | ||
| uint64_t now = hrtimer_gettime(); | ||
anchao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /* Process any expired high-resolution timers */ | ||
|
|
||
| hrtimer_process(now); | ||
| } | ||
| #endif /* CONFIG_HRTIMER */ | ||
|
|
||
| #ifndef CONFIG_SCHED_TICKLESS | ||
|
|
||
| /**************************************************************************** | ||
| * Name: nxsched_cpu_scheduler | ||
| * | ||
|
|
@@ -145,19 +242,7 @@ static inline void nxsched_process_scheduler(void) | |
| #endif | ||
|
|
||
| /**************************************************************************** | ||
| * Public Functions | ||
| ****************************************************************************/ | ||
|
|
||
| /**************************************************************************** | ||
| * System Timer Hooks | ||
| * | ||
| * These are standard interfaces that are exported by the OS | ||
| * for use by the architecture specific logic | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| /**************************************************************************** | ||
| * Name: nxsched_process_timer | ||
| * Name: nxsched_process_tick | ||
| * | ||
| * Description: | ||
| * This function handles system timer events. | ||
|
|
@@ -174,7 +259,7 @@ static inline void nxsched_process_scheduler(void) | |
| * | ||
| ****************************************************************************/ | ||
|
|
||
| void nxsched_process_timer(void) | ||
| static void nxsched_process_tick(void) | ||
| { | ||
| #ifdef CONFIG_CLOCK_TIMEKEEPING | ||
| /* Process wall time */ | ||
|
|
@@ -204,3 +289,77 @@ void nxsched_process_timer(void) | |
| board_timerhook(); | ||
| #endif | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef CONFIG_HRTIMER | ||
|
|
||
| /**************************************************************************** | ||
| * Name: nxsched_hrtimer_init | ||
| * | ||
| * Description: | ||
| * Initialize the scheduler high-resolution timer (hrtimer) instance | ||
| * and arm the first scheduler timer event. | ||
| * | ||
| * Returned Value: | ||
| * Zero on success, or a negative errno value on failure. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| int nxsched_hrtimer_init(void) | ||
| { | ||
| /* Initialize the scheduler hrtimer instance */ | ||
|
|
||
| hrtimer_init(&g_nxsched_hrtimer, nxsched_hrtimer_callback); | ||
|
|
||
| /* Start the first scheduler timer event with one tick interval */ | ||
|
|
||
| return hrtimer_start(&g_nxsched_hrtimer, NSEC_PER_TICK, HRTIMER_MODE_REL); | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
| * Name: nxsched_hrtimer_start | ||
| * | ||
| * Description: | ||
| * Start or re-arm the scheduler high-resolution timer. | ||
| * | ||
| * Input Parameters: | ||
| * ticks - Absolute expiration time | ||
| * | ||
| * Returned Value: | ||
| * Zero on success, or a negative errno value on failure. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| int nxsched_hrtimer_start(clock_t ticks) | ||
| { | ||
| return hrtimer_start(&g_nxsched_hrtimer, ticks, HRTIMER_MODE_ABS); | ||
| } | ||
| #endif | ||
|
|
||
| /**************************************************************************** | ||
| * System Timer Hooks | ||
| * | ||
| * These are standard interfaces that are exported by the OS | ||
| * for use by the architecture specific logic | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| void nxsched_process_timer(void) | ||
| { | ||
| #if defined(CONFIG_HRTIMER) | ||
| /* High-resolution timer-based scheduling */ | ||
|
|
||
| nxsched_process_hrtimer(); | ||
|
|
||
| #elif defined(CONFIG_SCHED_TICKLESS) | ||
| /* Legacy tickless scheduling */ | ||
|
|
||
| nxsched_timer_expiration(); | ||
|
|
||
| #else | ||
| /* Legacy periodic tick-based scheduling */ | ||
|
|
||
| nxsched_process_tick(); | ||
|
|
||
| #endif | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we update all driver and remove nxsched_timer_expiration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let me consider about this