unaligned access on IA64
Posted on July 21, 2007 by etbe
I recently had some problems with unaligned access on IA64, messages about unaligned access were being logged via printk and I couldn’t determine the cause – or even how to track it down. To test what an unaligned access means (which wasn’t documented anywhere that a quick google search could find) I wrote the test program in the second half of this post. Below is the output of the test program which accesses an integer at various offsets. As you can see it’s addresses that are congruent to 5, 6, and 7 mod 8 that cause the errors. At the int is 4 bytes long it seems that the cause of an unaligned access error is an access to a data type that crosses an 8 byte boundary. So a pointer or long long would have to be aligned to an 8 byte boundary, an int has to be at an address that is congruent to 4 or less mod 8, and a character can be anywhere.
Also if the sysctl /proc/sys/kernel/ignore-unaligned-usertrap is set to 1 then these messages will be disabled. But you really don’t want to do that, such errors apparently cause a significant performance loss so you want to file bug reports against programs that do this.
# ./a.out
index: 0
index: 1
a.out(10393): unaligned access to 0x607fffffff34ee25, ip=0×4000000000000961
index: 2
a.out(10393): unaligned access to 0x607fffffff34ee26, ip=0×4000000000000961
index: 3
a.out(10393): unaligned access to 0x607fffffff34ee27, ip=0×4000000000000961
index: 4
index: 5
index: 6
index: 7
index: 8
index: 9
a.out(10393): unaligned access to 0x607fffffff34ee2d, ip=0×4000000000000961
index: 10
a.out(10393): unaligned access to 0x607fffffff34ee2e, ip=0×4000000000000961
index: 11
a.out(10393): unaligned access to 0x607fffffff34ee2f, ip=0×4000000000000961
index: 12
index: 13
Below is the test program I used:
#include
#include
void doit(int *foo)
{
int bar;
memcpy(&bar, foo, sizeof(bar));
if(*foo == 1234)
printf("test\n");
}
int main()
{
char buf[1024];
int i;
for(i=0; i {
printf("index: %d\n", i);
doit(&buf[i]);
sleep(1);
}
return 0;
}
This entry was posted in Linux. Bookmark the permalink.
HP Sponsors Computer Recycling
Ron Paul
3 Responses to unaligned access on IA64
Kurt Roeckx says:
July 21, 2007 at 8:49 am
There is a program called prctl on ia64 that can control what happens to the program. It’s useful to for instance let it generate an signal (SIGBUS?) so you can debug where it happens.
Kurt
ian says:
July 21, 2007 at 11:19 am
对此问题:
可参见:kernel/Documentation/unaligned-memory-access.txt
修改kernel.ignore-unaligned-usertrap=1,可消除打印,但程序性能受影响。
另外,可用prctl --unaligned=signal gdb program 调试该程序。
ur wiki is often useful for ia64 related things, see
阅读(3046) | 评论(0) | 转发(0) |