From 09e80a77f56015efdcfa7b4819499b1ea17bf811 Mon Sep 17 00:00:00 2001 From: yunwei37 <1067852565@qq.com> Date: Tue, 27 Jun 2023 16:44:37 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20eunomia-?= =?UTF-8?q?bpf/bpf-developer-tutorial@f1c9cba2c4ed33cba678064099650955ee0b?= =?UTF-8?q?0f62=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-helloworld/index.html | 12 +++++++----- print.html | 12 +++++++----- searchindex.js | 2 +- searchindex.json | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/1-helloworld/index.html b/1-helloworld/index.html index 2e33889..880bb74 100644 --- a/1-helloworld/index.html +++ b/1-helloworld/index.html @@ -193,9 +193,7 @@ Packing ebpf object and config into /src/package.json...

Hello World - minimal eBPF program

我们会先从一个简单的 eBPF 程序开始,它会在内核中打印一条消息。我们会使用 eunomia-bpf 的编译器工具链将其编译为 bpf 字节码文件,然后使用 ecli 工具加载并运行该程序。作为示例,我们可以暂时省略用户态程序的部分。

-

-```c
-/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
+
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
 #define BPF_NO_GLOBAL_DATA
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
@@ -213,7 +211,7 @@ int handle_tp(void *ctx)
  pid_t pid = bpf_get_current_pid_tgid() >> 32;
  if (pid_filter && pid != pid_filter)
   return 0;
- bpf_printk("BPF triggered from PID %d.\n", pid);
+ bpf_printk("BPF triggered sys_enter_write from PID %d.\n", pid);
  return 0;
 }
 
@@ -235,7 +233,7 @@ Packing ebpf object and config into package.json...
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
 

然后使用 ecli 运行编译后的程序:

-
$ sudo ecli run package.json
+
$ sudo ./ecli run package.json
 Runing eBPF program...
 

运行这段程序后,可以通过查看 /sys/kernel/debug/tracing/trace_pipe 文件来查看 eBPF 程序的输出:

@@ -244,6 +242,10 @@ Runing eBPF program... <...>-3840345 [010] d... 3220701.101143: bpf_trace_printk: write system call from PID 3840345.

按 Ctrl+C 停止 ecli 进程之后,可以看到对应的输出也停止。

+

注意:如果正在使用的 Linux 发行版例如 Ubuntu 默认情况下没有启用跟踪子系统可能看不到任何输出,使用以下指令打开这个功能:

+
$ sudo su
+# echo 1 > /sys/kernel/debug/tracing/tracing_on
+

eBPF 程序的基本框架

如上所述, eBPF 程序的基本框架包括:

Hello World - minimal eBPF program

我们会先从一个简单的 eBPF 程序开始,它会在内核中打印一条消息。我们会使用 eunomia-bpf 的编译器工具链将其编译为 bpf 字节码文件,然后使用 ecli 工具加载并运行该程序。作为示例,我们可以暂时省略用户态程序的部分。

-

-```c
-/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
+
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
 #define BPF_NO_GLOBAL_DATA
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
@@ -344,7 +342,7 @@ int handle_tp(void *ctx)
  pid_t pid = bpf_get_current_pid_tgid() >> 32;
  if (pid_filter && pid != pid_filter)
   return 0;
- bpf_printk("BPF triggered from PID %d.\n", pid);
+ bpf_printk("BPF triggered sys_enter_write from PID %d.\n", pid);
  return 0;
 }
 
@@ -366,7 +364,7 @@ Packing ebpf object and config into package.json...
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
 

然后使用 ecli 运行编译后的程序:

-
$ sudo ecli run package.json
+
$ sudo ./ecli run package.json
 Runing eBPF program...
 

运行这段程序后,可以通过查看 /sys/kernel/debug/tracing/trace_pipe 文件来查看 eBPF 程序的输出:

@@ -375,6 +373,10 @@ Runing eBPF program... <...>-3840345 [010] d... 3220701.101143: bpf_trace_printk: write system call from PID 3840345.

按 Ctrl+C 停止 ecli 进程之后,可以看到对应的输出也停止。

+

注意:如果正在使用的 Linux 发行版例如 Ubuntu 默认情况下没有启用跟踪子系统可能看不到任何输出,使用以下指令打开这个功能:

+
$ sudo su
+# echo 1 > /sys/kernel/debug/tracing/tracing_on
+

eBPF 程序的基本框架

如上所述, eBPF 程序的基本框架包括: