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.org/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 | #include <rtems/config.h> |
---|
26 | |
---|
27 | void _Scheduler_default_Tick( |
---|
28 | const Scheduler_Control *scheduler, |
---|
29 | Thread_Control *executing |
---|
30 | ) |
---|
31 | { |
---|
32 | #ifdef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
33 | /* |
---|
34 | * Increment the number of ticks this thread has been executing |
---|
35 | */ |
---|
36 | executing->cpu_time_used++; |
---|
37 | #endif |
---|
38 | |
---|
39 | /* |
---|
40 | * If the thread is not preemptible or is not ready, then |
---|
41 | * just return. |
---|
42 | */ |
---|
43 | |
---|
44 | if ( !executing->is_preemptible ) |
---|
45 | return; |
---|
46 | |
---|
47 | if ( !_States_Is_ready( executing->current_state ) ) |
---|
48 | return; |
---|
49 | |
---|
50 | /* |
---|
51 | * The cpu budget algorithm determines what happens next. |
---|
52 | */ |
---|
53 | |
---|
54 | switch ( executing->budget_algorithm ) { |
---|
55 | case THREAD_CPU_BUDGET_ALGORITHM_NONE: |
---|
56 | break; |
---|
57 | |
---|
58 | case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE: |
---|
59 | #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) |
---|
60 | case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: |
---|
61 | #endif |
---|
62 | if ( (int)(--executing->cpu_time_budget) <= 0 ) { |
---|
63 | |
---|
64 | /* |
---|
65 | * A yield performs the ready chain mechanics needed when |
---|
66 | * resetting a timeslice. If no other thread's are ready |
---|
67 | * at the priority of the currently executing thread, then the |
---|
68 | * executing thread's timeslice is reset. Otherwise, the |
---|
69 | * currently executing thread is placed at the rear of the |
---|
70 | * FIFO for this priority and a new heir is selected. |
---|
71 | */ |
---|
72 | _Scheduler_Yield( scheduler, executing ); |
---|
73 | executing->cpu_time_budget = |
---|
74 | rtems_configuration_get_ticks_per_timeslice(); |
---|
75 | } |
---|
76 | break; |
---|
77 | |
---|
78 | #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) |
---|
79 | case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT: |
---|
80 | if ( --executing->cpu_time_budget == 0 ) |
---|
81 | (*executing->budget_callout)( executing ); |
---|
82 | break; |
---|
83 | #endif |
---|
84 | } |
---|
85 | } |
---|