Skip to content

Commit

Permalink
migrate_image增加新指标
Browse files Browse the repository at this point in the history
  • Loading branch information
albertxu216 committed Jul 5, 2024
1 parent 79f5c90 commit 68f647c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ struct {
__uint(max_entries, 1024);
} migrate_info SEC(".maps");



SEC("tracepoint/sched/sched_migrate_task")
int tracepoint_sched_migrate_task(struct trace_event_raw_sched_migrate_task *args){
u64 time = bpf_ktime_get_ns();//当前转移时间点;
pid_t pid = args->pid;
struct migrate_event *migrate_event;
struct task_struct *task = (struct task_struct *)bpf_get_current_task();
struct rq *orig_rq = BPF_CORE_READ(task,se.cfs_rq,rq);
struct cfs_rq *orig_cfs = BPF_CORE_READ(task,se.cfs_rq);

bpf_printk("[se]:Pload_avg:%llu\tPutil_avg:%llu\n",BPF_CORE_READ(task,se.avg.load_avg),BPF_CORE_READ(task,se.avg.util_avg));
bpf_printk("[rq]: nr_running :%d cpu_capacity : %ld cpu_capacity_orig : %ld\n",
BPF_CORE_READ(orig_rq,cpu),BPF_CORE_READ(orig_rq,nr_running),
BPF_CORE_READ(orig_rq,cpu_capacity),BPF_CORE_READ(orig_rq,cpu_capacity_orig));
bpf_printk("Cload_avg:%ld\n",BPF_CORE_READ(orig_cfs,avg.runnable_avg));
migrate_event = bpf_map_lookup_elem(&migrate,&pid);
if(!migrate_event){
struct migrate_event migrate_event = {};
Expand All @@ -57,7 +63,12 @@ int tracepoint_sched_migrate_task(struct trace_event_raw_sched_migrate_task *arg
per_migrate.time = time;
per_migrate.orig_cpu = args->orig_cpu;
per_migrate.dest_cpu = args->dest_cpu;
bpf_printk("load_avg:%llu\tutil_avg:%llu\n",BPF_CORE_READ(task,se.avg.load_avg),BPF_CORE_READ(task,se.avg.util_avg));

per_migrate.cpu_capacity = BPF_CORE_READ(orig_rq,cpu_capacity);
per_migrate.cpu_capacity_orig = BPF_CORE_READ(orig_rq,cpu_capacity_orig);
per_migrate.cpu_load_avg = BPF_CORE_READ(orig_cfs,avg.runnable_avg);


per_migrate.pload_avg = BPF_CORE_READ(task,se.avg.load_avg);//进程的量化负载;
per_migrate.putil_avg = BPF_CORE_READ(task,se.avg.util_avg);//进程的实际算力;
per_migrate.mem_usage = BPF_CORE_READ(task,mm,total_vm) << PAGE_SHIFT;
Expand All @@ -82,6 +93,11 @@ int tracepoint_sched_migrate_task(struct trace_event_raw_sched_migrate_task *arg
per_migrate.time = time;
per_migrate.orig_cpu = args->orig_cpu;
per_migrate.dest_cpu = args->dest_cpu;

per_migrate.cpu_capacity = BPF_CORE_READ(orig_rq,cpu_capacity);
per_migrate.cpu_capacity_orig = BPF_CORE_READ(orig_rq,cpu_capacity_orig);
per_migrate.cpu_load_avg = BPF_CORE_READ(orig_cfs,avg.runnable_avg);

per_migrate.pload_avg = BPF_CORE_READ(task,se.avg.load_avg);//进程的量化负载;
per_migrate.putil_avg = BPF_CORE_READ(task,se.avg.util_avg);//进程的实际算力;
per_migrate.mem_usage = BPF_CORE_READ(task,mm,total_vm) << PAGE_SHIFT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va
static int migrate_print(){
time_t now = time(NULL);// 获取当前时间
struct tm *localTime = localtime(&now);// 将时间转换为本地时间结构
printf("Time: %02d:%02d:%02d\n",localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
printf("---------------------------------------------------------------------------------\n");
printf("\nTime: %02d:%02d:%02d\n",localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
printf("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
int err,migrate_fd =bpf_map__fd(skel->maps.migrate),migrate_info_fd =bpf_map__fd(skel->maps.migrate_info);

pid_t lookup_key = -1 ,next_key;
Expand All @@ -144,6 +144,7 @@ static int migrate_print(){
}
u64 last_time_stamp = 0;
printf("\npid:%d\tprio:%d\tcount:%d\trear:%d\n",migrate_event.pid,migrate_event.prio,migrate_event.count,migrate_event.rear);
printf("---------------------------------------------------------------------------------\n");
for(int i=migrate_event.rear;i<=migrate_event.count;i++){
struct per_migrate migrate_info;
struct minfo_key mkey;
Expand All @@ -154,9 +155,10 @@ static int migrate_print(){
fprintf(stderr, "failed to lookup infos err %d mkey_pid: %d mkey_count: %d\n", err,mkey.pid,i);
continue;
}
printf("time_stamp:%llu\t%d->%d\tpload_avg:%llu\tputil_avg:%llu\t",
printf("time_stamp:%llu\t%d->%d \t PROC_LOAD:%llu \t PROC_UTIL:%llu\t",
migrate_info.time,migrate_info.orig_cpu,migrate_info.dest_cpu,migrate_info.pload_avg,migrate_info.putil_avg);
printf("mmem_usage:%llu kb\tread:%llu kb\twite:%llu kb\tcontext_switch:%llu\t",
printf("CPU_LOAD: %ld \t Cpu_Capacity:[%ld:%ld] \t ",migrate_info.cpu_load_avg,migrate_info.cpu_capacity,migrate_info.cpu_capacity_orig);
printf("mmem_usage:%llu kb \t\t read:%llu kb \t\t wite:%llu kb \t\t context_switch:%llu\t",
migrate_info.mem_usage/1024,migrate_info.read_bytes/1024,migrate_info.write_bytes/1024,
migrate_info.context_switches);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ struct per_migrate{//每次迁移,记录该次迁移信息;
u64 time;
u32 orig_cpu;
u32 dest_cpu;
u64 orig_cpu_load;

u64 orig_cpu_load;//cfs->avg.runnale_avg 就绪队列所有调度实体;量化负载总和
u64 dest_cpu_load;
int cpu_capacity;//计算机算力
int cpu_capacity_orig;//额定算力
u64 cpu_load_avg;
u64 pload_avg;
u64 putil_avg;

int on_cpu;
u64 mem_usage;
u64 read_bytes;
Expand Down

0 comments on commit 68f647c

Please sign in to comment.