[d4d7899] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
[a344308] | 4 | * @brief Default Scheduler At Tick Handler |
---|
[d4d7899] | 5 | * |
---|
| 6 | * @ingroup ScoreScheduler |
---|
| 7 | */ |
---|
| 8 | |
---|
[05df0a8] | 9 | /* |
---|
[dca9a82] | 10 | * COPYRIGHT (c) 1989-2009. |
---|
[05df0a8] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
[dcf3687] | 14 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[05df0a8] | 16 | */ |
---|
| 17 | |
---|
[a8eed23] | 18 | #if HAVE_CONFIG_H |
---|
| 19 | #include "config.h" |
---|
| 20 | #endif |
---|
| 21 | |
---|
[c6e21ee1] | 22 | #include <rtems/score/schedulerimpl.h> |
---|
[5618c37a] | 23 | #include <rtems/score/threadimpl.h> |
---|
[a344308] | 24 | #include <rtems/score/smp.h> |
---|
[e785fbaa] | 25 | #include <rtems/config.h> |
---|
[05df0a8] | 26 | |
---|
[c5831a3f] | 27 | void _Scheduler_default_Tick( |
---|
[e1598a6] | 28 | const Scheduler_Control *scheduler, |
---|
| 29 | Thread_Control *executing |
---|
[24934e36] | 30 | ) |
---|
[05df0a8] | 31 | { |
---|
[701dd96f] | 32 | (void) scheduler; |
---|
| 33 | |
---|
[05df0a8] | 34 | /* |
---|
[a0ed4ed] | 35 | * If the thread is not preemptible or is not ready, then |
---|
[05df0a8] | 36 | * just return. |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | if ( !executing->is_preemptible ) |
---|
| 40 | return; |
---|
| 41 | |
---|
| 42 | if ( !_States_Is_ready( executing->current_state ) ) |
---|
| 43 | return; |
---|
| 44 | |
---|
| 45 | /* |
---|
| 46 | * The cpu budget algorithm determines what happens next. |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | switch ( executing->budget_algorithm ) { |
---|
| 50 | case THREAD_CPU_BUDGET_ALGORITHM_NONE: |
---|
| 51 | break; |
---|
| 52 | |
---|
| 53 | case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE: |
---|
[442eac69] | 54 | #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) |
---|
| 55 | case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: |
---|
| 56 | #endif |
---|
[c0f4682] | 57 | if ( (int)(--executing->cpu_time_budget) <= 0 ) { |
---|
[8bef4cc] | 58 | |
---|
| 59 | /* |
---|
| 60 | * A yield performs the ready chain mechanics needed when |
---|
| 61 | * resetting a timeslice. If no other thread's are ready |
---|
| 62 | * at the priority of the currently executing thread, then the |
---|
| 63 | * executing thread's timeslice is reset. Otherwise, the |
---|
| 64 | * currently executing thread is placed at the rear of the |
---|
| 65 | * FIFO for this priority and a new heir is selected. |
---|
| 66 | */ |
---|
[701dd96f] | 67 | _Thread_Yield( executing ); |
---|
[e785fbaa] | 68 | executing->cpu_time_budget = |
---|
| 69 | rtems_configuration_get_ticks_per_timeslice(); |
---|
[05df0a8] | 70 | } |
---|
| 71 | break; |
---|
| 72 | |
---|
[442eac69] | 73 | #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) |
---|
| 74 | case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT: |
---|
| 75 | if ( --executing->cpu_time_budget == 0 ) |
---|
| 76 | (*executing->budget_callout)( executing ); |
---|
| 77 | break; |
---|
| 78 | #endif |
---|
[05df0a8] | 79 | } |
---|
| 80 | } |
---|