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

4.115
Last change on this file since fc2ad63 was fc2ad63, checked in by Sebastian Huber <sebastian.huber@…>, on 08/12/13 at 08:59:40

smp: _Scheduler_simple_smp_Allocate_processor()

Rename _Scheduler_simple_smp_Allocate_processor() to
_Scheduler_SMP_Allocate_processor().

  • Property mode set to 100644
File size: 3.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.com/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/schedulersimpleimpl.h>
23#include <rtems/score/schedulersmpimpl.h>
24#include <rtems/score/wkspace.h>
25
26void _Scheduler_simple_smp_Initialize( void )
27{
28  Scheduler_SMP_Control *self =
29    _Workspace_Allocate_or_fatal_error( sizeof( *self ) );
30
31  _Chain_Initialize_empty( &self->ready[ 0 ] );
32  _Chain_Initialize_empty( &self->scheduled );
33
34  _Scheduler.information = self;
35}
36
37static void _Scheduler_simple_smp_Move_from_scheduled_to_ready(
38  Chain_Control *ready_chain,
39  Thread_Control *scheduled_to_ready
40)
41{
42  _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node );
43  _Scheduler_simple_Insert_priority_lifo( ready_chain, scheduled_to_ready );
44}
45
46static void _Scheduler_simple_smp_Move_from_ready_to_scheduled(
47  Chain_Control *scheduled_chain,
48  Thread_Control *ready_to_scheduled
49)
50{
51  _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node );
52  _Scheduler_simple_Insert_priority_fifo( scheduled_chain, ready_to_scheduled );
53}
54
55static void _Scheduler_simple_smp_Insert(
56  Chain_Control *chain,
57  Thread_Control *thread,
58  Chain_Node_order order
59)
60{
61  _Chain_Insert_ordered_unprotected( chain, &thread->Object.Node, order );
62}
63
64static void _Scheduler_simple_smp_Enqueue_ordered(
65  Thread_Control *thread,
66  Chain_Node_order order
67)
68{
69  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
70
71  /*
72   * The scheduled chain has exactly processor count nodes after
73   * initialization, thus the lowest priority scheduled thread exists.
74   */
75  Thread_Control *lowest_scheduled =
76    (Thread_Control *) _Chain_Last( &self->scheduled );
77
78  if ( ( *order )( &thread->Object.Node, &lowest_scheduled->Object.Node ) ) {
79    _Scheduler_SMP_Allocate_processor( thread, lowest_scheduled );
80
81    _Scheduler_simple_smp_Insert( &self->scheduled, thread, order );
82
83    _Scheduler_simple_smp_Move_from_scheduled_to_ready(
84      &self->ready[ 0 ],
85      lowest_scheduled
86    );
87  } else {
88    _Scheduler_simple_smp_Insert( &self->ready[ 0 ], thread, order );
89  }
90}
91
92void _Scheduler_simple_smp_Enqueue_priority_lifo( Thread_Control *thread )
93{
94  _Scheduler_simple_smp_Enqueue_ordered(
95    thread,
96    _Scheduler_simple_Insert_priority_lifo_order
97  );
98}
99
100void _Scheduler_simple_smp_Enqueue_priority_fifo( Thread_Control *thread )
101{
102  _Scheduler_simple_smp_Enqueue_ordered(
103    thread,
104    _Scheduler_simple_Insert_priority_fifo_order
105  );
106}
107
108void _Scheduler_simple_smp_Extract( Thread_Control *thread )
109{
110  Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
111
112  _Chain_Extract_unprotected( &thread->Object.Node );
113
114  if ( thread->is_scheduled ) {
115    Thread_Control *highest_ready =
116      (Thread_Control *) _Chain_First( &self->ready[ 0 ] );
117
118    _Scheduler_SMP_Allocate_processor( highest_ready, thread );
119
120    _Scheduler_simple_smp_Move_from_ready_to_scheduled(
121      &self->scheduled,
122      highest_ready
123    );
124  }
125}
126
127void _Scheduler_simple_smp_Yield( Thread_Control *thread )
128{
129  ISR_Level level;
130
131  _ISR_Disable( level );
132
133  _Scheduler_simple_smp_Extract( thread );
134  _Scheduler_simple_smp_Enqueue_priority_fifo( thread );
135
136  _ISR_Enable( level );
137}
138
139void _Scheduler_simple_smp_Schedule( Thread_Control *thread )
140{
141  ( void ) thread;
142}
Note: See TracBrowser for help on using the repository browser.