閱讀581 返回首頁    go 小米 go 小米5


看代碼不如看係統狀態

今天同事問我, linux的中斷可以嵌套嗎?
我說我也不知道啊, 印象中是cpu是可以中斷嵌套的, 但是linux關掉了, 所以linux是不允許中斷嵌套的, 如何證明, 找代碼, 突然跳到另一個領域, 哪有這麼快能找到, 看代碼不如看係統

直接開個vm, 把狀態停到中斷函數裏麵, 比如do_timer

Breakpoint 1, do_timer (ticks=1) at kernel/time/timekeeping.c:1604
1604    {
(gdb) bt
#0  do_timer (ticks=1) at kernel/time/timekeeping.c:1604
#1  0xffffffff810da0bf in tick_do_update_jiffies64 (now=..., now@entry=...) at kernel/time/tick-sched.c:83
#2  0xffffffff810da191 in tick_sched_do_timer (now=now@entry=...) at kernel/time/tick-sched.c:131
#3  0xffffffff810da6e3 in tick_sched_timer (timer=timer@entry=0xffff88003fd0df40) at kernel/time/tick-sched.c:1047
#4  0xffffffff810a18e5 in __run_hrtimer (cpu_base=cpu_base@entry=0xffff88003fd0d920, base=base@entry=0xffff88003fd0d960, timer=0xffff88003fd0df40, now=now@entry=0xffff88003fd03ee0) at kernel/hrtimer.c:1218
#5  0xffffffff810a1a00 in __hrtimer_run_queues (cpu_base=cpu_base@entry=0xffff88003fd0d920, now=..., now@entry=...) at kernel/hrtimer.c:1272
#6  0xffffffff810a1dc9 in hrtimer_interrupt (dev=<optimized out>) at kernel/hrtimer.c:1306
#7  0xffffffff81048cdb in local_apic_timer_interrupt () at arch/x86/kernel/apic/apic.c:917
#8  0xffffffff81606d05 in smp_apic_timer_interrupt (regs=<optimized out>) at arch/x86/kernel/apic/apic.c:941
#9  <signal handler called>
#10 0xffffffffffffff10 in ?? ()
Cannot access memory at address 0x297
(gdb) info registers 
rax            0x15fe   5630
rbx            0xf583e  1005630
rcx            0xf4240  1000000
rdx            0xffffffff81927184       -2121109116
rsi            0x148a8f680      5514000000
rdi            0x1      1
rbp            0xffff88003fd03e48       0xffff88003fd03e48
rsp            0xffff88003fd03e38       0xffff88003fd03e38
r8             0x6      6
r9             0x2      2
r10            0x4b6    1206
r11            0x7      7
r12            0x148a90c7e      5514005630
r13            0xffff880035fcbba8       -131940489577560
r14            0xffff88003fd0d920       -131940324681440
r15            0xffff88003fd0d960       -131940324681376
rip            0xffffffff810d3a1f       0xffffffff810d3a1f <do_timer>
eflags         0x2      [ ]
cs             0x10     16
ss             0x18     24
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0

eflags 0x2 [ ] 中斷沒開, 可以再換個函數看一下, 看了一圈, 基本都沒開, 可以認為中斷是不能嵌套的

其實是真的不能嵌套的
https://github.com/torvalds/linux/commit/e58aa3d2d0cc01ad8d6f7f640a0670433f794922

最後更新:2017-04-01 17:58:18

  上一篇:go 每周回顧小技巧
  下一篇:go 重複執行太枯燥?web批量操作有高招!