source: rtems/doc/porting/codetuning.t @ 0660b4f8

4.104.114.84.95
Last change on this file since 0660b4f8 was 0660b4f8, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 19:50:56

Changed copyright date to 1999.

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