Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ebpf support #912

Merged
merged 11 commits into from
Oct 19, 2024
Merged

Conversation

Godones
Copy link
Contributor

@Godones Godones commented Sep 4, 2024

  • 实现bpf()一部分命令,包括几种基本map,相关的helper函数
  • 实现部分perf相关的数据结构
  • 暂时为文件实现简单mmap
  • 实现一个使用kprobe统计syscall 调用次数的ebpf程序

对eBPF支持程度(基本):

  • 简单的eBPF程序(没有指定特殊的Map)
  • 使用内核已经实现的Map的eBPF程序
  • 可以和kprobe配合使用
  • 内核Map相关的接口定义已经实现,添加新的Map较为简单

不支持的功能:

  • 区分不同的eBPF程序类型(Network/Cgroup)并限定可调用的helper函数集
  • 与内核其它跟踪机制配合(tracepoint)
  • 其它helper和Map

todo

  • 修改mmap,需要讨论,因为这个和块缓存层相关
  • 添加文档
  • 修复可能的错误
  • 增加rbpf版本信息

add basic bpf map type.
add basic perf type.
update kprobe impl.
add user app example.
@github-actions github-actions bot added the enhancement New feature or request label Sep 4, 2024
@Godones
Copy link
Contributor Author

Godones commented Sep 4, 2024

@Chiichen @fslongjin 我重新整理了ebpf的提交代码,麻烦两位看看。

Copy link
Member

@Chiichen Chiichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Godones 简单描述下这个 PR 之后对 eBPF 的支持到了什么程度(基本/可用/完整支持),以及支持/不支持哪些功能

kernel/src/bpf/map/mod.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/mod.rs Outdated Show resolved Hide resolved
kernel/src/mm/ucontext.rs Show resolved Hide resolved
@fslongjin
Copy link
Member

最好能在内核文档里面写几个文档,描述你的设计&方案

@Chiichen
Copy link
Member

Chiichen commented Sep 6, 2024

@Godones 交流了一下,会在下次或者下下次社区会议上分享这个 PR 的工作内容,等会议结束后再合并一次主线(应该主要是文件映射那边有一些冲突要解决),再开始 review 这个 PR

@Chiichen
Copy link
Member

@Godones 已经合并了最新的主线,麻烦解决一下冲突,对齐一下主线的实现,我记得在mmap的实现那部分(ucontext)逻辑是有冲突的

@Godones
Copy link
Contributor Author

Godones commented Sep 13, 2024

@Godones 已经合并了最新的主线,麻烦解决一下冲突,对齐一下主线的实现,我记得在mmap的实现那部分(ucontext)逻辑是有冲突的

可以

@Godones
Copy link
Contributor Author

Godones commented Sep 13, 2024

@Chiichen 似乎合并主线后无法通过CI?

@Chiichen
Copy link
Member

@Chiichen 似乎合并主线后无法通过CI?

是的,我看应该是格式检查挂了,因为我在网页上解决的冲突,所以可能没有仔细去格式化,你就基于现有的分支代码解决冲突就可以了,应该格式化之后 ci 是不会挂的

@dragonosbot dragonosbot added A-fs Area: 文件系统 O-riscv64 Target: riscv64 O-x86_64 Target: x86_64 labels Sep 16, 2024
@Godones
Copy link
Contributor Author

Godones commented Sep 16, 2024

@Chiichen 新的修改中主要是适配当前主线的mmap实现,以及修复了一些错误。由于主线的mmap并不能完全适用于所有文件的实现,我在IndexNode添加了一个mmap, 向文件传递一些信息。

@Chiichen
Copy link
Member

@Jomocool 麻烦帮忙看看mmap相关的修改

@dragonosbot dragonosbot added the T-doc Relevant to the document team, which will review and decide on the PR/issue. label Sep 19, 2024
Copy link
Member

@Chiichen Chiichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大概看了一半,可以先看看,以及CI没过,看看是什么原因~?

