diff options
author | Keith Packard <keithp@keithp.com> | 2012-10-25 13:42:10 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-10-26 14:07:04 -0700 |
commit | e57ab2a7bfb69c0ef9b5b7fa8e53e20a500e7c6c (patch) | |
tree | 08d961311a7d2e7612d5c9aa090fd7a1dcdd53e6 /src | |
parent | ccf0faa7d26d56deca7928b521d07be40504466a (diff) |
altos: Provide ao_task_alarm_tick to reduce per-tick cost
Cache the next wakeup time and check that before jumping to the task
code.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ao_task.c | 20 | ||||
-rw-r--r-- | src/core/ao_task.h | 1 | ||||
-rw-r--r-- | src/stm/ao_timer.c | 3 |
3 files changed, 13 insertions, 11 deletions
diff --git a/src/core/ao_task.c b/src/core/ao_task.c index 985c37fa..0411fbdd 100644 --- a/src/core/ao_task.c +++ b/src/core/ao_task.c @@ -114,6 +114,8 @@ ao_task_validate_alarm_queue(void) #define ao_task_validate_alarm_queue() #endif +uint16_t ao_task_alarm_tick; + static void ao_task_to_alarm_queue(struct ao_task *task) { @@ -126,6 +128,7 @@ ao_task_to_alarm_queue(struct ao_task *task) } } ao_list_append(&task->alarm_queue, &alarm_queue); + ao_task_alarm_tick = ao_list_first_entry(&alarm_queue, struct ao_task, alarm_queue)->alarm; ao_task_validate_alarm_queue(); } @@ -133,6 +136,10 @@ static void ao_task_from_alarm_queue(struct ao_task *task) { ao_list_del(&task->alarm_queue); + if (ao_list_is_empty(&alarm_queue)) + ao_task_alarm_tick = 0; + else + ao_task_alarm_tick = ao_list_first_entry(&alarm_queue, struct ao_task, alarm_queue)->alarm; ao_task_validate_alarm_queue(); } @@ -154,10 +161,7 @@ void ao_task_check_alarm(uint16_t tick) { struct ao_task *alarm, *next; - int i; - if (ao_num_tasks == 0) - return; ao_list_for_each_entry_safe(alarm, next, &alarm_queue, struct ao_task, alarm_queue) { if ((int16_t) (tick - alarm->alarm) < 0) break; @@ -173,6 +177,7 @@ ao_task_init(void) uint8_t i; ao_list_init(&run_queue); ao_list_init(&alarm_queue); + ao_task_alarm_tick = 0; for (i = 0; i < SLEEP_HASH_SIZE; i++) ao_list_init(&sleep_queue[i]); } @@ -264,14 +269,9 @@ ao_task_validate(void) } } } -#else -#define ao_task_validate() -#endif +#endif /* DEBUG */ -#else -#define ao_task_to_run_queue(task) -#define ao_task_to_alarm_queue(task) -#endif +#endif /* HAS_TASK_QUEUE */ void ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant diff --git a/src/core/ao_task.h b/src/core/ao_task.h index b3f152a0..049f69a7 100644 --- a/src/core/ao_task.h +++ b/src/core/ao_task.h @@ -82,6 +82,7 @@ ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *nam #if HAS_TASK_QUEUE /* Called on timer interrupt to check alarms */ +extern uint16_t ao_task_alarm_tick; void ao_task_check_alarm(uint16_t tick); #endif diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c index d69035f8..e07625d8 100644 --- a/src/stm/ao_timer.c +++ b/src/stm/ao_timer.c @@ -44,7 +44,8 @@ void stm_tim6_isr(void) stm_tim6.sr = 0; ++ao_tick_count; #if HAS_TASK_QUEUE - ao_task_check_alarm((uint16_t) ao_tick_count); + if (ao_task_alarm_tick && (int16_t) (ao_tick_count - ao_task_alarm_tick) >= 0) + ao_task_check_alarm((uint16_t) ao_tick_count); #endif #if AO_DATA_ALL if (++ao_data_count == ao_data_interval) { |