Skip to content

Commit

Permalink
Merge branch 'linuxkerneltravel:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhangchannel authored May 24, 2024
2 parents 7c19c62 + 9ae9062 commit ea48108
Show file tree
Hide file tree
Showing 432 changed files with 376,269 additions and 1,022 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ebpf_kvm_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Test program execution
- name: Install dependencies
run: |
cd eBPF_Supermarket/kvm_watcher/
make deps
make
- name: Test program execution
continue-on-error: true
run: |
cd eBPF_Supermarket/kvm_watcher/
make
1 change: 1 addition & 0 deletions .github/workflows/ebpf_net_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ jobs:
sudo timeout -s SIGINT 5 ./netwatcher -k || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo timeout -s SIGINT 5 ./netwatcher -k -T || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo timeout -s SIGINT 5 ./netwatcher -I || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo timeout -s SIGINT 5 ./netwatcher -S || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
timeout-minutes: 5
15 changes: 13 additions & 2 deletions .github/workflows/ebpf_stack_analyser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ jobs:
run: |
cd eBPF_Supermarket/Stack_Analyser
make
sudo ./stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe vfs_open -d 5
sudo ./stack_analyzer probe p::vfs_open -d 5
sudo ./stack_analyzer probe t:sched:sched_switch -d 5
gcc -o ./testdir/usdt_pthread ./testdir/usdt_pthread.c
sudo ./stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe u:pthread:pthread_create -c "./testdir/usdt_pthread" -t 5
sudo ./stack_analyzer probe u:pthread:pthread_create -c "./testdir/usdt_pthread" -d 5
gcc -o ./testdir/uprobe_malloc ./testdir/uprobe_malloc.c
sudo ./stack_analyzer probe c:malloc -c "./testdir/uprobe_malloc" -d 5
magic-eyes-build-and-test:
runs-on: ubuntu-22.04
Expand All @@ -49,4 +56,8 @@ jobs:
cd MagicEyes/build
cmake -DBUILD_STACK_ANALYZER=ON ..
make
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe u:pthread:pthread_create -c "../../eBPF_Supermarket/Stack_Analyser/testdir/usdt_pthread" -t 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe vfs_open -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe p::vfs_open -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe t:sched:sched_switch -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe c:malloc -c "../../eBPF_Supermarket/Stack_Analyser/testdir/uprobe_malloc" -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe u:pthread:pthread_create -c "../../eBPF_Supermarket/Stack_Analyser/testdir/usdt_pthread" -d 5
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/controller
# Stack_Analyser
eBPF_Supermarket/Stack_Analyser/stack_analyzer
eBPF_Supermarket/Stack_Analyser/exporter/exporter
eBPF_Supermarket/Stack_Analyser/bpf_skel
eBPF_Supermarket/Stack_Analyser/bpf_skel
26 changes: 23 additions & 3 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ VMLINUX := ../vmlinux/$(ARCH)/vmlinux.h
# Use our own libbpf API headers and Linux UAPI headers distributed with
# libbpf to avoid dependency on system-wide headers, which could be missing or
# outdated
INCLUDES := -I$(OUTPUT) -I../../../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(LIBBLAZESYM_INC) -I./
INCLUDES := -I$(OUTPUT) -I../../../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(LIBBLAZESYM_INC) -I./include
CFLAGS := -g -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)

APPS =cs_delay sar sc_delay preempt schedule_delay mq_delay
TARGETS=cpu_watcher

SRC_DIR = ./include


# Get Clang's default includes on this system. We'll explicitly add these dirs
# to the includes list when compiling with `-target bpf` because otherwise some
Expand Down Expand Up @@ -112,7 +114,7 @@ $(LIBBLAZESYM_OBJ): $(LIBBLAZESYM_SRC)/target/release/libblazesym.a | $(OUTPUT)
$(Q)cp $(LIBBLAZESYM_SRC)/target/release/libblazesym.a $@

# Build BPF code
$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL)
$(OUTPUT)/%.bpf.o: bpf/%.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL)
$(call msg,BPF,$@)
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) \
$(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) \
Expand All @@ -126,14 +128,32 @@ $(APPS): %: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
$(Q)$(BPFTOOL) gen skeleton $< > $(OUTPUT)/$@.skel.h

# Build user-space code
$(OUTPUT)/%.o: $(SRC_DIR)/%.c | $(OUTPUT)
$(call msg,CC,$@)
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

$(OUTPUT)/$(TARGETS).o: $(TARGETS).c $(APPS) | $(OUTPUT)
$(call msg,CC,$@)
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@

# Build application binary
$(TARGETS): %: $(OUTPUT)/%.o $(COMMON_OBJ) $(LIBBPF_OBJ) | $(OUTPUT)
$(call msg,BINARY,$@)
$(Q)$(CC) $(CFLAGS) $^ $(ALL_LDFLAGS) -lelf -lz -o $@
$(Q)$(CC) $(CFLAGS) $^ $(ALL_LDFLAGS) -lstdc++ -lelf -lz -o $@

SUCCESS_MESSAGE:
@echo "\e[38;2;255;0;0m __ __ \e[0m"
@echo "\e[38;2;255;128;0m _________ __ __ _ ______ _/ /______/ /_ ___ _____\e[0m"
@echo "\e[38;2;255;255;0m / ___/ __ \/ / / / | | /| / / __ / __/ ___/ __ \/ _ \/ ___/\e[0m"
@echo "\e[38;2;128;255;0m/ /__/ /_/ / /_/ / | |/ |/ / /_/ / /_/ /__/ / / / __/ / \e[0m"
@echo "\e[38;2;0;255;0m\___/ .___/\__,_/ |__/|__/\__,_/\__/\___/_/ /_/\___/_/ \e[0m"
@echo "\e[38;2;0;255;128m /_/ \e[0m"
@echo "\e[38;2;0;255;255mSuccessful to compile cpu_watcher tools: \e[0m"
@echo "\e[38;2;0;255;255mPlease start your use ~ \e[0m"


