-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpu_watcher:schedule_delay功能扩充&sar功能适配controller (#830)
* cpu_watcher:schedule_delay增加阈值选项&&workflow增加测试流程 * . * cpu_watcher:增加controller功能 * cpu_watcher:schedule_delay增加dump出调度延迟过大task的前两个task * sar功能适配controller * .
- Loading branch information
Showing
9 changed files
with
187 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,27 +15,38 @@ | |
// author: [email protected] [email protected] [email protected] | ||
|
||
#include "vmlinux.h" | ||
#include <bpf/bpf_helpers.h> //包含了BPF 辅助函数 | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
#include "cpu_watcher.h" | ||
|
||
char LICENSE[] SEC("license") = "Dual BSD/GPL"; | ||
|
||
// 定义数组映射 | ||
//BPF_PERCPU_HASH(SyscallEnterTime,pid_t,struct syscall_flags,512);//记录时间戳 | ||
BPF_PERCPU_HASH(SyscallEnterTime,pid_t,u64,512);//记录时间戳 | ||
|
||
const int ctrl_key = 0; | ||
BPF_PERCPU_HASH(SyscallEnterTime,pid_t,u64,512); | ||
BPF_PERCPU_HASH(Events,pid_t,u64,10); | ||
BPF_ARRAY(sc_ctrl_map,int,struct sc_ctrl,1); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_RINGBUF); | ||
__uint(max_entries, 256 * 1024); | ||
} rb SEC(".maps");//环形缓冲区; | ||
|
||
static inline struct sc_ctrl *get_sc_ctrl(void) { | ||
struct sc_ctrl *sc_ctrl; | ||
sc_ctrl = bpf_map_lookup_elem(&sc_ctrl_map, &ctrl_key); | ||
if (!sc_ctrl || !sc_ctrl->sc_func) { | ||
return NULL; | ||
} | ||
return sc_ctrl; | ||
} | ||
|
||
|
||
SEC("tracepoint/raw_syscalls/sys_enter")//进入系统调用 | ||
SEC("tracepoint/raw_syscalls/sys_enter") | ||
int tracepoint__syscalls__sys_enter(struct trace_event_raw_sys_enter *args){ | ||
u64 start_time = bpf_ktime_get_ns()/1000;//ms | ||
pid_t pid = bpf_get_current_pid_tgid();//获取到当前进程的pid | ||
struct sc_ctrl *sc_ctrl = get_sc_ctrl(); | ||
u64 start_time = bpf_ktime_get_ns()/1000; | ||
pid_t pid = bpf_get_current_pid_tgid(); | ||
u64 syscall_id = (u64)args->id; | ||
|
||
//bpf_printk("ID:%ld\n",syscall_id); | ||
|
@@ -44,13 +55,13 @@ int tracepoint__syscalls__sys_enter(struct trace_event_raw_sys_enter *args){ | |
return 0; | ||
} | ||
|
||
SEC("tracepoint/raw_syscalls/sys_exit")//退出系统调用 | ||
SEC("tracepoint/raw_syscalls/sys_exit") | ||
int tracepoint__syscalls__sys_exit(struct trace_event_raw_sys_exit *args){ | ||
u64 exit_time = bpf_ktime_get_ns()/1000;//ms | ||
pid_t pid = bpf_get_current_pid_tgid() ;//获取到当前进程的pid | ||
struct sc_ctrl *sc_ctrl = get_sc_ctrl(); | ||
u64 exit_time = bpf_ktime_get_ns()/1000; | ||
pid_t pid = bpf_get_current_pid_tgid() ; | ||
u64 syscall_id; | ||
u64 start_time, delay; | ||
|
||
u64 *val = bpf_map_lookup_elem(&SyscallEnterTime, &pid); | ||
if(val !=0){ | ||
start_time = *val; | ||
|
@@ -59,27 +70,20 @@ int tracepoint__syscalls__sys_exit(struct trace_event_raw_sys_exit *args){ | |
}else{ | ||
return 0; | ||
} | ||
|
||
u64 *val2 = bpf_map_lookup_elem(&Events, &pid); | ||
if(val2 !=0){ | ||
syscall_id = *val2; | ||
bpf_map_delete_elem(&SyscallEnterTime, &pid); | ||
}else{ | ||
return 0; | ||
} | ||
|
||
|
||
struct syscall_events *e; | ||
e = bpf_ringbuf_reserve(&rb, sizeof(*e), 0); | ||
if (!e) return 0; | ||
|
||
e->pid = pid; | ||
e->delay = delay; | ||
bpf_get_current_comm(&e->comm, sizeof(e->comm)); | ||
e->syscall_id = syscall_id; | ||
|
||
bpf_ringbuf_submit(e, 0); | ||
|
||
|
||
return 0; | ||
} |
Oops, something went wrong.