1 | .. SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR) |
---|
4 | |
---|
5 | .. _ConfigurationSchedulersClustered: |
---|
6 | |
---|
7 | Clustered Scheduler Configuration |
---|
8 | ================================= |
---|
9 | |
---|
10 | This section describes configuration options related to clustered scheduling. |
---|
11 | A clustered scheduler configuration is optional. It is an advanced |
---|
12 | configuration area and only necessary in specific circumstances. |
---|
13 | |
---|
14 | Clustered scheduling helps to control the worst-case latencies in a |
---|
15 | multiprocessor system (SMP). The goal is to reduce the amount of shared state |
---|
16 | in the system and thus prevention of lock contention. Modern multiprocessor |
---|
17 | systems tend to have several layers of data and instruction caches. With |
---|
18 | clustered scheduling it is possible to honour the cache topology of a system |
---|
19 | and thus avoid expensive cache synchronization traffic. |
---|
20 | |
---|
21 | We have clustered scheduling in case the set of processors of a system is |
---|
22 | partitioned into non-empty pairwise-disjoint subsets. These subsets are called |
---|
23 | clusters. Clusters with a cardinality of one are partitions. Each cluster is |
---|
24 | owned by exactly one scheduler. |
---|
25 | |
---|
26 | In order to use clustered scheduling the application designer has to answer two |
---|
27 | questions. |
---|
28 | |
---|
29 | #. How is the set of processors partitioned into clusters? |
---|
30 | |
---|
31 | #. Which scheduler algorithm is used for which cluster? |
---|
32 | |
---|
33 | The schedulers are statically configured. |
---|
34 | |
---|
35 | Configuration Step 1 - Scheduler Algorithms |
---|
36 | ------------------------------------------- |
---|
37 | |
---|
38 | Firstly, the application must select which scheduling algorithms are available |
---|
39 | with the following defines |
---|
40 | |
---|
41 | - :ref:`CONFIGURE_SCHEDULER_EDF_SMP <CONFIGURE_SCHEDULER_EDF_SMP>`, |
---|
42 | |
---|
43 | - :ref:`CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP <CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP>`, |
---|
44 | |
---|
45 | - :ref:`CONFIGURE_SCHEDULER_PRIORITY_SMP <CONFIGURE_SCHEDULER_PRIORITY_SMP>`, and |
---|
46 | |
---|
47 | - :ref:`CONFIGURE_SCHEDULER_SIMPLE_SMP <CONFIGURE_SCHEDULER_SIMPLE_SMP>`. |
---|
48 | |
---|
49 | This is necessary to calculate the per-thread overhead introduced by the |
---|
50 | scheduler algorithms. After these definitions the configuration file must |
---|
51 | ``#include <rtems/scheduler.h>`` to have access to scheduler-specific |
---|
52 | configuration macros. |
---|
53 | |
---|
54 | It is possible to make more than one scheduler algorithm available to the |
---|
55 | application. For example a :ref:`Simple Priority SMP Scheduler |
---|
56 | <SchedulerSMPPrioritySimple>` could be used in a partition for low latency |
---|
57 | tasks in addition to an :ref:`EDF SMP Scheduler <SchedulerSMPEDF>` for a |
---|
58 | general-purpose cluster. Since the per-thread overhead depends on the |
---|
59 | scheduler algorithm only the scheduler algorithms used by the application |
---|
60 | should be configured. |
---|
61 | |
---|
62 | Configuration Step 2 - Schedulers |
---|
63 | --------------------------------- |
---|
64 | |
---|
65 | Each scheduler needs some data structures. Use the following macros to create |
---|
66 | the scheduler data structures for a particular scheduler identified in the |
---|
67 | configuration by ``name``. |
---|
68 | |
---|
69 | - ``RTEMS_SCHEDULER_EDF_SMP(name, max_cpu_count)``, |
---|
70 | |
---|
71 | - ``RTEMS_SCHEDULER_PRIORITY_AFFINITY_SMP(name, prio_count)``, |
---|
72 | |
---|
73 | - ``RTEMS_SCHEDULER_PRIORITY_SMP(name, prio_count)``, and |
---|
74 | |
---|
75 | - ``RTEMS_SCHEDULER_SIMPLE_SMP(name)``. |
---|
76 | |
---|
77 | The ``name`` parameter is used as part of a designator for scheduler-specific |
---|
78 | data structures, so the usual C/C++ designator rules apply. This ``name`` is |
---|
79 | not the scheduler object name. Additional parameters are scheduler-specific. |
---|
80 | |
---|
81 | .. _ConfigurationSchedulerTable: |
---|
82 | |
---|
83 | Configuration Step 3 - Scheduler Table |
---|
84 | -------------------------------------- |
---|
85 | |
---|
86 | The schedulers are registered in the system via the scheduler table. To |
---|
87 | populate the scheduler table define ``CONFIGURE_SCHEDULER_TABLE_ENTRIES`` to a |
---|
88 | list of the following scheduler table entry initializers |
---|
89 | |
---|
90 | - ``RTEMS_SCHEDULER_TABLE_EDF_SMP(name, obj_name)``, |
---|
91 | |
---|
92 | - ``RTEMS_SCHEDULER_TABLE_PRIORITY_AFFINITY_SMP(name, obj_name)``, |
---|
93 | |
---|
94 | - ``RTEMS_SCHEDULER_TABLE_PRIORITY_SMP(name, obj_name)``, and |
---|
95 | |
---|
96 | - ``RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(name, obj_name)``. |
---|
97 | |
---|
98 | The ``name`` parameter must correspond to the parameter defining the scheduler |
---|
99 | data structures of configuration step 2. The ``obj_name`` determines the |
---|
100 | scheduler object name and can be used in :ref:`rtems_scheduler_ident() |
---|
101 | <rtems_scheduler_ident>` to get the scheduler object identifier. The scheduler |
---|
102 | index is defined by the index of the scheduler table. It is a configuration |
---|
103 | error to add a scheduler multiple times to the scheduler table. |
---|
104 | |
---|
105 | Configuration Step 4 - Processor to Scheduler Assignment |
---|
106 | -------------------------------------------------------- |
---|
107 | |
---|
108 | The last step is to define which processor uses which scheduler. For this |
---|
109 | purpose a scheduler assignment table must be defined. The entry count of this |
---|
110 | table must be equal to the configured maximum processors |
---|
111 | (:ref:`CONFIGURE_MAXIMUM_PROCESSORS <CONFIGURE_MAXIMUM_PROCESSORS>`). A |
---|
112 | processor assignment to a scheduler can be optional or mandatory. The boot |
---|
113 | processor must have a scheduler assigned. In case the system needs more |
---|
114 | mandatory processors than available then a fatal run-time error will occur. To |
---|
115 | specify the scheduler assignments define |
---|
116 | ``CONFIGURE_SCHEDULER_ASSIGNMENTS`` to a list of |
---|
117 | |
---|
118 | - ``RTEMS_SCHEDULER_ASSIGN(scheduler_index, attr)`` and |
---|
119 | |
---|
120 | - ``RTEMS_SCHEDULER_ASSIGN_NO_SCHEDULER`` |
---|
121 | |
---|
122 | macros. The ``scheduler_index`` parameter must be a valid index into the |
---|
123 | scheduler table defined by configuration step 3. The ``attr`` parameter |
---|
124 | defines the scheduler assignment attributes. By default, a scheduler |
---|
125 | assignment to a processor is optional. For the scheduler assignment attribute |
---|
126 | use one of the mutually exclusive variants |
---|
127 | |
---|
128 | - ``RTEMS_SCHEDULER_ASSIGN_DEFAULT``, |
---|
129 | |
---|
130 | - ``RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY``, and |
---|
131 | |
---|
132 | - ``RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL``. |
---|
133 | |
---|
134 | It is possible to add/remove processors to/from schedulers at run-time, see |
---|
135 | :ref:`rtems_scheduler_add_processor() <rtems_scheduler_add_processor>` and |
---|
136 | :ref:`rtems_scheduler_remove_processor() <rtems_scheduler_remove_processor>`. |
---|
137 | |
---|
138 | Configuration Example |
---|
139 | --------------------- |
---|
140 | |
---|
141 | The following example shows a scheduler configuration for a hypothetical |
---|
142 | product using two chip variants. One variant has four processors which is used |
---|
143 | for the normal product line and another provides eight processors for the |
---|
144 | high-performance product line. The first processor performs hard-real time |
---|
145 | control of actuators and sensors. The second processor is not used by RTEMS at |
---|
146 | all and runs a Linux instance to provide a graphical user interface. The |
---|
147 | additional processors are used for a worker thread pool to perform data |
---|
148 | processing operations. |
---|
149 | |
---|
150 | The processors managed by RTEMS use two Deterministic Priority SMP schedulers |
---|
151 | capable of dealing with 256 priority levels. The scheduler with index zero has |
---|
152 | the name ``"IO "``. The scheduler with index one has the name ``"WORK"``. The |
---|
153 | scheduler assignments of the first, third and fourth processor are mandatory, |
---|
154 | so the system must have at least four processors, otherwise a fatal run-time |
---|
155 | error will occur during system startup. The processor assignments for the |
---|
156 | fifth up to the eighth processor are optional so that the same application can |
---|
157 | be used for the normal and high-performance product lines. The second |
---|
158 | processor has no scheduler assigned and runs Linux. A hypervisor will ensure |
---|
159 | that the two systems cannot interfere in an undesirable way. |
---|
160 | |
---|
161 | .. code-block:: c |
---|
162 | |
---|
163 | #define CONFIGURE_MAXIMUM_PROCESSORS 8 |
---|
164 | #define CONFIGURE_MAXIMUM_PRIORITY 255 |
---|
165 | |
---|
166 | /* Configuration Step 1 - Scheduler Algorithms */ |
---|
167 | #define CONFIGURE_SCHEDULER_PRIORITY_SMP |
---|
168 | #include <rtems/scheduler.h> |
---|
169 | |
---|
170 | /* Configuration Step 2 - Schedulers */ |
---|
171 | RTEMS_SCHEDULER_PRIORITY_SMP(io, CONFIGURE_MAXIMUM_PRIORITY + 1); |
---|
172 | RTEMS_SCHEDULER_PRIORITY_SMP(work, CONFIGURE_MAXIMUM_PRIORITY + 1); |
---|
173 | |
---|
174 | /* Configuration Step 3 - Scheduler Table */ |
---|
175 | #define CONFIGURE_SCHEDULER_TABLE_ENTRIES \ |
---|
176 | RTEMS_SCHEDULER_TABLE_PRIORITY_SMP( \ |
---|
177 | io, \ |
---|
178 | rtems_build_name('I', 'O', ' ', ' ') \ |
---|
179 | ), \ |
---|
180 | RTEMS_SCHEDULER_TABLE_PRIORITY_SMP( \ |
---|
181 | work, \ |
---|
182 | rtems_build_name('W', 'O', 'R', 'K') \ |
---|
183 | ) |
---|
184 | |
---|
185 | /* Configuration Step 4 - Processor to Scheduler Assignment */ |
---|
186 | #define CONFIGURE_SCHEDULER_ASSIGNMENTS \ |
---|
187 | RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \ |
---|
188 | RTEMS_SCHEDULER_ASSIGN_NO_SCHEDULER, \ |
---|
189 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \ |
---|
190 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \ |
---|
191 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \ |
---|
192 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \ |
---|
193 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \ |
---|
194 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL) |
---|
195 | |
---|
196 | Configuration Errors |
---|
197 | -------------------- |
---|
198 | |
---|
199 | In case one of the scheduler indices in ``CONFIGURE_SCHEDULER_ASSIGNMENTS`` |
---|
200 | is invalid a link-time error will occur with an undefined reference to |
---|
201 | ``RTEMS_SCHEDULER_INVALID_INDEX``. |
---|
202 | |
---|
203 | Some fatal errors may occur in case of scheduler configuration inconsistencies |
---|
204 | or a lack of processors on the system. The fatal source is |
---|
205 | ``RTEMS_FATAL_SOURCE_SMP``. |
---|
206 | |
---|
207 | - ``SMP_FATAL_BOOT_PROCESSOR_NOT_ASSIGNED_TO_SCHEDULER`` - the boot processor |
---|
208 | must have a scheduler assigned. |
---|
209 | |
---|
210 | - ``SMP_FATAL_MANDATORY_PROCESSOR_NOT_PRESENT`` - there exists a mandatory |
---|
211 | processor beyond the range of physically or virtually available processors. |
---|
212 | The processor demand must be reduced for this system. |
---|
213 | |
---|
214 | - ``SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED`` - the start of a mandatory |
---|
215 | processor failed during system initialization. The system may not have this |
---|
216 | processor at all or it could be a problem with a boot loader for example. |
---|
217 | Check the ``CONFIGURE_SCHEDULER_ASSIGNMENTS`` definition. |
---|
218 | |
---|
219 | - ``SMP_FATAL_MULTITASKING_START_ON_UNASSIGNED_PROCESSOR`` - it is not allowed |
---|
220 | to start multitasking on a processor with no scheduler assigned. |
---|