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
albertxu216 authored Feb 1, 2024
2 parents b1e72fb + 2780fb2 commit 0651ba4
Show file tree
Hide file tree
Showing 38 changed files with 2,429 additions and 1,403 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cpu_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
- name: Run cpu_watcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher/
make cpu_watcher
make
sudo ./cpu_watcher
6 changes: 0 additions & 6 deletions .github/workflows/eBPF_proc_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ jobs:
sudo insmod mutex_test1.ko
sudo insmod mutex_test2.ko
- name: Run test_sleep
run: |
cd eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test
gcc test_sleep.c -o test_sleep
./test_sleep
- name: Run test_proc
run: |
cd eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/kvm_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ jobs:
- name: Run QEMU to start VM
run: |
sudo qemu-system-x86_64 -enable-kvm -cpu host -m 2048 -drive file=cirros-0.5.1-x86_64-disk.img,format=qcow2 -boot c -nographic &
sleep 5
- name: Run kvm_watcher
run: |
cd eBPF_Supermarket/kvm_watcher/
make
sudo ./kvm_watcher -w -t 10
sudo ./kvm_watcher -e -t 10 -s
sudo ./kvm_watcher -n -t 10
sudo ./kvm_watcher -d -t 10
sudo ./kvm_watcher -f -m -t 10
sudo ./kvm_watcher -i -t 10
sudo ./kvm_watcher -w -t 2
sudo ./kvm_watcher -e -t 2 -s
sudo ./kvm_watcher -n -t 2
sudo ./kvm_watcher -d -t 2
sudo ./kvm_watcher -f -m -t 2
sudo ./kvm_watcher -c -t 2
make clean
2 changes: 1 addition & 1 deletion .github/workflows/system_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ jobs:
- name: Run cpu_watcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher
make cpu_watcher
make
sudo ./cpu_watcher
16 changes: 4 additions & 12 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,13 @@ 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)
INCLUDES := -I$(OUTPUT) -I../../../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(LIBBLAZESYM_INC) -I./
CFLAGS := -g -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)

APPS = cpu_watcher
APPS =cs_delay sar cpu_watcher


CARGO ?= $(shell which cargo)
ifeq ($(strip $(CARGO)),)
BZS_APPS :=
else
BZS_APPS := profile
APPS += $(BZS_APPS)
# Required by libblazesym
ALL_LDFLAGS += -lrt -ldl -lpthread -lm
endif

# 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 @@ -152,4 +144,4 @@ $(APPS): %: $(OUTPUT)/%.o $(COMMON_OBJ) $(LIBBPF_OBJ) | $(OUTPUT)
.DELETE_ON_ERROR:

# keep intermediate (.skel.h, .bpf.o, etc) targets
.SECONDARY:
.SECONDARY:
124 changes: 25 additions & 99 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,117 +29,43 @@ const volatile long long unsigned int forks_addr = 0;
#define PF_IDLE 0x00000002 /* I am an IDLE thread */
#define PF_KTHREAD 0x00200000 /* I am a kernel thread */

/*----------------------------------------------*/
/* cs_delay相关maps */
/*----------------------------------------------*/
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, u64);
} start SEC(".maps");//记录时间戳;

/*----------------------------------------------*/
/* sar相关maps */
/* cs_delay相关maps */
/*----------------------------------------------*/
// 计数表格,第0项为所统计fork数,第1项为进程切换数,
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);//基于数组的映射
__uint(max_entries, 3);//countMap 可以存储最多 3 对键值对
__type(key, int);
__type(value, u64);
} countMap SEC(".maps");

// 记录开始的时间
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 4096);
__type(key, pid_t);
__type(value, u64);
} procStartTime SEC(".maps");//记录时间戳;

//环形缓冲区;
BPF_ARRAY(start,int,u64,1);
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 256 * 1024);
} rb SEC(".maps");


/*----------------------------------------------*/
/* sar相关maps */
/*----------------------------------------------*/
// 计数表格,第0项为所统计fork数,第1项为进程切换数
BPF_ARRAY(countMap,int,u64,3);
// 记录开始的时间
BPF_ARRAY(procStartTime,pid_t,u64,4096);
// 储存运行队列rq的全局变量
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, struct rq);
} rq_map SEC(".maps");


struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, int);
} runqlen SEC(".maps");//多CPU数组

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
__uint(max_entries, 4096);
__type(key, u32);
__type(value, u64);
} softirqCpuEnterTime SEC(".maps");//记录软中断开始时间

struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, u64);
} softirqLastTime SEC(".maps");//软中断结束时间

BPF_ARRAY(rq_map,u32,struct rq,1);
//存储运行队列长度
BPF_PERCPU_ARRAY(runqlen,u32,int,1);
//记录软中断开始时间
BPF_HASH(softirqCpuEnterTime,u32,u64,4096);
//记录软中断结束时间
BPF_HASH(softirqLastTime,u32,u64,1);
// 记录开始的时间
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
__uint(max_entries, 8192);//该哈希表可容纳8192个条目
__type(key, u32);
__type(value, u64);
} irq_cpu_enter_start SEC(".maps");//irq_start是一个哈希类型的 eBPF map,用于存储开始执行时的时间戳。

BPF_HASH(irq_cpu_enter_start,u32,u64,8192);
//记录上次中断时间
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, u64);
} irq_Last_time SEC(".maps");

BPF_ARRAY(irq_Last_time,u32,u64,1);
// 储存cpu进入空闲的起始时间
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 128);
__type(key, u32);
__type(value, u64);
} idleStart SEC(".maps");

BPF_ARRAY(idleStart,u32,u64,128);
// 储存cpu进入空闲的持续时间
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, u64);
} idleLastTime SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, u64);
} kt_LastTime SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, u32);
__type(value, u64);
} ut_LastTime SEC(".maps");
BPF_ARRAY(idleLastTime,u32,u64,1);
// 储存cpu运行内核线程的时间
BPF_ARRAY(kt_LastTime,u32,u64,1);
// 储存cpu运行用户线程的时间
BPF_ARRAY(ut_LastTime,u32,u64,1);
// 统计fork数

/*----------------------------------------------*/
/* cs_delay跟踪函数 */
Expand Down
Loading

0 comments on commit 0651ba4

Please sign in to comment.