1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Default Scheduler At Tick Handler |
---|
5 | * |
---|
6 | * @ingroup ScoreScheduler |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2009. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/score/schedulerimpl.h> |
---|
23 | #include <rtems/score/threadimpl.h> |
---|
24 | #include <rtems/score/smp.h> |
---|
25 | |
---|
26 | static void _Scheduler_default_Tick_for_executing( Thread_Control *executing ) |
---|
27 | { |
---|
28 | #ifdef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
29 | /* |
---|
30 | * Increment the number of ticks this thread has been executing |
---|
31 | */ |
---|
32 | executing->cpu_time_used++; |
---|
33 | #endif |
---|
34 | |
---|
35 | /* |
---|
36 | * If the thread is not preemptible or is not ready, then |
---|
37 | * just return. |
---|
38 | */ |
---|
39 | |
---|
40 | if ( !executing->is_preemptible ) |
---|
41 | return; |
---|
42 | |
---|
43 | if ( !_States_Is_ready( executing->current_state ) ) |
---|
44 | return; |
---|
45 | |
---|
46 | /* |
---|
47 | * The cpu budget algorithm determines what happens next. |
---|
48 | */ |
---|
49 | |
---|
50 | switch ( executing->budget_algorithm ) { |
---|
51 | case THREAD_CPU_BUDGET_ALGORITHM_NONE: |
---|
52 | break; |
---|
53 | |
---|
54 | case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE: |
---|
55 | #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) |
---|
56 | case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: |
---|
57 | #endif |
---|
58 | if ( (int)(--executing->cpu_time_budget) <= 0 ) { |
---|
59 | |
---|
60 | /* |
---|
61 | * A yield performs the ready chain mechanics needed when |
---|
62 | * resetting a timeslice. If no other thread's are ready |
---|
63 | * at the priority of the currently executing thread, then the |
---|
64 | * executing thread's timeslice is reset. Otherwise, the |
---|
65 | * currently executing thread is placed at the rear of the |
---|
66 | * FIFO for this priority and a new heir is selected. |
---|
67 | */ |
---|
68 | _Scheduler_Yield( executing ); |
---|
69 | executing->cpu_time_budget = _Thread_Ticks_per_timeslice; |
---|
70 | } |
---|
71 | break; |
---|
72 | |
---|
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 |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | void _Scheduler_default_Tick( void ) |
---|
83 | { |
---|
84 | uint32_t processor_count = _SMP_Get_processor_count(); |
---|
85 | uint32_t processor; |
---|
86 | |
---|
87 | for ( processor = 0 ; processor < processor_count ; ++processor ) { |
---|
88 | const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( processor ); |
---|
89 | |
---|
90 | _Scheduler_default_Tick_for_executing( per_cpu->executing ); |
---|
91 | } |
---|
92 | } |
---|