source: rtems-docs/porting/code_tuning.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

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