diff --git a/src/probes/extends/ebpf.probe/src/include/__bpf_kern.h b/src/probes/extends/ebpf.probe/src/include/__bpf_kern.h index 3e2b8f22f75e6e24375affe83b37eeea29abb7ae..46264c7f5efd5cc0d95b0d8f4faaa2f3212d5758 100644 --- a/src/probes/extends/ebpf.probe/src/include/__bpf_kern.h +++ b/src/probes/extends/ebpf.probe/src/include/__bpf_kern.h @@ -125,8 +125,6 @@ static __always_inline __maybe_unused char is_compat_task(struct task_struct *ta #endif - - static __always_inline __maybe_unused struct sock *sock_get_by_fd(int fd, struct task_struct *task) { struct files_struct *files = _(task->files); @@ -155,9 +153,8 @@ static __always_inline __maybe_unused struct sock *sock_get_by_fd(int fd, struct return sk; } -#define KPROBE_RET(func, type, caller_type) \ - bpf_section("kprobe/" #func) \ - void __kprobe_bpf_##func(struct type *ctx) { \ +#define KPROBE_PARMS_STASH(func, ctx, caller_type) \ + do { \ int ret; \ struct __probe_key __key = {0}; \ struct __probe_val __val = {0}; \ @@ -172,6 +169,12 @@ static __always_inline __maybe_unused struct sock *sock_get_by_fd(int fd, struct if (ret < 0) { \ bpf_printk("---KPROBE_RET[" #func "] push failed.\n"); \ } \ + } while (0) + +#define KPROBE_RET(func, type, caller_type) \ + bpf_section("kprobe/" #func) \ + void __kprobe_bpf_##func(struct type *ctx) { \ + KPROBE_PARMS_STASH(func, ctx, caller_type); \ } \ \ bpf_section("kretprobe/" #func) \ diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/Makefile b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/Makefile index 72dffc989ff42f01e48c69395334d690f3f928d9..f79225a0b77eaf9e89c3c7bbd733f640dd68c707 100644 --- a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/Makefile +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/Makefile @@ -2,6 +2,7 @@ include ../mk/var.mk INCLUDES = $(BASE_INC) APP := opengauss_sli +TC_BPF := tc_tstamp.bpf.o SRC_CPLUS := $(wildcard *.cpp) SRC_CPLUS += $(CPLUSFILES) @@ -42,3 +43,4 @@ clean: install: mkdir -p $(INSTALL_DIR) cp $(APP) $(INSTALL_DIR) + cp $(TC_BPF) $(INSTALL_DIR) \ No newline at end of file diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_kprobe.bpf.c b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_kprobe.bpf.c index d8cec819b32e1789b4035a2d1db2153ae75df9f7..5bd5d65cf13b95c4d0957c1337dd2c47373b2b71 100644 --- a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_kprobe.bpf.c +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_kprobe.bpf.c @@ -23,6 +23,8 @@ #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) +#define LO_IPADDR 16777343 // 127.0.0.1 + char g_license[] SEC("license") = "GPL"; static __always_inline int init_conn_info(struct conn_info_t *conn_info, struct sock *sk) @@ -31,6 +33,9 @@ static __always_inline int init_conn_info(struct conn_info_t *conn_info, struct if (conn_info->client_ip_info.family == AF_INET) { conn_info->server_ip_info.ipaddr.ip4 = _(sk->sk_rcv_saddr); conn_info->client_ip_info.ipaddr.ip4 = _(sk->sk_daddr); + if (conn_info->server_ip_info.ipaddr.ip4 == LO_IPADDR && conn_info->client_ip_info.ipaddr.ip4 == LO_IPADDR) { + return SLI_ERR; + } } else if (conn_info->client_ip_info.family == AF_INET6) { bpf_probe_read(conn_info->server_ip_info.ipaddr.ip6, IP6_LEN, &sk->sk_v6_rcv_saddr); bpf_probe_read(conn_info->client_ip_info.ipaddr.ip6, IP6_LEN, &sk->sk_v6_daddr); @@ -80,6 +85,8 @@ KPROBE(__sys_recvfrom, pt_regs) return; } + KPROBE_PARMS_STASH(__sys_recvfrom, ctx, CTX_USER); + struct conn_key_t conn_key = {.fd = fd, .tgid = tgid}; struct conn_data_t *conn_data = (struct conn_data_t *)bpf_map_lookup_elem(&conn_map, &conn_key); if (conn_data != NULL && conn_data->sk != NULL) { @@ -87,6 +94,33 @@ KPROBE(__sys_recvfrom, pt_regs) } (void)update_conn_map_n_conn_samp_map(&conn_key); + return; +} + +KRETPROBE(__sys_recvfrom, pt_regs) +{ + u32 tgid __maybe_unused = bpf_get_current_pid_tgid() >> INT_LEN; + struct probe_val val; + if (PROBE_GET_PARMS(__sys_recvfrom, ctx, val, CTX_USER) < 0) { + return; + } + + int fd = (int)PROBE_PARM1(val); + const char *buf = (const char *)PROBE_PARM2(val); + int count = (int)PROBE_PARM3(val); + + process_rdwr_msg(fd, buf, count, MSG_READ, ctx); + + return; +} + +KPROBE(__sys_sendto, pt_regs) +{ + u32 tgid __maybe_unused = bpf_get_current_pid_tgid() >> INT_LEN; + int fd = (int)PT_REGS_PARM1(ctx); + char *buf = (char *)PT_REGS_PARM2(ctx); + int count = (int)PT_REGS_PARM3(ctx); + process_rdwr_msg(fd, buf, count, MSG_WRITE, ctx); return; } @@ -150,7 +184,6 @@ KPROBE(tcp_clean_rtx_queue, pt_regs) return; } csd->rtt_ts_nsec = end_ts_nsec - csd->start_ts_nsec; - csd->start_ts_nsec = 0; csd->status = SAMP_FINISHED; } } @@ -165,8 +198,7 @@ KPROBE(tcp_recvmsg, pt_regs) csd = (struct conn_samp_data_t *)bpf_map_lookup_elem(&conn_samp_map, &sk); if (csd != (void *)0) { - if ((csd->status == SAMP_FINISHED || csd->status == SAMP_INIT) - && (csd->start_ts_nsec == 0)) { + if ((csd->status == SAMP_FINISHED || csd->status == SAMP_INIT)) { if (sk != (void *)0) { struct sk_buff *skb = _(sk->sk_receive_queue.next); if (skb != (struct sk_buff *)(&sk->sk_receive_queue)){ diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_uprobe.bpf.c b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_uprobe.bpf.c index 735179a0c67a46f432aed47cda0b5bdd3d0b9bb0..dc98c409215f5f7ea825ff9f4464db3592896579 100644 --- a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_uprobe.bpf.c +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/ogsli_uprobe.bpf.c @@ -24,23 +24,11 @@ char g_license[] SEC("license") = "GPL"; -#define BPF_F_INDEX_MASK 0xffffffffULL -#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK - -#ifndef __PERIOD -#define __PERIOD NS(30) -#endif - enum { PROG_SSL_READ = 0, PROG_SSL_WRITE, }; -enum msg_event_rw_t { - MSG_READ, // 读消息事件 - MSG_WRITE, // 写消息事件 -}; - // ssl struct in opennssl 1.1.1 typedef long (*bio_callback_fn)(); struct ssl_method_st {}; @@ -64,11 +52,6 @@ struct ssl_st { struct bio_st *wbio; // used by SSL_write }; // end of ssl struct in opennssl 1.1.1 -struct bpf_map_def SEC("maps") msg_event_map = { - .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, - .key_size = sizeof(u32), - .value_size = sizeof(u32), -}; static __always_inline int get_fd_from_ssl(struct ssl_st* ssl_st_p, enum msg_event_rw_t rw_type) { @@ -87,151 +70,6 @@ static __always_inline int get_fd_from_ssl(struct ssl_st* ssl_st_p, enum msg_eve return fd; } -static __always_inline char read_first_byte_from_buf(const char *ori_buf, int ori_len) -{ - char msg[MAX_MSG_LEN_SSL] = {0}; - const char *buf; - int len; - - if (ori_len < 0 || ori_buf == NULL) { - return 0; - } - bpf_probe_read(&buf, sizeof(const char*), &ori_buf); - len = ori_len < MAX_MSG_LEN_SSL ? (ori_len & (MAX_MSG_LEN_SSL - 1)) : MAX_MSG_LEN_SSL; - bpf_probe_read_user(msg, len, buf); - - // case 'd': copy data - // case 'R': Reply collect info - if (msg[0] < 'A' || msg[0] >'z' || msg[0] == 'd' || msg[0] == 'R') { - //if (!(msg[0] == 'Q' || msg[0] == 'P')) { - return 0; - } - return msg[0]; -} - -static __always_inline void sample_finished(struct conn_data_t *conn_data, struct conn_samp_data_t *csd) -{ - if (conn_data->latency.rtt_nsec == 0) { - conn_data->latency.rtt_nsec = csd->rtt_ts_nsec; - conn_data->latency.req_cmd = csd->req_cmd; - conn_data->latency.rsp_cmd = csd->rsp_cmd; - } - if (conn_data->max.rtt_nsec < csd->rtt_ts_nsec) { - conn_data->max.rtt_nsec = csd->rtt_ts_nsec; - conn_data->max.req_cmd = csd->req_cmd; - conn_data->max.rsp_cmd = csd->rsp_cmd; - } - csd->status = SAMP_INIT; -} - -static __always_inline u64 get_period() -{ - u32 key = 0; - u64 period = __PERIOD; - - struct ogsli_args_s *args; - args = (struct ogsli_args_s *)bpf_map_lookup_elem(&args_map, &key); - if (args) { - period = args->period; - } - - return period; // units from second to nanosecond -} - -static __always_inline void periodic_report(u64 ts_nsec, struct conn_data_t *conn_data, - struct conn_key_t *conn_key, struct pt_regs *ctx) -{ - long err; - u64 period = get_period(); - // 表示没有任何采样数据,不上报 - if (conn_data->latency.rtt_nsec == 0) { - return; - } - - if (ts_nsec > conn_data->last_report_ts_nsec && - ts_nsec - conn_data->last_report_ts_nsec >= period) { - // rtt larger than period is considered an invalid value - if (conn_data->latency.rtt_nsec < period && conn_data->max.rtt_nsec < period) { - struct msg_event_data_t msg_evt_data = {0}; - msg_evt_data.tgid = conn_key->tgid; - msg_evt_data.fd = conn_key->fd; - msg_evt_data.conn_info = conn_data->conn_info; - msg_evt_data.latency = conn_data->latency; - msg_evt_data.max = conn_data->max; - err = bpf_perf_event_output(ctx, &msg_event_map, BPF_F_CURRENT_CPU, - &msg_evt_data, sizeof(struct msg_event_data_t)); - if (err < 0) { - bpf_printk("message event sent failed.\n"); - } - } - conn_data->latency.rtt_nsec = 0; - conn_data->max.rtt_nsec = 0; - conn_data->last_report_ts_nsec = ts_nsec; - } - - return; -} - -static __always_inline void process_rdwr_msg(int fd, const char *buf, int count, enum msg_event_rw_t rw_type, - struct pt_regs *ctx) -{ - u32 tgid = bpf_get_current_pid_tgid() >> INT_LEN; - u64 ts_nsec = bpf_ktime_get_ns(); - struct conn_samp_data_t *csd; - if (count <= 0) { - return; - } - struct conn_key_t conn_key = {.fd = fd, .tgid = tgid}; - struct conn_data_t *conn_data = (struct conn_data_t *)bpf_map_lookup_elem(&conn_map, &conn_key); - if (conn_data == NULL) { - return; - } - - csd = (struct conn_samp_data_t *)bpf_map_lookup_elem(&conn_samp_map, &conn_data->sk); - if (csd == NULL) { - return; - } - - char cmd = read_first_byte_from_buf(buf, count); - if (cmd == 0) { - return; - } - - if (rw_type == MSG_READ) { // MSG_READ - if (csd->status == SAMP_FINISHED) { - sample_finished(conn_data, csd); - } - - // 周期上报 - periodic_report(ts_nsec, conn_data, &conn_key, ctx); - - if (csd->status != SAMP_INIT) { - // 超过采样周期,则重置采样状态,避免采样状态一直处于不可达的情况 - if (ts_nsec > csd->start_ts_nsec && - ts_nsec - csd->start_ts_nsec >= __PERIOD) { - csd->status = SAMP_INIT; - csd->start_ts_nsec = 0; - } - return; - } - - csd->req_cmd = cmd; -#ifndef KERNEL_SUPPORT_TSTAMP - if (csd->start_ts_nsec == 0) { - csd->start_ts_nsec = ts_nsec; - } -#endif - csd->status = SAMP_READ_READY; - } else { // MSG_WRITE - csd->rsp_cmd = cmd; - if (csd->status == SAMP_READ_READY) { - csd->status = SAMP_WRITE_READY; - } - } - - return; -} - UPROBE(SSL_read, pt_regs) { UPROBE_PARMS_STASH(SSL_read, ctx, PROG_SSL_READ); diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_bpf.h b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_bpf.h index 653ad550f3561375a89553e0546e7ef7d53ddebc..341dc0dae280378196c655ad465890873ca0823d 100644 --- a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_bpf.h +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_bpf.h @@ -15,10 +15,25 @@ #ifndef __OPENGAUSS_BPF_H__ #define __OPENGAUSS_BPF_H__ +#if ((CURRENT_KERNEL_VERSION == KERNEL_VERSION(4, 18, 0)) || (CURRENT_KERNEL_VERSION >= KERNEL_VERSION(5, 10, 0))) +#define KERNEL_SUPPORT_TSTAMP +#endif + +#ifndef __PERIOD +#define __PERIOD NS(30) +#endif + #define MAX_MSG_LEN_SSL 32 #define MAX_COMMAND_REQ_SIZE (32 - 1) #define MAX_CONN_LEN 8192 +#define BPF_F_INDEX_MASK 0xffffffffULL +#define BPF_F_ALL_CPU BPF_F_INDEX_MASK + +#ifndef __PERF_OUT_MAX +#define __PERF_OUT_MAX (64) +#endif + enum samp_status_t { SAMP_INIT = 0, SAMP_READ_READY, @@ -27,6 +42,11 @@ enum samp_status_t { SAMP_FINISHED, }; +enum msg_event_rw_t { + MSG_READ, // 读消息事件 + MSG_WRITE, // 写消息事件 +}; + struct conn_key_t { __u32 tgid; int fd; @@ -71,4 +91,158 @@ struct bpf_map_def SEC("maps") conn_samp_map = { .max_entries = MAX_CONN_LEN, }; +struct bpf_map_def SEC("maps") output = { + .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, + .key_size = sizeof(u32), + .value_size = sizeof(u32), + .max_entries = __PERF_OUT_MAX, +}; + +static __always_inline void sample_finished(struct conn_data_t *conn_data, struct conn_samp_data_t *csd) +{ + if (conn_data->latency.rtt_nsec == 0) { + conn_data->latency.rtt_nsec = csd->rtt_ts_nsec; + conn_data->latency.req_cmd = csd->req_cmd; + conn_data->latency.rsp_cmd = csd->rsp_cmd; + } + if (conn_data->max.rtt_nsec < csd->rtt_ts_nsec) { + conn_data->max.rtt_nsec = csd->rtt_ts_nsec; + conn_data->max.req_cmd = csd->req_cmd; + conn_data->max.rsp_cmd = csd->rsp_cmd; + } + csd->status = SAMP_INIT; +} + +static __always_inline u64 get_period() +{ + u32 key = 0; + u64 period = __PERIOD; + + struct ogsli_args_s *args; + args = (struct ogsli_args_s *)bpf_map_lookup_elem(&args_map, &key); + if (args) { + period = args->period; + } + + return period; // units from second to nanosecond +} + + +static __always_inline char read_first_byte_from_buf(const char *ori_buf, int ori_len) +{ + char msg[MAX_MSG_LEN_SSL] = {0}; + const char *buf; + int len; + + if (ori_buf == NULL) { + return 0; + } + bpf_probe_read(&buf, sizeof(const char*), &ori_buf); + len = ori_len < MAX_MSG_LEN_SSL ? (ori_len & (MAX_MSG_LEN_SSL - 1)) : MAX_MSG_LEN_SSL; + bpf_probe_read_user(msg, len, buf); + + if (msg[0] < '0' || msg[0] >'z') { + return 0; + } + return msg[0]; +} + +static __always_inline void periodic_report(u64 ts_nsec, struct conn_data_t *conn_data, + struct conn_key_t *conn_key, struct pt_regs *ctx) +{ + long err; + u64 period = get_period(); + // 表示没有任何采样数据,不上报 + if (conn_data->latency.rtt_nsec == 0) { + return; + } + + if (ts_nsec > conn_data->last_report_ts_nsec && + ts_nsec - conn_data->last_report_ts_nsec >= period) { + // rtt larger than period is considered an invalid value + if (conn_data->latency.rtt_nsec < period && conn_data->max.rtt_nsec < period) { + struct msg_event_data_t msg_evt_data = {0}; + msg_evt_data.tgid = conn_key->tgid; + msg_evt_data.fd = conn_key->fd; + msg_evt_data.conn_info = conn_data->conn_info; + msg_evt_data.latency = conn_data->latency; + msg_evt_data.max = conn_data->max; + err = bpf_perf_event_output(ctx, &output, BPF_F_ALL_CPU, + &msg_evt_data, sizeof(struct msg_event_data_t)); + if (err < 0) { + bpf_printk("message event sent failed.\n"); + } + } + conn_data->latency.rtt_nsec = 0; + conn_data->max.rtt_nsec = 0; + conn_data->last_report_ts_nsec = ts_nsec; + } + + return; +} + +static __always_inline void process_rdwr_msg(int fd, const char *buf, int count, enum msg_event_rw_t rw_type, + struct pt_regs *ctx) +{ + u32 tgid = bpf_get_current_pid_tgid() >> INT_LEN; + u64 ts_nsec = bpf_ktime_get_ns(); + char cmd; + struct conn_samp_data_t *csd; + if (count <= 0) { + return; + } + + struct conn_key_t conn_key = {.fd = fd, .tgid = tgid}; + struct conn_data_t *conn_data = (struct conn_data_t *)bpf_map_lookup_elem(&conn_map, &conn_key); + if (conn_data == NULL) { + return; + } + + csd = (struct conn_samp_data_t *)bpf_map_lookup_elem(&conn_samp_map, &conn_data->sk); + if (csd == NULL) { + return; + } + + if (rw_type == MSG_READ) { // MSG_READ + if (csd->status == SAMP_READ_READY) { + return; + } + if (csd->status == SAMP_FINISHED) { + sample_finished(conn_data, csd); + } + + // 周期上报 + periodic_report(ts_nsec, conn_data, &conn_key, ctx); + + if (csd->status != SAMP_INIT) { + // 超过采样周期,则重置采样状态,避免采样状态一直处于不可达的情况 + if (ts_nsec > csd->start_ts_nsec && + ts_nsec - csd->start_ts_nsec >= __PERIOD) { + csd->status = SAMP_INIT; + } + return; + } + cmd = read_first_byte_from_buf(buf, count); + if (cmd == 0) { + return; + } + csd->req_cmd = cmd; +#ifndef KERNEL_SUPPORT_TSTAMP + csd->start_ts_nsec = ts_nsec; +#endif + csd->status = SAMP_READ_READY; + } else { // MSG_WRITE + if (csd->status == SAMP_READ_READY) { + cmd = read_first_byte_from_buf(buf, count); + if (cmd == 0) { + return; + } + csd->status = SAMP_WRITE_READY; + csd->rsp_cmd = cmd; + } + } + + return; +} + #endif \ No newline at end of file diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.c b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.c index b000a93fe7508e36ebd7f57680952fcc5235fe7a..d42523b038496ae163c3549a40f99d586b4c8a56 100644 --- a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.c +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.c @@ -47,6 +47,7 @@ #define OPENGAUSS_ARGS_PATH "/sys/fs/bpf/probe/__opengauss_args" #define OPENGAUSS_CONN_PATH "/sys/fs/bpf/probe/__opengauss_conn" #define OPENGAUSS_CONN_SAMP_PATH "/sys/fs/bpf/probe/__opengauss_conn_samp" +#define OPENGAUSS_OUTPUT_PATH "/sys/fs/bpf/probe/__opengauss_output" #define RM_OPENGAUSS_PATH "/usr/bin/rm -rf /sys/fs/bpf/probe/__opengauss*" @@ -55,6 +56,7 @@ MAP_SET_PIN_PATH(probe_name, args_map, OPENGAUSS_ARGS_PATH, load); \ MAP_SET_PIN_PATH(probe_name, conn_map, OPENGAUSS_CONN_PATH, load); \ MAP_SET_PIN_PATH(probe_name, conn_samp_map, OPENGAUSS_CONN_SAMP_PATH, load); \ + MAP_SET_PIN_PATH(probe_name, output, OPENGAUSS_OUTPUT_PATH, load); \ LOAD_ATTACH(probe_name, end, load) static volatile sig_atomic_t stop; @@ -373,6 +375,12 @@ int main(int argc, char **argv) } printf("arg parse interval time:%us\n", params.period); +#ifdef KERNEL_SUPPORT_TSTAMP + load_tc_bpf(params.netcard_list, TC_TSTAMP_PROG, TC_TYPE_INGRESS); +#else + printf("The kernel version does not support loading the tc tstamp program\n"); +#endif + fp = popen(RM_OPENGAUSS_PATH, "r"); if (fp != NULL) { (void)pclose(fp); @@ -424,7 +432,7 @@ int main(int argc, char **argv) clear_invalid_bpf_link(); if (init == 0) { load_args(GET_MAP_FD(ogsli_kprobe, args_map), ¶ms); - err = init_conn_mgt_process(GET_MAP_FD(ogsli_uprobe, msg_event_map)); + err = init_conn_mgt_process(GET_MAP_FD(ogsli_kprobe, output)); if (err != 0) { fprintf(stderr, "Init connection management process failed.\n"); goto init_err; @@ -434,12 +442,13 @@ int main(int argc, char **argv) sleep(params.period); } - - init_err: clear_all_bpf_link(); UNLOAD(ogsli_uprobe); init_k_err: UNLOAD(ogsli_kprobe); +#ifdef KERNEL_SUPPORT_TSTAMP + offload_tc_bpf(TC_TYPE_INGRESS); +#endif return -err; } diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.h b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.h index 26d2974eb5e3e59bbd1ca268b9b988c2433b4a4c..ed3860b0ce5ba3e5f436b863d6f5eca9a894d92a 100644 --- a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.h +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/opengauss_sli.h @@ -15,6 +15,8 @@ #ifndef __OPENGAUSS_SLI_H__ #define __OPENGAUSS_SLI_H__ +#define TC_PROG "tc_tstamp.bpf.o" + #define SLI_OK 0 #define SLI_ERR (-1) diff --git a/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/tc_tstamp.bpf.c b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/tc_tstamp.bpf.c new file mode 100644 index 0000000000000000000000000000000000000000..2ba5634a319efb4dd8137b9fdd9f023dadec8239 --- /dev/null +++ b/src/probes/extends/ebpf.probe/src/opengauss_sliprobe/tc_tstamp.bpf.c @@ -0,0 +1,31 @@ +/****************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * gala-gopher licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: wo_cow + * Create: 2022-5-13 + * Description: tc bpf prog + ******************************************************************************/ +#ifdef BPF_PROG_USER +#undef BPF_PROG_USER +#endif +#define BPF_PROG_KERN +#include "bpf.h" +#include + +SEC("tc") +int get_start_ts(struct __sk_buff *skb) +{ +#ifdef KERNEL_SUPPORT_TSTAMP + skb->tstamp = bpf_ktime_get_ns(); +#endif + return 0; +} + +char g_license[] SEC("license") = "GPL";