source: rtems-docs/c-user/config/intro.rst @ 88dd013

5
Last change on this file since 88dd013 was a526872, checked in by Sebastian Huber <sebastian.huber@…>, on 03/08/20 at 17:19:42

c-user: Split up configuring_a_system.rst

Introduce an index file for this chapter. This helps to generate some
sections from the specification in the future. Start with moving
"Introduction" up to "Unlimited Objects" to a new file.

Update #3836.

  • Property mode set to 100644
File size: 16.3 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR)
4
5Introduction
6============
7
8RTEMS must be configured for an application.  This configuration encompasses a
9variety of information including the length of each clock tick, the maximum
10number of each information RTEMS object that can be created, the application
11initialization tasks, the task scheduling algorithm to be used, and the device
12drivers in the application.
13
14Although this information is contained in data structures that are used by
15RTEMS at system initialization time, the data structures themselves must not be
16generated by hand. RTEMS provides a set of macros system which provides a
17simple standard mechanism to automate the generation of these structures.
18
19.. index:: confdefs.h
20.. index:: <rtems/confdefs.h>
21
22The RTEMS header file ``<rtems/confdefs.h>`` is at the core of the automatic
23generation of system configuration. It is based on the idea of setting macros
24which define configuration parameters of interest to the application and
25defaulting or calculating all others. This variety of macros can automatically
26produce all of the configuration data required for an RTEMS application.
27
28.. sidebar: Trivia:
29
30  The term ``confdefs`` is shorthand for a *Configuration Defaults*.
31
32As a general rule, application developers only specify values for the
33configuration parameters of interest to them. They define what resources or
34features they require. In most cases, when a parameter is not specified, it
35defaults to zero (0) instances, a standards compliant value, or disabled as
36appropriate. For example, by default there will be 256 task priority levels but
37this can be lowered by the application. This number of priority levels is
38required to be compliant with the RTEID/ORKID standards upon which the Classic
39API is based. There are similar cases where the default is selected to be
40compliant with the POSIX standard.
41
42For each configuration parameter in the configuration tables, the macro
43corresponding to that field is discussed. The RTEMS Maintainers expect that all
44systems can be easily configured using the ``<rtems/confdefs.h>`` mechanism and
45that using this mechanism will avoid internal RTEMS configuration changes
46impacting applications.
47
48Default Value Selection Philosophy
49==================================
50
51The user should be aware that the defaults are intentionally set as low as
52possible.  By default, no application resources are configured.  The
53``<rtems/confdefs.h>`` file ensures that at least one application task or
54thread is configured and that at least one of the initialization task/thread
55tables is configured.
56
57.. _Sizing the RTEMS Workspace:
58
59Sizing the RTEMS Workspace
60==========================
61
62The RTEMS Workspace is a user-specified block of memory reserved for use by
63RTEMS.  The application should NOT modify this memory.  This area consists
64primarily of the RTEMS data structures whose exact size depends upon the values
65specified in the Configuration Table.  In addition, task stacks and floating
66point context areas are dynamically allocated from the RTEMS Workspace.
67
68The ``<rtems/confdefs.h>`` mechanism calculates the size of the RTEMS Workspace
69automatically.  It assumes that all tasks are floating point and that all will
70be allocated the minimum stack space.  This calculation includes the amount of
71memory that will be allocated for internal use by RTEMS. The automatic
72calculation may underestimate the workspace size truly needed by the
73application, in which case one can use the ``CONFIGURE_MEMORY_OVERHEAD`` macro
74to add a value to the estimate. See :ref:`Specify Memory Overhead` for more
75details.
76
77The memory area for the RTEMS Workspace is determined by the BSP.  In case the
78RTEMS Workspace is too large for the available memory, then a fatal run-time
79error occurs and the system terminates.
80
81The file ``<rtems/confdefs.h>`` will calculate the value of the
82``work_space_size`` parameter of the Configuration Table. There are many
83parameters the application developer can specify to help ``<rtems/confdefs.h>``
84in its calculations.  Correctly specifying the application requirements via
85parameters such as ``CONFIGURE_EXTRA_TASK_STACKS`` and
86``CONFIGURE_MAXIMUM_TASKS`` is critical for production software.
87
88For each class of objects, the allocation can operate in one of two ways.  The
89default way has an ceiling on the maximum number of object instances which can
90concurrently exist in the system. Memory for all instances of that object class
91is reserved at system initialization.  The second way allocates memory for an
92initial number of objects and increases the current allocation by a fixed
93increment when required. Both ways allocate space from inside the RTEMS
94Workspace.
95
96See :ref:`ConfigUnlimitedObjects` for more details about the second way, which
97allows for dynamic allocation of objects and therefore does not provide
98determinism.  This mode is useful mostly for when the number of objects cannot
99be determined ahead of time or when porting software for which you do not know
100the object requirements.
101
102The space needed for stacks and for RTEMS objects will vary from one version of
103RTEMS and from one target processor to another.  Therefore it is safest to use
104``<rtems/confdefs.h>`` and specify your application's requirements in terms of
105the numbers of objects and multiples of ``RTEMS_MINIMUM_STACK_SIZE``, as far as
106is possible. The automatic estimates of space required will in general change
107when:
108
109- a configuration parameter is changed,
110
111- task or interrupt stack sizes change,
112
113- the floating point attribute of a task changes,
114
115- task floating point attribute is altered,
116
117- RTEMS is upgraded, or
118
119- the target processor is changed.
120
121Failure to provide enough space in the RTEMS Workspace may result in fatal
122run-time errors terminating the system.
123
124Potential Issues with RTEMS Workspace Size Estimation
125=====================================================
126
127The ``<rtems/confdefs.h>`` file estimates the amount of memory required for the
128RTEMS Workspace.  This estimate is only as accurate as the information given to
129``<rtems/confdefs.h>`` and may be either too high or too low for a variety of
130reasons.  Some of the reasons that ``<rtems/confdefs.h>`` may reserve too much
131memory for RTEMS are:
132
133- All tasks/threads are assumed to be floating point.
134
135Conversely, there are many more reasons that the resource estimate could be too
136low:
137
138- Task/thread stacks greater than minimum size must be accounted for explicitly
139  by developer.
140
141- Memory for messages is not included.
142
143- Device driver requirements are not included.
144
145- Network stack requirements are not included.
146
147- Requirements for add-on libraries are not included.
148
149In general, ``<rtems/confdefs.h>`` is very accurate when given enough
150information.  However, it is quite easy to use a library and forget to account
151for its resources.
152
153Format to be followed for making changes in this file
154=====================================================
155
156MACRO NAME:
157  Should be alphanumeric. Can have '_' (underscore).
158
159DATA TYPE:
160  Please refer to all existing formats.
161
162RANGE:
163  The range depends on the Data Type of the macro.
164
165  - If the data type is of type task priority, then its value should be an
166    integer in the range of 1 to 255.
167
168  - If the data type is an integer, then it can have numbers, characters (in
169    case the value is defined using another macro) and arithmetic operations
170    (+, -, \*, /).
171
172  - If the data type is a function pointer the first character should be an
173    alphabet or an underscore. The rest of the string can be alphanumeric.
174
175  - If the data type is RTEMS Attributes or RTEMS Mode then the string should
176    be alphanumeric.
177
178  - If the data type is RTEMS NAME then the value should be an integer>=0 or
179    ``RTEMS_BUILD_NAME( 'U', 'I', '1', ' ' )``
180
181DEFAULT VALUE:
182  The default value should be in the following formats- Please note that the
183  '.' (full stop) is necessary.
184
185  - In case the value is not defined then: This is not defined by default.
186
187  - If we know the default value then: The default value is XXX.
188
189  - If the default value is BSP Specific then: This option is BSP specific.
190
191DESCRIPTION:
192  The description of the macro. (No specific format)
193
194NOTES:
195  Any further notes. (No specific format)
196
197Configuration Example
198=====================
199
200In the following example, the configuration information for a system with a
201single message queue, four (4) tasks, and a timeslice of fifty (50)
202milliseconds is as follows:
203
204.. code-block:: c
205
206    #include <bsp.h>
207    #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
208    #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
209    #define CONFIGURE_MICROSECONDS_PER_TICK   1000 /* 1 millisecond */
210    #define CONFIGURE_TICKS_PER_TIMESLICE       50 /* 50 milliseconds */
211    #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
212    #define CONFIGURE_MAXIMUM_TASKS 4
213    #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
214    #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
215               CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(20, sizeof(struct USER_MESSAGE))
216    #define CONFIGURE_INIT
217    #include <rtems/confdefs.h>
218
219In this example, only a few configuration parameters are specified. The impact
220of these are as follows:
221
222- The example specified ``CONFIGURE_RTEMS_INIT_TASK_TABLE`` but did not specify
223  any additional parameters. This results in a configuration of an application
224  which will begin execution of a single initialization task named ``Init``
225  which is non-preemptible and at priority one (1).
226
227- By specifying ``CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER``, this application
228  is configured to have a clock tick device driver. Without a clock tick device
229  driver, RTEMS has no way to know that time is passing and will be unable to
230  support delays and wall time. Further configuration details about time are
231  provided. Per ``CONFIGURE_MICROSECONDS_PER_TICK`` and
232  ``CONFIGURE_TICKS_PER_TIMESLICE``, the user specified they wanted a clock
233  tick to occur each millisecond, and that the length of a timeslice would be
234  fifty (50) milliseconds.
235
236- By specifying ``CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER``, the application
237  will include a console device driver. Although the console device driver may
238  support a combination of multiple serial ports and display and keyboard
239  combinations, it is only required to provide a single device named
240  ``/dev/console``. This device will be used for Standard Input, Output and
241  Error I/O Streams. Thus when ``CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER``
242  is specified, implicitly three (3) file descriptors are reserved for the
243  Standard I/O Streams and those file descriptors are associated with
244  ``/dev/console`` during initialization. All console devices are expected to
245  support the POSIX*termios* interface.
246
247- The example above specifies via ``CONFIGURE_MAXIMUM_TASKS`` that the
248  application requires a maximum of four (4) simultaneously existing Classic
249  API tasks. Similarly, by specifying ``CONFIGURE_MAXIMUM_MESSAGE_QUEUES``,
250  there may be a maximum of only one (1) concurrently existent Classic API
251  message queues.
252
253- The most surprising configuration parameter in this example is the use of
254  ``CONFIGURE_MESSAGE_BUFFER_MEMORY``. Message buffer memory is allocated from
255  the RTEMS Workspace and must be accounted for. In this example, the single
256  message queue will have up to twenty (20) messages of type ``struct
257  USER_MESSAGE``.
258
259- The ``CONFIGURE_INIT`` constant must be defined in order to make
260  ``<rtems/confdefs.h>`` instantiate the configuration data structures.  This
261  can only be defined in one source file per application that includes
262  ``<rtems/confdefs.h>`` or the symbol table will be instantiated multiple
263  times and linking errors produced.
264
265This example illustrates that parameters have default values. Among other
266things, the application implicitly used the following defaults:
267
268- All unspecified types of communications and synchronization objects in the
269  Classic and POSIX Threads API have maximums of zero (0).
270
271- The filesystem will be the default filesystem which is the In-Memory File
272  System (IMFS).
273
274- The application will have the default number of priority levels.
275
276- The minimum task stack size will be that recommended by RTEMS for the target
277  architecture.
278
279.. _ConfigUnlimitedObjects:
280
281Unlimited Objects
282=================
283
284In real-time embedded systems the RAM is normally a limited, critical resource
285and dynamic allocation is avoided as much as possible to ensure predictable,
286deterministic execution times. For such cases, see :ref:`Sizing the RTEMS
287Workspace` for an overview of how to tune the size of the workspace.
288Frequently when users are porting software to RTEMS the precise resource
289requirements of the software is unknown. In these situations users do not need
290to control the size of the workspace very tightly because they just want to get
291the new software to run; later they can tune the workspace size as needed.
292
293The following object classes in the Classic API can be configured in unlimited
294mode:
295
296- Barriers
297
298- Message Queues
299
300- Partitions
301
302- Periods
303
304- Ports
305
306- Regions
307
308- Semaphores
309
310- Tasks
311
312- Timers
313
314Additionally, the following object classes from the POSIX API can be configured
315in unlimited mode:
316
317- Keys -- :c:func:`pthread_key_create`
318
319- Key Value Pairs -- :c:func:`pthread_setspecific`
320
321- Message Queues -- :c:func:`mq_open`
322
323- Named Semaphores -- :c:func:`sem_open`
324
325- Shared Memory -- :c:func:`shm_open`
326
327- Threads -- :c:func:`pthread_create`
328
329- Timers -- :c:func:`timer_create`
330
331.. warning::
332
333    The following object classes can *not* be configured in unlimited mode:
334
335    - Drivers
336
337    - File Descriptors
338
339    - POSIX Queued Signals
340
341    - User Extensions
342
343Due to the memory requirements of unlimited objects it is strongly recommended
344to use them only in combination with the unified work areas. See :ref:`Separate
345or Unified Work Areas` for more information on unified work areas.
346
347The following example demonstrates how the two simple configuration defines for
348unlimited objects and unified works areas can replace many seperate
349configuration defines for supported object classes:
350
351.. code-block:: c
352
353    #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
354    #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
355    #define CONFIGURE_UNIFIED_WORK_AREAS
356    #define CONFIGURE_UNLIMITED_OBJECTS
357    #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
358    #define CONFIGURE_INIT
359    #include <rtems/confdefs.h>
360
361Users are cautioned that using unlimited objects is not recommended for
362production software unless the dynamic growth is absolutely required. It is
363generally considered a safer embedded systems programming practice to know the
364system limits rather than experience an out of memory error at an arbitrary and
365largely unpredictable time in the field.
366
367.. index:: rtems_resource_unlimited
368
369.. _ConfigUnlimitedObjectsClass:
370
371Unlimited Objects by Class
372--------------------------
373
374When the number of objects is not known ahead of time, RTEMS provides an
375auto-extending mode that can be enabled individually for each object type by
376using the macro ``rtems_resource_unlimited``. This takes a value as a
377parameter, and is used to set the object maximum number field in an API
378Configuration table. The value is an allocation unit size. When RTEMS is
379required to grow the object table it is grown by this size. The kernel will
380return the object memory back to the RTEMS Workspace when an object is
381destroyed. The kernel will only return an allocated block of objects to the
382RTEMS Workspace if at least half the allocation size of free objects remain
383allocated. RTEMS always keeps one allocation block of objects allocated. Here
384is an example of using ``rtems_resource_unlimited``:
385
386.. code-block:: c
387
388    #define CONFIGURE_MAXIMUM_TASKS rtems_resource_unlimited(5)
389
390.. index:: rtems_resource_is_unlimited
391.. index:: rtems_resource_maximum_per_allocation
392
393Object maximum specifications can be evaluated with the
394``rtems_resource_is_unlimited`` and``rtems_resource_maximum_per_allocation``
395macros.
396
397.. _ConfigUnlimitedObjectsDefault:
398
399Unlimited Objects by Default
400----------------------------
401
402To ease the burden of developers who are porting new software RTEMS also
403provides the capability to make all object classes listed above operate in
404unlimited mode in a simple manner. The application developer is only
405responsible for enabling unlimited objects
406(:ref:`CONFIGURE_UNLIMITED_OBJECTS`) and specifying the allocation size
407(:ref:`CONFIGURE_UNLIMITED_ALLOCATION_SIZE`).
408
409.. code-block:: c
410
411    #define CONFIGURE_UNLIMITED_OBJECTS
412    #define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 5
Note: See TracBrowser for help on using the repository browser.