- 論壇徽章:
- 0
|
內(nèi)核 版本 2.4
在時鐘中斷分析章節(jié)里面,跟蹤到do_timer函數(shù)后, 發(fā)現(xiàn)對jiffies 的自增采用了轉(zhuǎn)指針類型方式自增
void do_timer(struct pt_regs *regs)
{
(*(unsigned long *)&jiffies)++;
。。。。。。
}
linux內(nèi)核情景分析上說這個目的是 gcc會將這個語句 翻譯成一條對內(nèi)存單元的inc自增指令
這樣有利于保證原子性操作
但是我試了一下,發(fā)現(xiàn)還是 先把 jiffies mov到eax中,然后把eax 自增,然后通過mov到內(nèi)存單元里面去
是書上說錯了? 還是我驗(yàn)證的程序有問題
附上測試程序:
#include <stdio.h>
int main()
{
int i = 1;
(*(int*)&i)++;
printf("i = %d \n", i);
return (0);
}
gcc -S inc.c
cat inc.s
.file "inc.c"
.section .rodata
.LC0:
.string " i = %d \n"
.text
.globl main
.type main, @function
main:
.LFB2:
pushq %rbp
.LCFI0:
movq %rsp, %rbp
.LCFI1:
subq $16, %rsp
.LCFI2:
movl $1, -4(%rbp)
movl -4(%rbp), %eax
addl $1, %eax
movl %eax, -4(%rbp)
movl -4(%rbp), %esi
movl $.LC0, %edi
movl $0, %eax
call printf
movl $0, %eax
leave
ret
.LFE2:
麻煩大家指導(dǎo)一下。
謝謝
這個是針對2.4內(nèi)核的, 可能有點(diǎn)老 |
|