source: rtems-docs/porting/code_tuning.rst @ 62d58f2

5
Last change on this file since 62d58f2 was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 6.0 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR)
4
5Code Tuning Parameters
6######################
7
8Inline Thread_Enable_dispatch
9=============================
10
11Should the calls to _Thread_Enable_dispatch be inlined?
12
13- If ``TRUE``, then they are inlined.
14
15- If ``FALSE``, then a subroutine call is made.
16
17Basically this is an example of the classic trade-off of size versus
18speed.  Inlining the call (TRUE) typically increases the size of RTEMS
19while speeding up the enabling of dispatching.
20
21[NOTE: In general, the _Thread_Dispatch_disable_level will only be 0 or 1
22unless you are in an interrupt handler and that interrupt handler invokes
23the executive.] When not inlined something calls _Thread_Enable_dispatch
24which in turns calls _Thread_Dispatch.  If the enable dispatch is inlined,
25then one subroutine call is avoided entirely.]
26
27.. code-block:: c
28
29    #define CPU_INLINE_ENABLE_DISPATCH       FALSE
30
31Inline Thread_queue_Enqueue_priority
32====================================
33
34Should the body of the search loops in _Thread_queue_Enqueue_priority be
35unrolled one time?  In unrolled each iteration of the loop examines two
36"nodes" on the chain being searched.  Otherwise, only one node is examined
37per iteration.
38
39- If ``TRUE``, then the loops are unrolled.
40 
41- If ``FALSE``, then the loops are not unrolled.
42
43The primary factor in making this decision is the cost of disabling and
44enabling interrupts (_ISR_Flash) versus the cost of rest of the body of
45the loop.  On some CPUs, the flash is more expensive than one iteration of
46the loop body.  In this case, it might be desirable to unroll the loop.
47It is important to note that on some CPUs, this code is the longest
48interrupt disable period in RTEMS.  So it is necessary to strike a balance
49when setting this parameter.
50
51.. code-block:: c
52
53    #define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
54
55Structure Alignment Optimization
56================================
57
58The following macro may be defined to the attribute setting used to force
59alignment of critical RTEMS structures.  On some processors it may make
60sense to have these aligned on tighter boundaries than the minimum
61requirements of the compiler in order to have as much of the critical data
62area as possible in a cache line.  This ensures that the first access of
63an element in that structure fetches most, if not all, of the data
64structure and places it in the data cache.  Modern CPUs often have cache
65lines of at least 16 bytes and thus a single access implicitly fetches
66some surrounding data and places that unreferenced data in the cache.
67Taking advantage of this allows RTEMS to essentially prefetch critical
68data elements.
69
70The placement of this macro in the declaration of the variables is based
71on the syntactically requirements of the GNU C "__attribute__" extension.
72For another toolset, the placement of this macro could be incorrect.  For
73example with GNU C, use the following definition of
74CPU_STRUCTURE_ALIGNMENT to force a structures to a 32 byte boundary.
75
76.. code-block:: c
77
78    #define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (32)))
79
80To benefit from using this, the data must be heavily used so it will stay
81in the cache and used frequently enough in the executive to justify
82turning this on.  NOTE:  Because of this, only the Priority Bit Map table
83currently uses this feature.
84
85The following illustrates how the CPU_STRUCTURE_ALIGNMENT is defined on
86ports which require no special alignment for optimized access to data
87structures:
88
89.. code-block:: c
90
91    #define CPU_STRUCTURE_ALIGNMENT
92
93Data Alignment Requirements
94===========================
95
96Data Element Alignment
97----------------------
98
99The CPU_ALIGNMENT macro should be set to the CPU's worst alignment
100requirement for data types on a byte boundary.  This is typically the
101alignment requirement for a C double. This alignment does not take into
102account the requirements for the stack.
103
104The following sets the CPU_ALIGNMENT macro to 8 which indicates that there
105is a basic C data type for this port which much be aligned to an 8 byte
106boundary.
107
108.. code-block:: c
109
110    #define CPU_ALIGNMENT              8
111
112Heap Element Alignment
113----------------------
114
115The CPU_HEAP_ALIGNMENT macro is set to indicate the byte alignment
116requirement for data allocated by the RTEMS Code Heap Handler.  This
117alignment requirement may be stricter than that for the data types
118alignment specified by CPU_ALIGNMENT.  It is common for the heap to follow
119the same alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is
120strict enough for the heap, then this should be set to CPU_ALIGNMENT. This
121macro is necessary to ensure that allocated memory is properly aligned for
122use by high level language routines.
123
124The following example illustrates how the CPU_HEAP_ALIGNMENT macro is set
125when the required alignment for elements from the heap is the same as the
126basic CPU alignment requirements.
127
128.. code-block:: c
129
130    #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
131
132NOTE:  This does not have to be a power of 2.  It does have to be greater
133or equal to than CPU_ALIGNMENT.
134
135Partition Element Alignment
136---------------------------
137
138The CPU_PARTITION_ALIGNMENT macro is set to indicate the byte alignment
139requirement for memory buffers allocated by the RTEMS Partition Manager
140that is part of the Classic API.  This alignment requirement may be
141stricter than that for the data types alignment specified by
142CPU_ALIGNMENT.  It is common for the partition to follow the same
143alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
144enough for the partition, then this should be set to CPU_ALIGNMENT.  This
145macro is necessary to ensure that allocated memory is properly aligned for
146use by high level language routines.
147
148The following example illustrates how the CPU_PARTITION_ALIGNMENT macro is
149set when the required alignment for elements from the RTEMS Partition
150Manager is the same as the basic CPU alignment requirements.
151
152.. code-block:: c
153
154    #define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
155
156NOTE:  This does not have to be a power of 2.  It does have to be greater
157or equal to than CPU_ALIGNMENT.
Note: See TracBrowser for help on using the repository browser.