aboutsummaryrefslogtreecommitdiffstats
path: root/src/sched.c
Commit message (Collapse)AuthorAgeFilesLines
* sched: Implement generic sleep mechanism based on tasks pendingKevin O'Connor2017-08-081-8/+49
| | | | | | | | | Track when tasks are pending and spin in irq_wait() when no tasks are pending. This improves the mechanism for sleeping the processor - it's simpler for the board specific code and it reduces the possibility of the processor sleeping when tasks are busy. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Introduce sched_wake_tasks() function to wake up tasksKevin O'Connor2017-08-081-0/+10
| | | | | | | | Add function to indicate when tasks need to be run. This will allow the scheduler code to know if there are any tasks that need to be processed. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Implement internal avr specific timer to handle 16bit overflowsKevin O'Connor2017-08-081-7/+6
| | | | | | | | | | Don't rely on the generic scheduler code to always have a timer no more than 1ms in the future. Instead, create an avr specific timer that will be called every 0x8000 ticks. This simplifies the generic code and it reduces the amount of code that needs to be run every millisecond. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Support adding timers to the start of timer_listKevin O'Connor2017-08-081-5/+18
| | | | | | | | If sched_add_timer() is called on a timer that would make it the new head of the list, then add it and signal the board code that the timer should be rescheduled. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Don't count milliseconds in the periodic timerKevin O'Connor2017-08-081-32/+38
| | | | | | | It's not necessary to keep a millisecond counter. Replace the two users of sched_check_periodic() with explicit task wakeup flags. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Pass shutdown reason code via longjmp() parameterKevin O'Connor2017-07-041-5/+5
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* build: Use compile_time_request system for init, tasks, and shutdownKevin O'Connor2017-05-261-31/+9
| | | | | | | | Avoid using linker magic to define the init, task, and shutdown functions. Instead, use the compile_time_request system. This simplifies the build and produces more efficient code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Allow shutdown_reason to be uint8Kevin O'Connor2017-05-261-10/+11
| | | | | | | Store the shutdown_reason code in an 8-bit integer - this produces better code on AVR. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* irq: Add an irq_poll() stub for board codeKevin O'Connor2017-05-151-0/+1
| | | | | | | Allow the board specific code to run checks prior to running each task. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Move timer dispatch loop to board codeKevin O'Connor2017-03-301-30/+25
| | | | | | | | Rename sched_timer_kick() to sched_timer_dispatch() and move its loop into its callers in the board code. This eliminates the need to export timer_try_set_next() from the board code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Rename reschedule_timer() to insert_timer() and use in sched_add_timer()Kevin O'Connor2017-03-301-29/+23
| | | | | | | Use the same code in both rescheduling of a timer and adding a new timer. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Be explicit with loading of the waketime variableKevin O'Connor2017-03-261-21/+21
| | | | | | | | | Explicilty load the timer waketime variable into local variables in sched_timer_kick(). Change the optimization level from Os to O2. This helps gcc to avoid unnecessary reloads from memory in the common stepper_event() case. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Introduce optimized timer_is_before()Kevin O'Connor2017-03-261-3/+3
| | | | | | | | | Provide hand-coded assembler for timer_is_before() on AVR as that code is used frequently in the time-critical timer dispatch loop and gcc doesn't do a good job at compiling that comparison code. Remove the no longer needed waketime+1 hack from reschedule_timer(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Allow board code to define its own timer_is_before implementationKevin O'Connor2017-03-261-30/+7
| | | | | | | | | | | | Move sched_is_before() from sched.c to timer_is_before() in the board specific timer code. This allows the board code to provide its own definition. Also, remove the sched_from_us() and sched_read_time() wrapper functions and change the callers to directly invoke timer_from_us() / timer_read_time(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Report the time of a shutdownKevin O'Connor2017-03-241-1/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Move functions within sched.cKevin O'Connor2017-03-111-40/+38
| | | | | | Just code movement - no code changes. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Rename sched_timer() to sched_add_timer()Kevin O'Connor2017-03-111-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Don't overwrite shutdown reason if shutdown called while shutdownKevin O'Connor2017-03-101-1/+2
| | | | | | | If a shutdown occurs while the machine is already shutdown, then keep the original shutdown reason code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Avoid rescheduling the currently active timerKevin O'Connor2017-03-101-22/+29
| | | | | | | | | It's tricky to reschedule the timer irq correctly (due to race conditions with the irq) and in practice it's very rarely needed. Handle the special cases in the generic sched.c code so that the board code doesn't have to handle it. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Use a sentinel timer at the end of the timer_listKevin O'Connor2017-03-101-9/+29
| | | | | | | | Introduce a dummy sentinel timer object that is always the last item on timer_list. This optimizes the timer_list walking code as it no longer needs to check for NULL when traversing the list. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Minor change - remove unneeded header filesKevin O'Connor2017-01-141-2/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Improve AVR optimization of reschedule_timer()Kevin O'Connor2016-10-191-7/+11
| | | | | | | | Tweak the AVR register pressure optimization in reschedule_timer() to optimize it further. This improves the performance of AVR timers when there are several pending timers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Use 'unsigned int' instead of 'uint16_t' for shutdown reasonKevin O'Connor2016-06-141-2/+2
| | | | | | | Use 'unsigned int' instead of 'uint16_t' as is faster on some platforms. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Use uint_fast8_t for return type of timersKevin O'Connor2016-06-141-2/+2
| | | | | | | | Some architectures are faster passing regular integers than 8bit integers. Use uint_fast8_t so that the architecture chooses the appropriate type. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* irq: Allow boards to define the return type of irq_save()Kevin O'Connor2016-06-131-3/+3
| | | | | | | | The AVR wants a uint8_t return type for irq_save(), but other architectures will generally prefer int. Allow the board to configure the size of the flag by introducing an irqstatus_t typedef. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* generic: Move board timer.h files into generic/misc.hKevin O'Connor2016-06-131-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Optimize timer list handlingKevin O'Connor2016-06-131-39/+50
| | | | | | Rework the timer list rescheduling to be more optimized. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Change sched_from_ms() to sched_from_us()Kevin O'Connor2016-06-021-6/+6
| | | | | | | Some code may require micro-second precision so update sched_from_ms() to use micro-seconds. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Initial commit of source code.Kevin O'Connor2016-05-251-0/+282
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>