《分会场1_陈松_使用eBPF开发设备驱动的探索_报告PPT.pdf》由会员分享,可在线阅读,更多相关《分会场1_陈松_使用eBPF开发设备驱动的探索_报告PPT.pdf(13页珍藏版)》请在三个皮匠报告上搜索。
1、使用eBPF开发设备驱动的探索第三届 eBPF开发者大会w w w.e b p f t r a v e l.c o m中 国 西 安麒麟软件 陈松1,我遇到的问题第三届 eBPF开发者大会w w w.e b p f t r a v e l.c o m中 国 西 安2,来自社区的灵感3,我的方案介绍4,后续的思考第 三 届 e B P F 开 发 者 大 会1,我遇到的问题借到了一块RX7900XTX显卡按照AMD的官网指导安装了rocm,其中包括amdgpu.ko运转的不错rocm-smi和radeontop都显示了正确的信息第 三 届 e B P F 开 发 者 大 会1,我遇到的问题编译安
2、装一个自己的内核,dkms报错调整了内核版本,modprobe仍然报错第 三 届 e B P F 开 发 者 大 会1,我遇到的问题driver/gpio/TODO驱动的兼容性问题:结构的定义在不同版本中,会有元素的增加,删除或者重命名函数的定义也会有参数的变化,重命名,或者消失模块安装时由于vermagic不同导致的安装失败第 三 届 e B P F 开 发 者 大 会2,来自社区的灵感https:/www.kernel.org/doc/html/next/scheduler/sched-ext.htmlhttps:/ 三 届 e B P F 开 发 者 大 会2,来自社区的灵感通过stru
3、ct_ops挂载在函数的kprobe上挂载在trace event上第 三 届 e B P F 开 发 者 大 会3,我的方案介绍方案包含两部分:内核驱动的框架,eBPF驱动在内核框架中定义一组回调函数,在eBPF程序中实现这组回调函数以struct_ops为桥梁,将eBPF的实现注入到内核驱动模块中第 三 届 e B P F 开 发 者 大 会3,我的方案介绍1,struct chr_ext_ops unsigned long(*cust_read)(char*buf);unsigned int(*cust_write)(const char*buf);unsigned int(*cust_
4、open)(void);void(*cust_close)(void);char nameCHR_EXT_NAME_LEN;一组函数指针,在内核中定义,在ebpf代码中实现。static struct chr_ext_ops cust_chr_ext_ops;保存ebpf传递过来的函数指针,也就是ebpf驱动的行为逻辑。2,static struct bpf_struct_ops bpf_chr_ext_ops=.verifier_ops=&ext_verifier_ops,.reg=ext_reg,.unreg=ext_unreg,.check_member=ext_check_member
5、,.init_member=ext_init_member,.init=ext_init,.;bpf_struct_ops是内核与ebpf程序的桥梁,帮助ebpf中实现的chr_ext_ops 传递到内核中。ret=register_bpf_struct_ops(&bpf_chr_ext_ops,chr_ext_ops);在该模块初始化时注册到ebpf的内核管理器中3,ebpf内核程序实现具体逻辑void BPF_PROG(cust_open_demo)void BPF_PROG(cust_open_demo)unsigned int BPF_PROG(cust_write_demo,cons
6、t char*buf)unsigned int BPF_PROG(cust_read_demo,char*buf).同时,将该些函数指针放到一个struct chr_ext_ops结构体中:SEC(.struct_ops.link)struct chr_ext_ops chr_ext_demo_ops=.cust_open =(void*)cust_open_demo,.cust_close=(void*)cust_close_demo,.cust_read =(void*)cust_read_demo,.cust_write =(void*)cust_