Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
helight authored Jul 8, 2024
2 parents 68f647c + b6a3da5 commit 992fd04
Show file tree
Hide file tree
Showing 28 changed files with 2,743 additions and 60 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/ebpf_cpu_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libbpf-dev clang llvm libelf-dev libpcap-dev gcc-multilib build-essential
sudo apt install -y libbpf-dev clang llvm libelf-dev libpcap-dev gcc-multilib build-essential
git submodule update --init --recursive
- name: Run cpu_watcher
- name: Build cpu_watcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher/
make
sudo ./cpu_watcher
- name: Run test_cpuwatcher
- name: Run cpu_watcher
run: |
sudo ./eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher
- name: Build test_cpuwatcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher/test
make
./test_cpuwatcher
- name: Run test_cpuwatcher
run: |
./eBPF_Supermarket/CPU_Subsystem/cpu_watcher/test/test_cpuwatcher
11 changes: 8 additions & 3 deletions .github/workflows/ebpf_net_manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ jobs:
cd eBPF_Supermarket/Network_Subsystem/net_manager/
sudo ./configure
sudo make
ifconfig
# run
sudo timeout -s SIGINT 5 ./xdp_loader -d ens33 -S || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo ./xacladm load ens33 ./conf.d/mac_load.conf
sudo xdp-loader unload ens33 --all
cd testenv
sudo ./testenv.sh setup --name veth-basic02
cd ..
cd net_manager
sudo timeout -s SIGINT 5 ./xdp_loader -d eth0 -S || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo ./xdp_loader -d eth0 -S



32 changes: 30 additions & 2 deletions MagicEyes/src/visualization/vscode_ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@

![](./images/lmp_vscode_ext.gif)

### 2. 相关提示
### 2. 安装与使用

#### 2.1 导入插件

![import_vscode_ext](./images/import_vscode_ext.png)

安装成功如下:

![lmp_ext_install_success](./images/lmp_ext_install_success.png)

#### 2.2 设置

- 启动grafana(可以在docker中启动),启动prometheus与BPF后端采集程序可以看到数据呈现
- 设置IP地址与端口,默认端口是`localhost:3000`
- 设置token

![create_token](./images/create_token.png)

