在中断处理程序获取被中断任务的调用堆栈

时间:2018-06-17 00:42:28

标签: linux linux-device-driver callstack

我正在LKM中编写PCI设备驱动程序。在PCI中断处理程序中,我想访问和/或打印中断任务的堆栈帧。我应该调用哪些函数来获取堆栈指针和堆栈帧?

1 个答案:

答案 0 :(得分:0)

它将显示中断处理程序调用堆栈的转储堆栈:

类似这样的东西:

[ 1002.364770] [c0000000050a8740] [c0000000000157c0] .show_stack+0x130/0x200 (unreliable)
[ 1002.364872] [c0000000050a8810] [c00000000082f6d0] .dump_stack+0x28/0x3c
[ 1002.364955] [c0000000050a8880] [c000000000010b98] .do_IRQ+0x2b8/0x2c0
[ 1002.365039] [c0000000050a8930] [c0000000000026d4] hardware_interrupt_common+0x154/0x180
[ 1002.365148] --- Exception: 501 at .cp_start_xmit+0x3a4/0x820 [8139cp]
[ 1002.365148] LR = .cp_start_xmit+0x390/0x820 [8139cp]
[ 1002.365359] [c0000000050a8d40] [c0000000006d7f14] .dev_hard_start_xmit+0x394/0x640
[ 1002.365433] [c0000000050a8e00] [c0000000007028c0] .sch_direct_xmit+0x110/0x260
[ 1002.365499] [c0000000050a8ea0] [c0000000006d8420] .dev_queue_xmit+0x260/0x630
[ 1002.365571] [c0000000050a8f40] [d0000000027d30d4] .br_dev_queue_push_xmit+0xc4/0x130 [bridge]
[ 1002.365641] [c0000000050a8fc0] [d0000000027d01f8] .br_dev_xmit+0x198/0x270 [bridge]
[ 1002.365707] [c0000000050a9070] [c0000000006d7f14] .dev_hard_start_xmit+0x394/0x640
[ 1002.365774] [c0000000050a9130] [c0000000006d85e8] .dev_queue_xmit+0x428/0x630
[ 1002.365834] [c0000000050a91d0] [c000000000729764] .ip_finish_output+0x2a4/0x550
[ 1002.365902] [c0000000050a9290] [c00000000072aaf0] .ip_local_out+0x50/0x70
[ 1002.365960] [c0000000050a9310] [c00000000072aed8] .ip_queue_xmit+0x148/0x420
[ 1002.366018] [c0000000050a93b0] [c000000000749524] .tcp_transmit_skb+0x4e4/0xaf0
[ 1002.366085] [c0000000050a94a0] [c00000000073de9c] .__tcp_ack_snd_check+0x7c/0xf0
[ 1002.366152] [c0000000050a9520] [c0000000007451d8] .tcp_rcv_established+0x1e8/0x930
[ 1002.366217] [c0000000050a95f0] [c00000000075326c] .tcp_v4_do_rcv+0x21c/0x570
[ 1002.366274] [c0000000050a96c0] [c000000000754a44] .tcp_v4_rcv+0x734/0x930
[ 1002.366332] [c0000000050a97a0] [c000000000724144] .ip_local_deliver_finish+0x184/0x360
[ 1002.366398] [c0000000050a9840] [c000000000724468] .ip_rcv_finish+0x148/0x400
[ 1002.366457] [c0000000050a98d0] [c0000000006d3248] .__netif_receive_skb_core+0x4f8/0xb00
[ 1002.366523] [c0000000050a99d0] [c0000000006d5414] .netif_receive_skb+0x44/0x110

您可以使用systemtap来检查正在运行的模块的回溯:

示例:

global time

global seq;

probe module("llt").function("llt_msg_recv"){
                print("-------------------------------\n")
                print("LLT_MSG_RECV\n");
                print_backtrace()
                print("-------------------------------\n")
}

probe kernel.function("netif_rx")
{
    netdev = $skb->dev
    dev_name = get_netdev_name(netdev)
    protocol = $skb->protocol
    printf("[dev_name: %s, protocol: %d, length: %d, truesize: %d]\n", dev_name, protocol, length, truesize)
    print_backtrace()
    print("---------------------------------------\n")

}

probe kernel.function("napi_gro_receive")
{
        print("------------------------------------\n")
        print_backtrace()
        print("------------------------------------\n")
}

因此,我们有一个udp内核挂钩来读取数据LLT_UDP_RECV。 相应的bactrace将显示如下。

LLT_MSG_RECV
 0xffffffffa0e65070 : llt_msg_recv+0x0/0x3f0 [llt]
 0xffffffffa0e5b6ea : llt_udp_recv+0x41a/0x500 [llt]
 0xffffffff8146859c : sock_queue_rcv_skb+0x15c/0x1b0 [kernel]
 0xffffffff814dbd1f : __udp_queue_rcv_skb+0x4f/0x170 [kernel]
 0xffffffff814deeab : udp_queue_rcv_skb+0x2ab/0x390 [kernel]
 0xffffffff814df193 : __udp4_lib_rcv+0x203/0x9e0 [kernel]
 0xffffffff814df98a : udp_rcv+0x1a/0x20 [kernel]
 0xffffffff814b3d5d : ip_local_deliver_finish+0xdd/0x2d0 [kernel]
 0xffffffff814b3fe8 : ip_local_deliver+0x98/0xa0 [kernel]
 0xffffffff814b34ad : ip_rcv_finish+0x12d/0x440 [kernel]
 0xffffffff814b3a35 : ip_rcv+0x275/0x350 [kernel]
 0xffffffff81478401 : __netif_receive_skb+0x201/0x590 [kernel]
 0xffffffff8147c268 : netif_receive_skb+0x58/0x60 [kernel]
 0xffffffff8147c370 : napi_skb_finish+0x50/0x70 [kernel]
 0xffffffff8147c989 : napi_gro_receive+0x39/0x50 [kernel]
 0xffffffffa0d9ee74 [ib_ipoib]
-------------------------------
------------------------------------
 0xffffffff8147c950 : napi_gro_receive+0x0/0x50 [kernel]
 0xffffffffa0320f13 [tg3]

最后一个函数属于tg3驱动程序函数 tg_rx