Back to home page

OSCL-LXR

 
 

    


0001 ================
0002 Memory alignment
0003 ================
0004 
0005 Too many problems popped up because of unnoticed misaligned memory access in
0006 kernel code lately.  Therefore the alignment fixup is now unconditionally
0007 configured in for SA11x0 based targets.  According to Alan Cox, this is a
0008 bad idea to configure it out, but Russell King has some good reasons for
0009 doing so on some f***ed up ARM architectures like the EBSA110.  However
0010 this is not the case on many design I'm aware of, like all SA11x0 based
0011 ones.
0012 
0013 Of course this is a bad idea to rely on the alignment trap to perform
0014 unaligned memory access in general.  If those access are predictable, you
0015 are better to use the macros provided by include/asm/unaligned.h.  The
0016 alignment trap can fixup misaligned access for the exception cases, but at
0017 a high performance cost.  It better be rare.
0018 
0019 Now for user space applications, it is possible to configure the alignment
0020 trap to SIGBUS any code performing unaligned access (good for debugging bad
0021 code), or even fixup the access by software like for kernel code.  The later
0022 mode isn't recommended for performance reasons (just think about the
0023 floating point emulation that works about the same way).  Fix your code
0024 instead!
0025 
0026 Please note that randomly changing the behaviour without good thought is
0027 real bad - it changes the behaviour of all unaligned instructions in user
0028 space, and might cause programs to fail unexpectedly.
0029 
0030 To change the alignment trap behavior, simply echo a number into
0031 /proc/cpu/alignment.  The number is made up from various bits:
0032 
0033 ===             ========================================================
0034 bit             behavior when set
0035 ===             ========================================================
0036 0               A user process performing an unaligned memory access
0037                 will cause the kernel to print a message indicating
0038                 process name, pid, pc, instruction, address, and the
0039                 fault code.
0040 
0041 1               The kernel will attempt to fix up the user process
0042                 performing the unaligned access.  This is of course
0043                 slow (think about the floating point emulator) and
0044                 not recommended for production use.
0045 
0046 2               The kernel will send a SIGBUS signal to the user process
0047                 performing the unaligned access.
0048 ===             ========================================================
0049 
0050 Note that not all combinations are supported - only values 0 through 5.
0051 (6 and 7 don't make sense).
0052 
0053 For example, the following will turn on the warnings, but without
0054 fixing up or sending SIGBUS signals::
0055 
0056         echo 1 > /proc/cpu/alignment
0057 
0058 You can also read the content of the same file to get statistical
0059 information on unaligned access occurrences plus the current mode of
0060 operation for user space code.
0061 
0062 
0063 Nicolas Pitre, Mar 13, 2001.  Modified Russell King, Nov 30, 2001.