Skip to content

Commit

Permalink
mq_delay 增加对发送&&接收时延的监测
Browse files Browse the repository at this point in the history
  • Loading branch information
albertxu216 committed Mar 29, 2024
1 parent d2e19fa commit 05b4754
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
18 changes: 12 additions & 6 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,22 @@ static int mq_event(void *ctx, void *data,unsigned long data_sz)
time_t now = time(NULL);// 获取当前时间
struct tm *localTime = localtime(&now);// 将时间转换为本地时间结构
printf("\n\nTime: %02d:%02d:%02d\n",localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
printf("-----------------------------------------------------------------------------------------------------------\n");
printf("-----------------------------------------------------------------------------------------------------------------------\n");
const struct mq_events *e = data;

printf("Mqdes: %-8llu msg_len: %-8llu msg_prio: %-8llu\n",e->mqdes,e->msg_len,e->msg_prio);
printf("SND_PID: %-8lu SND_enter_time: %-16llu\n",
e->send_pid,e->send_enter_time);
printf("-----------------------------------------------------------------------------------------------------------\n");
printf("SND_PID: %-8lu SND_enter_time: %-16llu SND_exit_time: %-16llu\n",
e->send_pid,e->send_enter_time,e->send_exit_time);
printf("RCV_PID: %-8lu RCV_enter_time: %-16llu RCV_exit_time: %-16llu\n",
e->rcv_pid,e->rcv_enter_time,e->rcv_exit_time);
printf("RCV_Delay: %-8.2fms\nDelay: %-8.2fms\n\n",(e->rcv_exit_time - e->rcv_enter_time)/1000000.0,e->delay/1000000.0);

printf("-------------------------------------------------------------------------------\n");

printf("SND_Delay/ms: %-8.2f RCV_Delay/ms: %-8.2f Delay/ms: %-8.5f\n",
(e->send_exit_time - e->send_enter_time)/1000000.0,
(e->rcv_exit_time - e->rcv_enter_time)/1000000.0,
(e->rcv_exit_time - e->send_enter_time)/1000000.0);
printf("-----------------------------------------------------------------------------------------------------------------------\n\n");

return 0;
}

Expand Down
4 changes: 0 additions & 4 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,8 @@ struct mq_events {

u64 send_enter_time;
u64 send_exit_time;
u64 send_delay;

u64 rcv_enter_time;
u64 rcv_exit_time;
u64 rcv_delay;
u64 delay;
};
struct send_events {
int send_pid;
Expand Down
46 changes: 23 additions & 23 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/mq_delay.bpf.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
// Copyright 2024 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]


#include "vmlinux.h"
#include <bpf/bpf_helpers.h> //包含了BPF 辅助函数
#include <bpf/bpf_tracing.h>
Expand Down Expand Up @@ -116,9 +99,30 @@ int BPF_KRETPROBE(load_msg_exit,void *ret){
}
/*已经获得key*/
bpf_map_update_elem(&send_msg2, &Key_msg_ptr, mq_send_info, BPF_ANY);//key_messege->mq_send_info;
bpf_map_delete_elem(&send_msg1,&pid);
return 0;
}

SEC("kretprobe/do_mq_timedsend")
int BPF_KRETPROBE(do_mq_timedsend_exit,void *ret)
{
bpf_printk("do_mq_timedsend_exit----------------------------------------------------------------\n");
u64 send_exit_time = bpf_ktime_get_ns();//开始发送信息时间;
int pid = bpf_get_current_pid_tgid();//发送端pid
u64 Key;

struct send_events *mq_send_info1 = bpf_map_lookup_elem(&send_msg1, &pid);
if(!mq_send_info1){
return 0;
}
Key = mq_send_info1->Key_msg_ptr;
struct send_events *mq_send_info2 = bpf_map_lookup_elem(&send_msg2, &Key);
if(!mq_send_info2){
return 0;
}
mq_send_info2->send_exit_time = send_exit_time;
bpf_map_delete_elem(&send_msg1,&pid);
return 0;
}
/*-----------------------------------------------------------------------------发送端--------------------------------------------------------------------------------------------------------*/
/* 分界 */
/*-----------------------------------------------------------------------------接收端--------------------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -188,9 +192,6 @@ int BPF_KRETPROBE(do_mq_timedreceive_exit,void *ret){
return 0;
}

send_enter_time = mq_send_info->send_enter_time;
delay = rcv_exit_time - send_enter_time;

/*ringbuffer传值*/
struct mq_events *e;
e = bpf_ringbuf_reserve(&rb, sizeof(*e), 0);
Expand All @@ -202,10 +203,9 @@ int BPF_KRETPROBE(do_mq_timedreceive_exit,void *ret){
e->msg_prio = mq_send_info->msg_prio;

e->send_enter_time = mq_send_info->send_enter_time;

e->send_exit_time = mq_send_info->send_exit_time;
e->rcv_enter_time = mq_rcv_info->rcv_enter_time;
e->rcv_exit_time = rcv_exit_time;
e->delay = delay;
bpf_ringbuf_submit(e, 0);
bpf_map_delete_elem(&send_msg2, &Key);//暂时性删除
bpf_map_delete_elem(&rcv_msg1,&pid);//删除rcv_msg1 map;
Expand Down

0 comments on commit 05b4754

Please sign in to comment.