source: rtems/cpukit/score/include/rtems/score/scheduler.h @ f39f667a

4.115
Last change on this file since f39f667a was f39f667a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/14 at 11:50:48

score: Simplify _Thread_Change_priority()

The function to change a thread priority was too complex. Simplify it
with a new scheduler operation. This increases the average case
performance due to the simplified logic. The interrupt disabled
critical section is a bit prolonged since now the extract, update and
enqueue steps are executed atomically. This should however not impact
the worst-case interrupt latency since at least for the Deterministic
Priority Scheduler this sequence can be carried out with a wee bit of
instructions and no loops.

Add _Scheduler_Change_priority() to replace the sequence of

  • _Thread_Set_transient(),
  • _Scheduler_Extract(),
  • _Scheduler_Enqueue(), and
  • _Scheduler_Enqueue_first().

Delete STATES_TRANSIENT, _States_Is_transient() and
_Thread_Set_transient() since this state is now superfluous.

With this change it is possible to get rid of the
SCHEDULER_SMP_NODE_IN_THE_AIR state. This considerably simplifies the
implementation of the new SMP locking protocols.

  • Property mode set to 100644
File size: 8.7 KB
Line 
1/**
2 *  @file  rtems/score/scheduler.h
3 *
4 *  @brief Constants and Structures Associated with the Scheduler
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the scheduler.
8 */
9
10/*
11 *  Copyright (C) 2010 Gedare Bloom.
12 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_SCHEDULER_H
20#define _RTEMS_SCORE_SCHEDULER_H
21
22#include <rtems/score/percpu.h>
23#include <rtems/score/priority.h>
24#include <rtems/score/thread.h>
25#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
26  #include <sys/cpuset.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 *  @defgroup ScoreScheduler Scheduler Handler
35 *
36 *  @ingroup Score
37 *
38 *  This handler encapsulates functionality related to managing sets of threads
39 *  that are ready for execution.
40 */
41/**@{*/
42
43typedef struct Scheduler_Control Scheduler_Control;
44
45typedef struct Scheduler_Node Scheduler_Node;
46
47/**
48 * @brief The scheduler operations.
49 */
50typedef struct {
51  /** @see _Scheduler_Handler_initialization() */
52  void ( *initialize )( const Scheduler_Control * );
53
54  /** @see _Scheduler_Schedule() */
55  void ( *schedule )( const Scheduler_Control *, Thread_Control *);
56
57  /** @see _Scheduler_Yield() */
58  void ( *yield )( const Scheduler_Control *, Thread_Control *);
59
60  /** @see _Scheduler_Block() */
61  void ( *block )( const Scheduler_Control *, Thread_Control * );
62
63  /** @see _Scheduler_Unblock() */
64  void ( *unblock )( const Scheduler_Control *, Thread_Control * );
65
66  /** @see _Scheduler_Change_priority() */
67  void ( *change_priority )(
68    const Scheduler_Control *,
69    Thread_Control *,
70    Priority_Control,
71    bool
72  );
73
74  /** @see _Scheduler_Allocate() */
75  bool ( *allocate )( const Scheduler_Control *, Thread_Control * );
76
77  /** @see _Scheduler_Free() */
78  void ( *free )( const Scheduler_Control *, Thread_Control * );
79
80  /** @see _Scheduler_Update() */
81  void ( *update )( const Scheduler_Control *, Thread_Control * );
82
83  /** @see _Scheduler_Priority_compare() */
84  int ( *priority_compare )(
85    Priority_Control,
86    Priority_Control
87  );
88
89  /** @see _Scheduler_Release_job() */
90  void ( *release_job ) (
91    const Scheduler_Control *,
92    Thread_Control *,
93    uint32_t
94  );
95
96  /** @see _Scheduler_Tick() */
97  void ( *tick )( const Scheduler_Control *, Thread_Control * );
98
99  /** @see _Scheduler_Start_idle() */
100  void ( *start_idle )(
101    const Scheduler_Control *,
102    Thread_Control *,
103    Per_CPU_Control *
104  );
105
106#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
107  /** @see _Scheduler_Get_affinity() */
108  bool ( *get_affinity )(
109    const Scheduler_Control *,
110    Thread_Control *,
111    size_t,
112    cpu_set_t *
113  );
114 
115  /** @see _Scheduler_Set_affinity() */
116  bool ( *set_affinity )(
117    const Scheduler_Control *,
118    Thread_Control *,
119    size_t,
120    const cpu_set_t *
121  );
122#endif
123} Scheduler_Operations;
124
125/**
126 * @brief Scheduler context.
127 *
128 * The scheduler context of a particular scheduler implementation must place
129 * this structure at the begin of its context structure.
130 */
131typedef struct Scheduler_Context {
132#if defined(RTEMS_SMP)
133  /**
134   * @brief Count of processors owned by this scheduler instance.
135   */
136  uint32_t processor_count;
137#endif
138} Scheduler_Context;
139
140/**
141 * @brief Scheduler control.
142 */
143struct Scheduler_Control {
144  /**
145   * @brief Reference to a statically allocated scheduler context.
146   */
147  Scheduler_Context *context;
148
149  /**
150   * @brief The scheduler operations.
151   */
152  Scheduler_Operations Operations;
153
154  /**
155   * @brief The scheduler name.
156   */
157  uint32_t name;
158};
159
160/**
161 * @brief Scheduler node for per-thread data.
162 */
163struct Scheduler_Node {
164  /* No fields yet */
165};
166
167/**
168 * @brief Registered schedulers.
169 *
170 * Application provided via <rtems/confdefs.h>.
171 *
172 * @see _Scheduler_Count.
173 */
174extern const Scheduler_Control _Scheduler_Table[];
175
176/**
177 * @brief Count of registered schedulers.
178 *
179 * Application provided via <rtems/confdefs.h> on SMP configurations.
180 *
181 * It is very important that this is a compile-time constant on uni-processor
182 * configurations (in this case RTEMS_SMP is not defined) so that the compiler
183 * can optimize the some loops away
184 *
185 * @see _Scheduler_Table.
186 */
187#if defined(RTEMS_SMP)
188  extern const size_t _Scheduler_Count;
189#else
190  #define _Scheduler_Count ( (size_t) 1 )
191#endif
192
193#if defined(RTEMS_SMP)
194  /**
195   * @brief The scheduler assignment default attributes.
196   */
197  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
198
199  /**
200   * @brief The presence of this processor is optional.
201   */
202  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
203
204  /**
205   * @brief The presence of this processor is mandatory.
206   */
207  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
208
209  /**
210   * @brief Scheduler assignment.
211   */
212  typedef struct {
213    /**
214     * @brief The scheduler for this processor.
215     */
216    const Scheduler_Control *scheduler;
217
218    /**
219     * @brief The scheduler assignment attributes.
220     *
221     * Use @ref SCHEDULER_ASSIGN_DEFAULT to select default attributes.
222     *
223     * The presence of a processor can be
224     * - @ref SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL, or
225     * - @ref SCHEDULER_ASSIGN_PROCESSOR_MANDATORY.
226     */
227    uint32_t attributes;
228  } Scheduler_Assignment;
229
230  /**
231   * @brief The scheduler assignments.
232   *
233   * The length of this array must be equal to the maximum processors.
234   *
235   * Application provided via <rtems/confdefs.h>.
236   *
237   * @see _Scheduler_Table and rtems_configuration_get_maximum_processors().
238   */
239  extern const Scheduler_Assignment _Scheduler_Assignments[];
240#endif
241
242/**
243 * @brief Returns an arbitrary non-NULL value.
244 *
245 * @param[in] scheduler Unused.
246 * @param[in] the_thread Unused.
247 *
248 * @retval true Always.
249 */
250bool _Scheduler_default_Allocate(
251  const Scheduler_Control *scheduler,
252  Thread_Control          *the_thread
253);
254
255/**
256 * @brief Does nothing.
257 *
258 * @param[in] scheduler Unused.
259 * @param[in] the_thread Unused.
260 */
261void _Scheduler_default_Free(
262  const Scheduler_Control *scheduler,
263  Thread_Control          *the_thread
264);
265
266/**
267 * @brief Does nothing.
268 *
269 * @param[in] scheduler Unused.
270 * @param[in] the_thread Unused.
271 */
272void _Scheduler_default_Update(
273  const Scheduler_Control *scheduler,
274  Thread_Control          *the_thread
275);
276
277/**
278 * @brief Does nothing.
279 *
280 * @param[in] scheduler Unused.
281 * @param[in] the_thread Unused.
282 * @param[in] deadline Unused.
283 */
284void _Scheduler_default_Release_job(
285  const Scheduler_Control *scheduler,
286  Thread_Control          *the_thread,
287  uint32_t                 deadline
288);
289
290/**
291 * @brief Performs tick operations depending on the CPU budget algorithm for
292 * each executing thread.
293 *
294 * This routine is invoked as part of processing each clock tick.
295 *
296 * @param[in] scheduler The scheduler.
297 * @param[in] execution An executing thread.
298 */
299void _Scheduler_default_Tick(
300  const Scheduler_Control *scheduler,
301  Thread_Control          *executing
302);
303
304/**
305 * @brief Starts an idle thread.
306 *
307 * @param[in] scheduler The scheduler.
308 * @param[in] the_thread An idle thread.
309 * @param[in] cpu This parameter is unused.
310 */
311void _Scheduler_default_Start_idle(
312  const Scheduler_Control *scheduler,
313  Thread_Control          *the_thread,
314  Per_CPU_Control         *cpu
315);
316
317#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
318  /**
319   * @brief Get affinity for the default scheduler.
320   *
321   * @param[in] thread The associated thread.
322   * @param[in] cpusetsize The size of the cpuset.
323   * @param[out] cpuset Affinity set containing all CPUs.
324   *
325   * @retval 0 Successfully got cpuset
326   * @retval -1 The cpusetsize is invalid for the system
327   */
328  bool _Scheduler_default_Get_affinity(
329    const Scheduler_Control *scheduler,
330    Thread_Control          *thread,
331    size_t                   cpusetsize,
332    cpu_set_t               *cpuset
333  );
334
335  /**
336   * @brief Set affinity for the default scheduler.
337   *
338   * @param[in] thread The associated thread.
339   * @param[in] cpusetsize The size of the cpuset.
340   * @param[in] cpuset Affinity new affinity set.
341   *
342   * @retval 0 Successful
343   *
344   *  This method always returns successful and does not save
345   *  the cpuset.
346   */
347  bool _Scheduler_default_Set_affinity(
348    const Scheduler_Control *scheduler,
349    Thread_Control          *thread,
350    size_t                   cpusetsize,
351    const cpu_set_t         *cpuset
352  );
353#endif
354
355/**
356 * @brief Indicates if thread priority queues are broken with the configured
357 * scheduler or not.
358 *
359 * See also PR2174: Memory corruption with EDF scheduler and thread priority
360 * queues.
361 */
362extern const bool _Scheduler_FIXME_thread_priority_queues_are_broken;
363
364/**@}*/
365
366#ifdef __cplusplus
367}
368#endif
369
370#endif
371/* end of include file */
Note: See TracBrowser for help on using the repository browser.