1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/score/schedulersimplesmp.h> |
---|
18 | #include <rtems/score/smp.h> |
---|
19 | |
---|
20 | static void _Scheduler_simple_smp_Tick_helper( |
---|
21 | int cpu |
---|
22 | ) |
---|
23 | { |
---|
24 | Thread_Control *executing; |
---|
25 | ISR_Level level; |
---|
26 | |
---|
27 | executing = _Per_CPU_Information[cpu].executing; |
---|
28 | |
---|
29 | #ifdef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
30 | /* |
---|
31 | * Increment the number of ticks this thread has been executing |
---|
32 | */ |
---|
33 | executing->cpu_time_used++; |
---|
34 | #endif |
---|
35 | |
---|
36 | /* |
---|
37 | * If the thread is not preemptible or is not ready, then |
---|
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: |
---|
56 | #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) |
---|
57 | case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: |
---|
58 | #endif |
---|
59 | if ( (int)(--executing->cpu_time_budget) <= 0 ) { |
---|
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 | * |
---|
69 | * In the SMP case, we do the chain manipulation for every |
---|
70 | * CPU, then schedule after all CPUs have been evaluated. |
---|
71 | */ |
---|
72 | _ISR_Disable( level ); |
---|
73 | _Scheduler_simple_Ready_queue_requeue( &_Scheduler, executing ); |
---|
74 | _ISR_Enable( level ); |
---|
75 | |
---|
76 | executing->cpu_time_budget = _Thread_Ticks_per_timeslice; |
---|
77 | } |
---|
78 | break; |
---|
79 | |
---|
80 | #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) |
---|
81 | case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT: |
---|
82 | if ( --executing->cpu_time_budget == 0 ) |
---|
83 | (*executing->budget_callout)( executing ); |
---|
84 | break; |
---|
85 | #endif |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | void _Scheduler_simple_smp_Tick( void ) |
---|
90 | { |
---|
91 | uint32_t cpu; |
---|
92 | |
---|
93 | /* |
---|
94 | * Iterate over all cores, updating time slicing information |
---|
95 | * and logically performing a yield. Then perform a schedule |
---|
96 | * operation to account for all the changes. |
---|
97 | */ |
---|
98 | for ( cpu=0 ; cpu < _SMP_Processor_count ; cpu++ ) { |
---|
99 | _Scheduler_simple_smp_Tick_helper( cpu ); |
---|
100 | } |
---|
101 | _Scheduler_simple_smp_Schedule(); |
---|
102 | } |
---|