Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
wniming
V2EX  ›  Linux

使用 bpf 在内核的某一个函数的开头加上一个 dump_stack()是否可以实现?

  •  
  •   wniming · Apr 10, 2023 · 2592 views
    This topic created in 1144 days ago, the information mentioned may be changed or developed.

    比如楼主现在可以通过 bpftrace 的以下用法得到某一个函数被调用的次数,但我还想知道每次的调用栈,懒得改代码重编译再重启,能不能自己写一个 bpf 程序实现这个需求?

    bpftrace -e 'kprobe:vgic_kick_vcpus { @[probe] = count() }'

    5 replies    2023-04-13 16:24:53 +08:00
    cfeitong
        1
    cfeitong  
       Apr 10, 2023 via Android
    不能。原因是 ebpf 无法读取用户态内存,自然也无法读取用户栈。
    wniming
        2
    wniming  
    OP
       Apr 10, 2023
    @cfeitong 感谢回复,我问的是关于内核态的函数,不是用户态。
    zpd2009
        3
    zpd2009  
       Apr 10, 2023
    @wniming 我了解到的是不行的。eBPF 可以干很多事情,但是限制也是很厉害的。没有看到有支持 dump 调用栈的函数。https://github.com/iovisor/bcc/blob/master/docs/kernel-versions.md
    fuzhuo233
        4
    fuzhuo233  
       Apr 11, 2023 via iPhone   ❤️ 1
    不是有 kstack/ustack 么,一把梭
    bpftrace -e 'kprobe:vgic_kick_vcpus { @[kstack] = count() }'
    zpd2009
        5
    zpd2009  
       Apr 13, 2023
    @zpd2009 尝试一下 bpf_get_task_stack ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3141 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:58 · PVG 21:58 · LAX 06:58 · JFK 09:58
    ♥ Do have faith in what you're doing.