source: rtems/cpukit/score/src/schedulersimplesmp.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Simple SMP Scheduler Implementation
5 *
6 * @ingroup ScoreSchedulerSMP
7 */
8
9/*
10 * Copyright (c) 2013 embedded brains GmbH.
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include <rtems/score/schedulersimplesmp.h>
22#include <rtems/score/schedulersmpimpl.h>
23#include <rtems/score/wkspace.h>
24
25void _Scheduler_simple_smp_Initialize( void )
26{
27  Scheduler_SMP_Control *self =
28    _Workspace_Allocate_or_fatal_error( sizeof( *self ) );
29
30  _Chain_Initialize_empty( &self->ready[ 0 ] );
31  _Chain_Initialize_empty( &self->scheduled );
32
33  _Scheduler.information = self;
34}
35
36static Thread_Control *_Scheduler_simple_smp_Get_highest_ready(
37  Scheduler_SMP_Control *self
38)
39{
40  Thread_Control *highest_ready = NULL;
41  Chain_Control *ready = &self->ready[ 0 ];
42
43  if ( !_Chain_Is_empty( ready ) ) {
44    highest_ready = (Thread_Control *) _Chain_First( ready );
45  }
46
47  return highest_ready;
48}
49
50static void _Scheduler_simple_smp_Move_from_scheduled_to_ready(
51  Scheduler_SMP_Control *self,
52  Thread_Control *scheduled_to_ready
53)
54{
55  _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node );
56  _Scheduler_simple_Insert_priority_lifo(
57    &self->ready[ 0 ],
58    scheduled_to_ready
59  );
60}
61
62static void _Scheduler_simple_smp_Move_from_ready_to_scheduled(
63  Scheduler_SMP_Control *self,
64  Thread_Control *ready_to_scheduled
65)
66{
67  _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node );
68  _Scheduler_simple_Insert_priority_fifo(
69    &self->scheduled,
70    ready_to_scheduled
71  );
72}
73
74static void _Scheduler_simple_smp_Insert_ready_lifo(
75  Scheduler_SMP_Control *self,
76  Thread_Control *thread
77)
78{
79  _Chain_Insert_ordered_unprotected(
80    &self->ready[ 0 ],
81    &thread->Object.Node,
82    _Scheduler_simple_Insert_priority_lifo_order
83  );
84}
85
86static void _Scheduler_simple_smp_Insert_ready_fifo(
87  Scheduler_SMP_Control *self,
88  Thread_Control *thread
89)
90{
91  _Chain_Insert_ordered_unprotected(
92    &self->ready[ 0 ],
93    &thread->Object.Node,
94    _Scheduler_simple_Insert_priority_fifo_order
95  );
96}
97
98static void _Scheduler_simple_smp_Do_extract(
99  Scheduler_SMP_Control *self,
100  Thread_Control *thread
101)
102{
103  ( void ) self;
104
105  thread->is_in_the_air = thread->is_scheduled;
106  thread->is_scheduled = false;
107
108  _Chain_Extract_unprotected( &thread->Object.Node );
109}
110
111void _Scheduler_simple_smp_Block( Thread_Control *thread )
112{
113  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
114
115  _Scheduler_SMP_Block(
116    self,
117    thread,
118    _Scheduler_simple_smp_Do_extract,
119    _Scheduler_simple_smp_Get_highest_ready,
120    _Scheduler_simple_smp_Move_from_ready_to_scheduled
121  );
122}
123
124static void _Scheduler_simple_smp_Enqueue_ordered(
125  Scheduler_SMP_Control *self,
126  Thread_Control *thread,
127  Chain_Node_order order,
128  Scheduler_SMP_Insert insert_ready,
129  Scheduler_SMP_Insert insert_scheduled
130)
131{
132  _Scheduler_SMP_Enqueue_ordered(
133    self,
134    thread,
135    order,
136    _Scheduler_simple_smp_Get_highest_ready,
137    insert_ready,
138    insert_scheduled,
139    _Scheduler_simple_smp_Move_from_ready_to_scheduled,
140    _Scheduler_simple_smp_Move_from_scheduled_to_ready
141  );
142}
143
144void _Scheduler_simple_smp_Enqueue_priority_lifo( Thread_Control *thread )
145{
146  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
147
148  _Scheduler_simple_smp_Enqueue_ordered(
149    self,
150    thread,
151    _Scheduler_simple_Insert_priority_lifo_order,
152    _Scheduler_simple_smp_Insert_ready_lifo,
153    _Scheduler_SMP_Insert_scheduled_lifo
154  );
155}
156
157void _Scheduler_simple_smp_Enqueue_priority_fifo( Thread_Control *thread )
158{
159  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
160
161  _Scheduler_simple_smp_Enqueue_ordered(
162    self,
163    thread,
164    _Scheduler_simple_Insert_priority_fifo_order,
165    _Scheduler_simple_smp_Insert_ready_fifo,
166    _Scheduler_SMP_Insert_scheduled_fifo
167  );
168}
169
170void _Scheduler_simple_smp_Extract( Thread_Control *thread )
171{
172  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
173
174  _Scheduler_SMP_Extract(
175    self,
176    thread,
177    _Scheduler_simple_smp_Do_extract
178  );
179}
180
181void _Scheduler_simple_smp_Yield( Thread_Control *thread )
182{
183  ISR_Level level;
184
185  _ISR_Disable( level );
186
187  _Scheduler_simple_smp_Extract( thread );
188  _Scheduler_simple_smp_Enqueue_priority_fifo( thread );
189
190  _ISR_Enable( level );
191}
192
193void _Scheduler_simple_smp_Schedule( Thread_Control *thread )
194{
195  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
196
197  _Scheduler_SMP_Schedule(
198    self,
199    thread,
200    _Scheduler_simple_smp_Get_highest_ready,
201    _Scheduler_simple_smp_Move_from_ready_to_scheduled
202  );
203}
Note: See TracBrowser for help on using the repository browser.