[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 |
---|
[dd687d97] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[05df0a8] | 16 | */ |
---|
| 17 | |
---|
[a8eed23] | 18 | #if HAVE_CONFIG_H |
---|
| 19 | #include "config.h" |
---|
| 20 | #endif |
---|
| 21 | |
---|
[05df0a8] | 22 | #include <rtems/system.h> |
---|
[a344308] | 23 | #include <rtems/score/scheduler.h> |
---|
| 24 | #include <rtems/score/thread.h> |
---|
| 25 | #include <rtems/score/smp.h> |
---|
[05df0a8] | 26 | |
---|
[a344308] | 27 | static void _Scheduler_default_Tick_for_executing( Thread_Control *executing ) |
---|
[05df0a8] | 28 | { |
---|
[c6f7e060] | 29 | #ifdef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
[c3330a8] | 30 | /* |
---|
| 31 | * Increment the number of ticks this thread has been executing |
---|
| 32 | */ |
---|
[5fa5185] | 33 | executing->cpu_time_used++; |
---|
[c3330a8] | 34 | #endif |
---|
[05df0a8] | 35 | |
---|
| 36 | /* |
---|
[a0ed4ed] | 37 | * If the thread is not preemptible or is not ready, then |
---|
[05df0a8] | 38 | * just return. |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | if ( !executing->is_preemptible ) |
---|
| 42 | return; |
---|
| 43 | |
---|
| 44 | if ( !_States_Is_ready( executing->current_state ) ) |
---|
| 45 | return; |
---|
| 46 | |
---|
| 47 | /* |
---|
| 48 | * The cpu budget algorithm determines what happens next. |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | switch ( executing->budget_algorithm ) { |
---|
| 52 | case THREAD_CPU_BUDGET_ALGORITHM_NONE: |
---|
| 53 | break; |
---|
| 54 | |
---|
| 55 | case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE: |
---|
[442eac69] | 56 | #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) |
---|
| 57 | case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: |
---|
| 58 | #endif |
---|
[c0f4682] | 59 | if ( (int)(--executing->cpu_time_budget) <= 0 ) { |
---|
[8bef4cc] | 60 | |
---|
| 61 | /* |
---|
| 62 | * A yield performs the ready chain mechanics needed when |
---|
| 63 | * resetting a timeslice. If no other thread's are ready |
---|
| 64 | * at the priority of the currently executing thread, then the |
---|
| 65 | * executing thread's timeslice is reset. Otherwise, the |
---|
| 66 | * currently executing thread is placed at the rear of the |
---|
| 67 | * FIFO for this priority and a new heir is selected. |
---|
| 68 | */ |
---|
[6eba7c85] | 69 | _Scheduler_Yield( executing ); |
---|
[05df0a8] | 70 | executing->cpu_time_budget = _Thread_Ticks_per_timeslice; |
---|
| 71 | } |
---|
| 72 | break; |
---|
| 73 | |
---|
[442eac69] | 74 | #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) |
---|
| 75 | case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT: |
---|
| 76 | if ( --executing->cpu_time_budget == 0 ) |
---|
| 77 | (*executing->budget_callout)( executing ); |
---|
| 78 | break; |
---|
| 79 | #endif |
---|
[05df0a8] | 80 | } |
---|
| 81 | } |
---|
[a344308] | 82 | |
---|
| 83 | void _Scheduler_default_Tick( void ) |
---|
| 84 | { |
---|
| 85 | uint32_t processor_count = _SMP_Get_processor_count(); |
---|
| 86 | uint32_t processor; |
---|
| 87 | |
---|
| 88 | for ( processor = 0 ; processor < processor_count ; ++processor ) { |
---|
| 89 | _Scheduler_default_Tick_for_executing( |
---|
| 90 | _Per_CPU_Information[ processor ].executing |
---|
| 91 | ); |
---|
| 92 | } |
---|
| 93 | } |
---|