1) 找到bpf_prog_load得到的bpf-prog fd(里面包含了bpf程序的内核进行jit编译后的指令集) 2) 初始化bpf_link_perf(bpf程序和bpf performance event之间的桥梁) 3) bpf_link_create将bpf程序注入到kprobe/uprobe异常处理函数会执行的prog_array中 4) 使能perf_event_open_probe得到的performance event 我们主要关...
1) 找到bpf_prog_load得到的bpf-prog fd(里面包含了bpf程序的内核进行jit编译后的指令集) 2) 初始化bpf_link_perf(bpf程序和bpf performance event之间的桥梁) 3) bpf_link_create将bpf程序注入到kprobe/uprobe异常处理函数会执行的prog_array中 4) 使能perf_event_open_probe得到的performance event 我们主要关...
它具有可以传递给 libbpf API 函数的struct bpf_object *obj;。 它还具有maps、progs和links“部分”,可直接访问 BPF 映射和 BPF 代码中定义的程序(例如,handle_tpBPF 程序)。 这些引用可以直接传递给 libbpf API,以使用 BPF map/program/link 做一些额外的事情。 Skeleton 还可以选择包含bss、data和rodata部分...
};staticstructbpf_program*bpf_progs[NR_BPF_PROGS]={};staticstructbpf_link*bpf_prog_links[NR_BPF_PROGS]={};staticconstintNR_MAPS=2;staticconstchar*map_names[NR_MAPS]={"kstack_map","ustack_map"};staticintmap_fds[NR_MAPS]={};voidprint_ksym(__u64addr){structksym*sym;if(!addr)return...
staticinterr=0;static struct bpf_object*obj=NULL;static constintNR_BPF_PROGS=1;static constchar*bpf_prog_names[NR_BPF_PROGS]={"bpg_open",};static struct bpf_program*bpf_progs[NR_BPF_PROGS]={};static struct bpf_link*bpf_prog_links[NR_BPF_PROGS]={};static constintNR_MAPS=2;static co...
staticintattach_raw_tp(conststructbpf_program*prog,longcookie,structbpf_link**link){/* ...省略... */*link=bpf_program__attach_raw_tracepoint(prog,tp_name);returnlibbpf_get_error(link);} bpf_program__attach_raw_tracepoint调用bpf_raw_tracepoint_open ...
bpftool link list 显示所有激活的链接,除了显示功能外,还支持其它功能,可以通过man bpftool link来查看具体支持的功能。 bpftool perf list 显示系统里所有raw_tracepoint, tracepoint, kprobe attachments ,除了显示功能外,还支持其它功能,可以通过man bpftool perf来查看具体支持的功能。
#include<stdlib.h>#include<unistd.h>#include<string.h>#include<signal.h>#include<time.h>#include<assert.h>#include<errno.h>#include<sys/resource.h>#include<linux/if_link.h>#include<linux/limits.h>#include<bpf/libbpf.h>#include"trace.skel.h"#defineBPF_SYSFS_ROOT"/sys/fs/bpf"enum{ ...
变量HOSTLOADLIBES是用于链接(link)操作时指定的特殊选项,如上面代码中使用两个library(因为代码中使用了相关的函数),通过选项-l加到最终生成的可执行文件中: libelf,这个库用来管理elf格式的文件,bpf程序一般都会使用elf作为最终格式,因此需要加载这个library。
bpftool link list 显示所有激活的链接,除了显示功能外,还支持其它功能,可以通过man bpftool link来查看具体支持的功能。 bpftool perf list 显示系统里所有raw_tracepoint, tracepoint, kprobe attachments ,除了显示功能外,还支持其它功能,可以通过man bpftool perf来查看具体支持的功能。