-
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
Open
wangchdo
wants to merge
1
commit into
apache:master
Choose a base branch
from
wangchdo:add_hrtimer_sched_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||||||
| * | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
xiaoxiang781216 marked this conversation as resolved.
Show resolved
Hide resolved
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. |
||
|
|
||
| /**************************************************************************** | ||
| * 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Uh oh!
There was an error while loading. Please reload this page.
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.
wouldn't that break backward compatibility with existing tickless timer? :-P