all: $(TARGETS) SUCCESS_MESSAGE


# delete failed targets
.DELETE_ON_ERROR:
Expand Down
7 changes: 6 additions & 1 deletion eBPF_Supermarket/CPU_Subsystem/cpu_watcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ make clean 清除生成文件
- `sysc/ms`: CPU执行用户程序系统调用(`syscall`)所占用的时间,是所有CPU的叠加。
- ` utime/ms`:CPU执行普通用户进程时,花在用户态的时间,是所有CPU的叠加。

原理介绍:

[libbpf_sar工具原理分析](docs/libbpf_sar.md)
### **2.统计抢占调度时间:**

​ 统计系统中发生抢占调度的情况,包括抢占进程的`pid`与进程名,以及被强占进程的`pid`,和本次抢占时间,单位纳秒。
Expand Down Expand Up @@ -214,9 +217,11 @@ per_len = 1000

​ 获取内核全局变量,直接从内核全局变量读取信息。如proc/s就是通过直接读取total_forks内核全局变量来计算每秒产生进程数的。

## 五、cpu_watcher可视化

[cpu_watcher可视化指南](docs/cpu_watcher_vis_guide.md)

## 、未来展望
## 、未来展望

目前`cpu_watcher`工具的总体框架已经完成,工具所能满足的功能已覆盖CPU所涉及的大部分性能指标。下一阶段,本工具将从以下几个方向进行开发和优化:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected] [email protected] [email protected]

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 The LMP Authors.
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected]
// author: [email protected] [email protected] [email protected]

#include "vmlinux.h"
#include <bpf/bpf_helpers.h> //包含了BPF 辅助函数
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected] [email protected] [email protected]

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
Expand Down Expand Up @@ -33,7 +49,8 @@ int BPF_PROG(sched_switch, bool preempt, struct task_struct *prev, struct task_s
return 0;
}

SEC("kprobe/finish_task_switch")
// SEC("kprobe/finish_task_switch")
SEC("kprobe/finish_task_switch.isra.0")
int BPF_KPROBE(finish_task_switch, struct task_struct *prev) {
u64 end_time = bpf_ktime_get_ns();
pid_t pid = BPF_CORE_READ(prev, pid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected] [email protected] [email protected]

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
Expand Down Expand Up @@ -36,8 +52,8 @@ BPF_ARRAY(ut_LastTime,u32,u64,1);
BPF_ARRAY(tick_user,u32,u64,1);
BPF_ARRAY(symAddr,u32,u64,1);
// 统计fork数
//SEC("kprobe/finish_task_switch.isra.0")
SEC("kprobe/finish_task_switch")
SEC("kprobe/finish_task_switch.isra.0")
// SEC("kprobe/finish_task_switch")
int kprobe__finish_task_switch(struct pt_regs *ctx)
{
u32 key = 0;
Expand Down Expand Up @@ -75,8 +91,8 @@ int trace_sched_switch2(struct cswch_args *info) {
return 0;
}

SEC("kprobe/finish_task_switch")
//SEC("kprobe/finish_task_switch.isra.0")
// SEC("kprobe/finish_task_switch")
SEC("kprobe/finish_task_switch.isra.0")
int BPF_KPROBE(finish_task_switch,struct task_struct *prev){
pid_t pid=BPF_CORE_READ(prev,pid);
u64 *val, time = bpf_ktime_get_ns();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected] [email protected] [email protected]

#include "vmlinux.h"
#include <bpf/bpf_helpers.h> //包含了BPF 辅助函数
#include <bpf/bpf_tracing.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected] [email protected] [email protected]

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
Expand Down Expand Up @@ -111,18 +127,30 @@ int BPF_PROG(sched_switch, bool preempt, struct task_struct *prev, struct task_s
struct sum_schedule sum_schedule= {};
sum_schedule.sum_count++;
sum_schedule.sum_delay += delay;
if (delay > sum_schedule.max_delay)
if (delay > sum_schedule.max_delay){
sum_schedule.max_delay = delay;
if (sum_schedule.min_delay == 0 || delay < sum_schedule.min_delay)
if(next->pid!=0){
sum_schedule.pid_max = next->pid;
}
}else if (sum_schedule.min_delay == 0 || delay < sum_schedule.min_delay)
sum_schedule.min_delay = delay;
if(next->pid!=0){
sum_schedule.pid_min = next->pid;
}
bpf_map_update_elem(&sys_schedule, &key, &sum_schedule, BPF_ANY);
} else {
sum_schedule->sum_count++;
sum_schedule->sum_delay += delay;
if (delay > sum_schedule->max_delay)
if (delay > sum_schedule->max_delay){
sum_schedule->max_delay = delay;
if (sum_schedule->min_delay == 0 || delay < sum_schedule->min_delay)
if(next->pid!=0){
sum_schedule->pid_max = next->pid;
}
}else if (sum_schedule->min_delay == 0 || delay < sum_schedule->min_delay)
sum_schedule->min_delay = delay;
if(next->pid!=0){
sum_schedule->pid_min = next->pid;
}
}
return 0;
}
Expand Down
Loading

0 comments on commit ea48108

Please sign in to comment.