Skip to content

Commit 4cf8006

Browse files
committedFeb 10, 2025·
update
1 parent 5e62255 commit 4cf8006

File tree

6 files changed

+137
-10
lines changed

6 files changed

+137
-10
lines changed
 

‎src/18-further-reading/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The papers demonstrate eBPF's versatility in accelerating systems, enhancing sec
2222

2323
If you have any suggestions or adding papers, please feel free to open an issue or PR. The list was created in 2023.10, New papers will be added in the future.
2424

25-
> Check out our open-source projects at [eunomia-bpf](https://github.com/eunomia-bpf) and eBPF tutorials at [bpf-developer-tutorial](https://github.com/eunomia-bpf/bpf-developer-tutorial). I'm also looking for a PhD position in the area of systems and networking in 2024/2025. My [Github](https://github.com/yunwei37) and [email](yunwei356@gmail.com).
25+
> Check out our open-source projects at [eunomia-bpf](https://github.com/eunomia-bpf) and eBPF tutorials at [bpf-developer-tutorial](https://github.com/eunomia-bpf/bpf-developer-tutorial). I'm also looking for a PhD position in the area of systems and networking in 2024/2025. My [Github](https://github.com/yunwei37) and [email](mailto:yunwei356@gmail.com).
2626
2727
## XRP: In-Kernel Storage Functions with eBPF
2828

‎src/18-further-reading/README.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ eBPF(扩展的伯克利数据包过滤器)是一种新兴的技术,允许
2020

2121
如果您有任何建议或添加论文的意见,请随时开放一个问题或PR。此列表创建于 2023.10,未来将添加新的论文。
2222

23-
> 如果您对 eBPF 有些进一步的兴趣的话,也可以查看我们在 [eunomia-bpf](https://github.com/eunomia-bpf) 的开源项目和 [bpf-developer-tutorial](https://github.com/eunomia-bpf/bpf-developer-tutorial) 的 eBPF 教程。我也在寻找 2024/2025 年系统和网络领域的 PhD 相关机会,这是我的 [Github](https://github.com/yunwei37)[邮箱](yunwei356@gmail.com)
23+
> 如果您对 eBPF 有些进一步的兴趣的话,也可以查看我们在 [eunomia-bpf](https://github.com/eunomia-bpf) 的开源项目和 [bpf-developer-tutorial](https://github.com/eunomia-bpf/bpf-developer-tutorial) 的 eBPF 教程。我也在寻找 2024/2025 年系统和网络领域的 PhD 相关机会,这是我的 [Github](https://github.com/yunwei37)[邮箱](mailto:yunwei356@gmail.com)
2424
2525
## XRP: In-Kernel Storage Functions with eBPF
2626

‎src/32-http2/README.zh.md

-5
This file was deleted.

‎src/43-kfuncs/module/README.md

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# write a basic kernel module
2+
3+
## hello world
4+
5+
Writing a Linux kernel module involves creating code that can be loaded into and unloaded from the kernel dynamically, without rebooting the system. Here’s a simple step-by-step guide to help you write a basic kernel module:
6+
7+
### 1. Set Up Your Environment
8+
9+
Make sure you have the Linux kernel headers installed and a suitable development environment ready. For Ubuntu or Debian, install them with:
10+
11+
```bash
12+
sudo apt-get install linux-headers-$(uname -r) build-essential
13+
```
14+
15+
### 2. Write the Kernel Module Code
16+
17+
Here’s an example of a very basic Linux kernel module:
18+
19+
```c
20+
// hello.c: A simple Linux kernel module
21+
#include <linux/init.h> // Macros for module initialization
22+
#include <linux/module.h> // Core header for loading modules
23+
#include <linux/kernel.h> // Kernel logging macros
24+
25+
// Function executed when the module is loaded
26+
static int __init hello_init(void)
27+
{
28+
printk(KERN_INFO "Hello, world!\n");
29+
return 0; // Return 0 if successful
30+
}
31+
32+
// Function executed when the module is removed
33+
static void __exit hello_exit(void)
34+
{
35+
printk(KERN_INFO "Goodbye, world!\n");
36+
}
37+
38+
// Macros to define the module’s init and exit points
39+
module_init(hello_init);
40+
module_exit(hello_exit);
41+
42+
MODULE_LICENSE("GPL"); // License type (GPL)
43+
MODULE_AUTHOR("Your Name"); // Module author
44+
MODULE_DESCRIPTION("A simple module"); // Module description
45+
MODULE_VERSION("1.0"); // Module version
46+
```
47+
48+
### 3. Create a Makefile
49+
50+
To compile the kernel module, you’ll need a `Makefile`. Here's a simple one:
51+
52+
```makefile
53+
obj-m += hello.o # hello.o is the target
54+
55+
all:
56+
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
57+
58+
clean:
59+
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
60+
```
61+
62+
### 4. Compile the Module
63+
64+
Run the following command in the directory where your `hello.c` and `Makefile` are located:
65+
66+
```bash
67+
make
68+
```
69+
70+
This will generate a file called `hello.ko`, which is the compiled kernel module.
71+
72+
### 5. Load the Module
73+
74+
To insert the module into the kernel, use `insmod`:
75+
76+
```bash
77+
sudo insmod hello.ko
78+
```
79+
80+
### 6. Check the Logs
81+
82+
To see the output from the `printk` statements, use the `dmesg` command:
83+
84+
```bash
85+
dmesg | tail
86+
```
87+
88+
You should see something like:
89+
90+
```txt
91+
[ 1234.5678] Hello, world!
92+
```
93+
94+
### 7. Remove the Module
95+
96+
To unload the module, use `rmmod`:
97+
98+
```bash
99+
sudo rmmod hello
100+
```
101+
102+
Again, check the logs using `dmesg`:
103+
104+
```bash
105+
sudo dmesg | tail
106+
```
107+
108+
You should see:
109+
110+
```txt
111+
[ 1234.9876] Goodbye, world!
112+
```
113+
114+
### 8. Clean Up
115+
116+
To clean up the build files, run:
117+
118+
```bash
119+
make clean
120+
```
121+
122+
### Notes
123+
124+
- **License**: The `MODULE_LICENSE("GPL")` ensures the module is GPL-compliant, which allows it to use symbols (functions) exported by the kernel.
125+
- **Debugging**: Use `printk` for logging within the module. It behaves similarly to `printf` but is designed for kernel space.
126+
- **Module Parameters**: You can add parameters to modules using `module_param()` to pass arguments when the module is loaded.
127+
128+
### Next Steps
129+
130+
Once you are familiar with this basic example, you can explore:
131+
132+
- Writing more advanced modules that interact with hardware or the filesystem.
133+
- Using kernel-specific APIs like work queues, kthreads, or handling interrupts.
134+
- Diving into eBPF or loadable kernel module techniques for debugging and tracing kernel events.

‎src/SUMMARY.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# eBPF Tutorial by Example: Learning CO-RE eBPF Step by Step
22

3-
[![CI](https://github.com/eunomia-bpf/bpf-developer-tutorial/actions/workflows/main.yml/badge.svg)](https://github.com/eunomia-bpf/bpf-developer-tutorial/actions/workflows/main.yml)
4-
53
This is a development tutorial for eBPF based on CO-RE (Compile Once, Run Everywhere). It provides practical eBPF development practices from beginner to advanced, including basic concepts, code examples, and real-world applications. Unlike BCC, we use frameworks like libbpf, Cilium, libbpf-rs, and eunomia-bpf for development, with examples in languages such as C, Go, and Rust.
64

75
This tutorial does not cover complex concepts and scenario introductions. Its main purpose is to provide examples of eBPF tools (**very short, starting with twenty lines of code!**) to help eBPF application developers quickly grasp eBPF development methods and techniques. The tutorial content can be found in the directory, with each directory being an independent eBPF tool example.

‎src/bpftrace-tutorial/README.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Attaching 1 probe...
6666
按Ctrl-C后打印进程的系统调用计数。
6767

6868
- @: 表示一种特殊的变量类型,称为map,可以以不同的方式来存储和描述数据。你可以在@后添加可选的变量名(如@num),用来增加可读性或者区分不同的map。
69-
- []: 可选的中括号允许设置map的关键字,比较像关联数组。
69+
- [] 可选的中括号允许设置map的关键字,比较像关联数组。
7070
- count(): 这是一个map函数 - 记录被调用次数。因为调用次数根据comm保存在map里,输出结果是进程执行系统调用的次数统计。
7171

7272
Maps会在bpftrace结束(如按Ctrl-C)时自动打印出来。

0 commit comments

Comments
 (0)
Please sign in to comment.