RTEMS Logo

RTEMS 4.6.1 On-Line Library


Code Tuning Parameters Structure Alignment Optimization

PREV UP NEXT Bookshelf RTEMS Porting Guide

9.3: Structure Alignment Optimization

The following macro may be defined to the attribute setting used to force alignment of critical RTEMS structures. On some processors it may make sense to have these aligned on tighter boundaries than the minimum requirements of the compiler in order to have as much of the critical data area as possible in a cache line. This ensures that the first access of an element in that structure fetches most, if not all, of the data structure and places it in the data cache. Modern CPUs often have cache lines of at least 16 bytes and thus a single access implicitly fetches some surrounding data and places that unreferenced data in the cache. Taking advantage of this allows RTEMS to essentially prefetch critical data elements.

The placement of this macro in the declaration of the variables is based on the syntactically requirements of the GNU C "__attribute__" extension. For another toolset, the placement of this macro could be incorrect. For example with GNU C, use the following definition of CPU_STRUCTURE_ALIGNMENT to force a structures to a 32 byte boundary.

#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (32)))

To benefit from using this, the data must be heavily used so it will stay in the cache and used frequently enough in the executive to justify turning this on. NOTE: Because of this, only the Priority Bit Map table currently uses this feature.

The following illustrates how the CPU_STRUCTURE_ALIGNMENT is defined on ports which require no special alignment for optimized access to data structures:

#define CPU_STRUCTURE_ALIGNMENT


PREV UP NEXT Bookshelf RTEMS Porting Guide

Copyright © 1988-2004 OAR Corporation