kernel/src/bpf/map/array_map.rs Show resolved Hide resolved
kernel/src/bpf/map/hash_map.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/hash_map.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/lru.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/mod.rs Show resolved Hide resolved
kernel/src/bpf/map/mod.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/queue.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/queue.rs Outdated Show resolved Hide resolved
kernel/src/bpf/map/queue.rs Show resolved Hide resolved
kernel/src/bpf/prog/mod.rs Show resolved Hide resolved
user/apps/test_ebpf/Cargo.toml Outdated Show resolved Hide resolved
user/apps/syscall_ebpf/.vim/coc-settings.json Outdated Show resolved Hide resolved
kernel/src/perf/util.rs Outdated Show resolved Hide resolved
kernel/src/perf/bpf.rs Show resolved Hide resolved
kernel/src/filesystem/vfs/file.rs Outdated Show resolved Hide resolved
@Chiichen
Copy link
Member

ci好像还是没过,我看别的PR,看起来好像是ci的问题? @fslongjin https://github.com/DragonOS-Community/DragonOS/actions/runs/10926795584/job/30564234565?pr=928

@Chiichen
Copy link
Member

Chiichen commented Oct 8, 2024

Waiting for pending review

@fslongjin
Copy link
Member

文档里面的几个图片需要重命名一下,改成有意义的名字。

@Godones
Copy link
Contributor Author

Godones commented Oct 11, 2024

文档里面的几个图片需要重命名一下,改成有意义的名字。

ok

docs/kernel/trace/kprobe.md Show resolved Hide resolved
docs/kernel/trace/kprobe.md Show resolved Hide resolved
kernel/src/bpf/helper/mod.rs Outdated Show resolved Hide resolved
kernel/src/mm/ucontext.rs Show resolved Hide resolved
kernel/src/mm/ucontext.rs Outdated Show resolved Hide resolved
kernel/src/mm/ucontext.rs Show resolved Hide resolved
@Chiichen
Copy link
Member

TODO 将当前 do_mmap 的实现,转移到sysfs下

@Chiichen
Copy link
Member

@Godones 似乎test_ebpf 还是没编过

@fslongjin
Copy link
Member

@Godones 似乎test_ebpf 还是没编过

需要把主线合并进来才行,主线的构建容器里面才装了bpf相关工具链。

@Godones
Copy link
Contributor Author

Godones commented Oct 15, 2024

@Godones 似乎test_ebpf 还是没编过

需要把主线合并进来才行,主线的构建容器里面才装了bpf相关工具链。

应该是CI里面使用的依赖是较新的版本,我修改一下就可以

Copy link
Member

@Chiichen Chiichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Chiichen
Copy link
Member

@Godones 上次提到关于mmap的问题解决好了吗

@Godones
Copy link
Contributor Author

Godones commented Oct 18, 2024

@Godones 上次提到关于mmap的问题解决好了吗

这个需要另外一个同学完成它的修改

@Chiichen
Copy link
Member

@Godones 上次提到关于mmap的问题解决好了吗

这个需要另外一个同学完成它的修改

@fslongjin 那先把这个PR合了?

@fslongjin fslongjin merged commit f065d3c into DragonOS-Community:feat-ebpf Oct 19, 2024
7 checks passed
fslongjin pushed a commit that referenced this pull request Oct 25, 2024
* feat(kprobe): Add basic kprobe support for x86_64

* feat: add ebpf support (#912)

- 实现bpf()一部分命令,包括几种基本map,相关的helper函数
- 实现部分perf相关的数据结构
- 暂时为文件实现简单mmap
- 实现一个使用kprobe统计syscall 调用次数的ebpf程序

对eBPF支持程度(基本):

- 简单的eBPF程序(没有指定特殊的Map)
- 使用内核已经实现的Map的eBPF程序
- 可以和kprobe配合使用
- 内核Map相关的接口定义已经实现,添加新的Map较为简单

不支持的功能:
- 区分不同的eBPF程序类型(Network/Cgroup)并限定可调用的helper函数集
- 与内核其它跟踪机制配合(tracepoint)
- 其它helper和Map


todo

- [ ]  修改mmap,需要讨论,因为这个和块缓存层相关
- [x]  添加文档
- [x]  修复可能的错误
- [x] 增加rbpf版本信息

* feat: add /sys/devices/system/cpu/possible file

* feat: add /sys/devices/system/cpu/online
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fs Area: 文件系统 enhancement New feature or request O-riscv64 Target: riscv64 O-x86_64 Target: x86_64 T-doc Relevant to the document team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants