-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sched: Improve timer vs task priority check (#417)
Rename sched_tasks_busy() to sched_check_set_tasks_busy() and change it to only return true if tasks are active (running or requested) for two consecutive calls. This makes it less likely that timers will yield to tasks except when tasks really are notably backlogged. This also makes it less likely that multiple steppers controlling the same rail will be interrupted by tasks mid-step. This should slightly improve the timing, and make it less likely that a halt during homing/probing will occur with these steppers taking a different number of total steps. Signed-off-by: Kevin O'Connor <[email protected]> Co-authored-by: Kevin O'Connor <[email protected]>
- Loading branch information
1 parent
50da0b4
commit df56732
Showing
6 changed files
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Basic scheduling functions and startup/shutdown code. | ||
// | ||
// Copyright (C) 2016-2021 Kevin O'Connor <[email protected]> | ||
// Copyright (C) 2016-2024 Kevin O'Connor <[email protected]> | ||
// | ||
// This file may be distributed under the terms of the GNU GPLv3 license. | ||
|
||
|
@@ -19,7 +19,7 @@ static struct timer periodic_timer, sentinel_timer, deleted_timer; | |
|
||
static struct { | ||
struct timer *timer_list, *last_insert; | ||
int8_t tasks_status; | ||
int8_t tasks_status, tasks_busy; | ||
uint8_t shutdown_status, shutdown_reason; | ||
} SchedStatus = {.timer_list = &periodic_timer, .last_insert = &periodic_timer}; | ||
|
||
|
@@ -205,11 +205,15 @@ sched_wake_tasks(void) | |
SchedStatus.tasks_status = TS_REQUESTED; | ||
} | ||
|
||
// Check if tasks need to be run | ||
// Check if tasks busy (called from low-level timer dispatch code) | ||
uint8_t | ||
sched_tasks_busy(void) | ||
sched_check_set_tasks_busy(void) | ||
{ | ||
return SchedStatus.tasks_status >= TS_REQUESTED; | ||
// Return busy if tasks never idle between two consecutive calls | ||
if (SchedStatus.tasks_busy >= TS_REQUESTED) | ||
return 1; | ||
SchedStatus.tasks_busy = SchedStatus.tasks_status; | ||
return 0; | ||
} | ||
|
||
// Note that a task is ready to run | ||
|
@@ -243,7 +247,7 @@ run_tasks(void) | |
irq_disable(); | ||
if (SchedStatus.tasks_status != TS_REQUESTED) { | ||
// Sleep processor (only run timers) until tasks woken | ||
SchedStatus.tasks_status = TS_IDLE; | ||
SchedStatus.tasks_status = SchedStatus.tasks_busy = TS_IDLE; | ||
do { | ||
irq_wait(); | ||
} while (SchedStatus.tasks_status != TS_REQUESTED); | ||
|
This file contains 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