> [grafana官方_创建token](https://grafana.com/docs/grafana/latest/administration/service-accounts/#create-a-service-account-in-grafana)
![set_token](./images/set_token.png)

设置可视化面板存放路径

Expand All @@ -20,7 +40,15 @@

![](./images/error_info.png)

### 3. 开发注意事项
### 3. 插件开发

#### 3.1 开发

安装yarn并且通过`yarn install`安装所需依赖

> tips: 按 F5 开启调试
#### 3.2 开发注意事项

1. yo code生成的框架,vscode最小版本是1.90,需要修改为1.74,不然我当前的版本。1.89无法运行插件
2. tsconfig
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_cpu_watcher = {
title: cpu_watcher_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现cpu_watcher的grafana的可视化面板",
arguments: [
cpu_watcher_label
]
Expand All @@ -182,7 +182,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_proc_image = {
title: proc_iamge_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现proc_image的grafana的可视化面板",
arguments: [
proc_iamge_label
]
Expand Down Expand Up @@ -214,7 +214,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_net_manager = {
title: net_manager_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现net_manager的grafana的可视化面板",
arguments: [
net_manager_label
]
Expand All @@ -231,7 +231,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_mem_watcher = {
title: mem_watcher_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现mem_watcher的grafana的可视化面板",
arguments: [
mem_watcher_label
]
Expand All @@ -248,7 +248,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_stack_analyzer = {
title: stack_analyzer_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现stack_analyzer的grafana的可视化面板",
arguments: [
stack_analyzer_label
]
Expand All @@ -265,7 +265,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_kvm_watcher = {
title: kvm_watcher_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现kvm_watcher的grafana的可视化面板",
arguments: [
kvm_watcher_label
]
Expand Down Expand Up @@ -390,4 +390,4 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
}
}
*/
*/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Schedule_delay工具使用说明

​ Schedule_delay工具是用来检测系统中调度延时的工具,该工具可以监测特定线程或线程组、以及整个系统的调度延迟(最大、最小、平均)。即从一个任务具备运行的条件,到真正执行(获得 CPU 的执行权)的这段时间。实时观测该指标可以帮助我们了解到当前操作系统的负载。

## 原理讲解

​ 该工具使用六个map来控制工具的行为和存储数据与用户态交互。分别为:

- **ARRAY MAP**`sched_ctrl_map`:作为调度控制信息的存储,策略上将该map pin到bpf文件系统,即可在用户态更新该map,与内核态交互。其value为`struct sched_ctrl`

```c
struct sched_ctrl {
bool sched_func; // 控制是否记录调度相关事件
pid_t target_pid; // 目标进程的 PID
int target_cpu_id; // 目标 CPU 的 ID
pid_t target_tgid; // 目标线程组的 TGID
};
```

​ 通过这些控制信息,可以控制该工具在内核态的行为。

- **HASH MAP**`enable add`:用来记录进程是否被调度过,以避免重复计数或错误计数。

- **HASH MAP**`proc_schedule`:用于存储和跟踪每个进程的调度事件信息,key为进程的id和cpu_id,value为` struct schedule_event`:

```c
struct schedule_event {
pid_t pid; // 进程ID
int tgid; // 线程组ID
int prio; // 进程优先级
u32 count; // 调度次数
u64 enter_time; // 进入调度的时间
u64 sum_delay; // 累计调度延迟
u64 max_delay; // 最大调度延迟
u64 min_delay; // 最小调度延迟
};
```

- **HASH MAP**`target_schedule`:用于存储指定**线程**的调度信息,value为` struct schedule_event`,在用户态通过更新`sched_ctrl_map`指定要记录的线程。
- **HASH MAP**`tg_schedule`:用于存储指定**线程组**的调度信息,value为` struct schedule_event`,在用户态通过更新`sched_ctrl_map`指定要记录的线程组。

- **ARRAY MAP**`sys_schedule`:用于记录整个系调度延时,value为`struct sum_schedule:`

```c
struct sum_schedule {
long long unsigned int sum_count; // 总调度次数
long long unsigned int sum_delay; // 总调度延迟
long long unsigned int max_delay; // 最大调度延迟
long long unsigned int min_delay; // 最小调度延迟
};
```

**代码逻辑图如下:**

![](images/schedule_delay_process.png)

## 2.使用方法

### 2.1编译

​ 首先在`lmp/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image`目录下进行编译操作。

```shell
make
```

​ 编译成功后,会生成两个可执行文件`proc_image`,`controller`

### 2.2挂载

​ 在`lmp/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image`目录下运行 `proc_image`可执行文件。

​ 使用-S选项挂载检测调度延迟的几个挂载点:

```shell
sudo ./proc_image -S
```

```
sudo ./proc_image -S
......
libbpf: map 'sched_ctrl_map': created successfully, fd=3
libbpf: map 'proc_schedule': created successfully, fd=4
libbpf: map 'enable_add': created successfully, fd=5
libbpf: map 'target_schedule': created successfully, fd=6
libbpf: map 'tg_schedule': created successfully, fd=7
libbpf: map 'sys_schedule': created successfully, fd=8
libbpf: map 'schedule.rodata': created successfully, fd=9
libbpf: pinned map '/sys/fs/bpf/proc_image_map/sched_ctrl_map'
```

​ 此时用户态内核态交互的**sched_ctrl_map**已经pin上,现在我们可以通过controller执行文件来更改输出策略。

### 2.3用户态控制交互

​ 可使用`controller`工具和内核态进行交互,控制输出。

​ 重启一个终端, 在`lmp/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image`目录下运行 `controller`可执行文件。

​ 使用schedule_image工具的不同参数,控制该工具的使用策略:

| 参数 | |
| :--: | ---------------------- |
| -S | 使用schedule_image工具 |
| -a | 激活schedule_image工具 |
| -p | 指定目标线程 |
| -P | 指定目标线程组 |
| -c | 指定检测CPU |
| -t | 指定检测时间 |

通过以下指令更改控制策略:

- 激活对线程21416的调度延迟进行监测:

```
sudo ./controller -S -a -p 21416
```

- 激活对线程组21416的调度延迟进行监测:

```
sudo ./controller -s -a -p 21416
```

- 关闭对线程21416的调度延迟进行监测:

```
sudo ./controller -S -d -p 21416
```

- 关闭对线程组21416的调度延迟进行监测:

```
sudo ./controller -S -d -P 21416
```

- 检测整个系统的调度延迟:

```
sudo ./controller -S -a
```

- 关闭进程画像工具:

```
sudo ./controller -f
```

#### 2.4 输出

​ 对线程21416的调度延迟进行监测,可以看到指定进程的调度延迟信息,包括该线程最大、最小、平均的调度延迟(P_xxx_DELAY),以及整个系统的最大、最小、平均的调度延迟(S_xxx_DELAY)。
![](images/schedule_delay_output.png)
2 changes: 1 addition & 1 deletion eBPF_Supermarket/Network_Subsystem/net_manager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MAKEFLAGS += --no-print-directory -s
Q = @
endif

PROJ := xacl_ip router xacl_mac xstate
PROJ := xacl_ip router xacl_mac xstate net_manager



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ struct config {
int xsk_if_queue;
bool xsk_poll_mode;
bool unload_all;
bool show_stats; // 数据统计
bool ip_filter; //ip过滤
bool mac_filter; //mac过滤
bool router; //路由
bool state; //会话保持
bool clear; //清理

};

/* Defined in common_params.o */
Expand Down
Loading

0 comments on commit 992fd04

Please sign in to comment.