【问题标题】:How I can include the /kernel/sched/* into a BPF program?如何将 /kernel/sched/* 包含到 BPF 程序中?
【发布时间】:2020-07-25 00:17:23
【问题描述】:

根据 BPF Performance Tools 一书,我正在尝试在 Linux 中使用 bpftrace 制作自定义 bpf 程序。我试图从路径 linux/kernel/sched/sched.h 中包含一些文件。我怎样才能包括它们? (不仅是 /include 文件夹,还来自 Linux 中的 linux/kernel/* 文件夹?)

我正在尝试合并#include /kernel/sched/sched.h 以使用“struct rq”。

我的程序示例是:

#!/usr/local/bin/bpftrace

#include <kernel/sched/sched.h>

kprobe:load_balance
{
     $rq = (struct rq *)arg1;
     printf("-------------------\n");
     printf("\n");
     printf("load_balance: %s pid: %d\n", comm, pid);
     printf("-------------------\n");
}

【问题讨论】:

    标签: linux linux-kernel bpf ebpf kprobe


    【解决方案1】:

    该标头未公开,因此如果您想使用它或其任何字段,您必须在自己的程序中复制 rq 结构定义。

    这种定义副本已经存在于 bpftrace 的示例中,例如 struct cfs_rq_partial

    【讨论】:

    • 谢谢!但是有没有办法使用路径 '/kernel/sched/sched.h' 以便在我的 BPF 程序中使用 sched.h 中的 'struct rq'?
    • 基本上,我想动态(kprobe)使用函数(load_balance)并使用这个函数的所有参数(arg0,arg1,arg2 ...)。这个函数的原型是:static int load_balance(int this_cpu, struct *this_rq, struct sched_domain *sd, emum cpu_idle_type idle, int *continue_balancing)
    • 啊,对不起。我在那里读得太快了。我已经更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多