ebpf的主从同步实现,QPS测试与内存池QPS测试。
This commit is contained in:
@@ -1,103 +1,80 @@
|
||||
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
|
||||
/* Copyright (c) 2020 Facebook */
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include "vmlinux.h"
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
|
||||
#include "replica.h"
|
||||
|
||||
char LICENSE[] SEC("license") = "Dual BSD/GPL";
|
||||
|
||||
int my_pid = 0;
|
||||
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
|
||||
__uint(key_size, sizeof(int));
|
||||
__uint(value_size, sizeof(int));
|
||||
} channel SEC(".maps");
|
||||
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
|
||||
__uint(key_size, sizeof(int));
|
||||
__uint(value_size, sizeof(int));
|
||||
} events SEC(".maps");
|
||||
|
||||
SEC("uprobe/kvs_create_snapshot_async")
|
||||
int uprobe_create_snapshot_async(struct pt_regs *ctx)
|
||||
/* __completed_cmd(const uint8_t *cmd, size_t len, unsigned long long seq); */
|
||||
SEC("uprobe//home/lian/share/9.1-kvstore/kvstore:__completed_cmd")
|
||||
int BPF_KPROBE(handle_completed_cmd,
|
||||
const __u8 *cmd, size_t len, __u64 seq)
|
||||
{
|
||||
struct event ev;
|
||||
__builtin_memset(&ev, 0, sizeof(ev));
|
||||
struct replica_event evt = {};
|
||||
__u32 copy_len;
|
||||
|
||||
const char *ip;
|
||||
__u32 port;
|
||||
evt.type = EVENT_COMPLETED_CMD;
|
||||
evt.complete.seq = seq;
|
||||
|
||||
ev.type = EVENT_CREATE_SNAPSHOT_ASYNC;
|
||||
copy_len = len;
|
||||
if (copy_len > MAX_CMD_LEN)
|
||||
copy_len = MAX_CMD_LEN;
|
||||
|
||||
ip = (const char *)PT_REGS_PARM1(ctx);
|
||||
port = (__u32)PT_REGS_PARM2(ctx);
|
||||
evt.complete.len = copy_len;
|
||||
|
||||
bpf_probe_read_user_str(ev.data.sync.ip,
|
||||
sizeof(ev.data.sync.ip),
|
||||
ip);
|
||||
ev.data.sync.port = port;
|
||||
if (cmd)
|
||||
bpf_probe_read_user(evt.complete.cmd, copy_len, cmd);
|
||||
|
||||
bpf_perf_event_output(ctx, &channel,
|
||||
bpf_perf_event_output(ctx, &events,
|
||||
BPF_F_CURRENT_CPU,
|
||||
&ev, sizeof(ev));
|
||||
&evt, sizeof(evt));
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("uprobe/__compeleted_cmd")
|
||||
int uprobe_completed_cmd(struct pt_regs *ctx)
|
||||
/* __ssync(const uint8_t *ip, uint32_t ip_len, int port, unsigned long long seq); */
|
||||
SEC("uprobe//home/lian/share/9.1-kvstore/kvstore:__ssync")
|
||||
int BPF_KPROBE(handle_ssync,
|
||||
const __u8 *ip, __u32 ip_len, int port, __u64 seq)
|
||||
{
|
||||
struct event ev;
|
||||
__builtin_memset(&ev, 0, sizeof(ev));
|
||||
struct replica_event evt = {};
|
||||
|
||||
const __u8 *cmd;
|
||||
__u32 len;
|
||||
evt.type = EVENT_SSYNC;
|
||||
evt.sync.seq = seq;
|
||||
evt.sync.port = port;
|
||||
|
||||
ev.type = EVENT_COMPLETED_CMD;
|
||||
__u32 copy_len = ip_len;
|
||||
if (copy_len > sizeof(evt.sync.ip))
|
||||
copy_len = sizeof(evt.sync.ip);
|
||||
|
||||
cmd = (const __u8 *)PT_REGS_PARM1(ctx);
|
||||
len = (__u32)PT_REGS_PARM2(ctx);
|
||||
if (ip)
|
||||
bpf_probe_read_user(evt.sync.ip, copy_len, ip);
|
||||
|
||||
if (len > sizeof(ev.data.cmd.cmd))
|
||||
len = sizeof(ev.data.cmd.cmd);
|
||||
|
||||
ev.data.cmd.len = len;
|
||||
|
||||
bpf_probe_read_user(ev.data.cmd.cmd, len, cmd);
|
||||
|
||||
bpf_perf_event_output(ctx, &channel,
|
||||
bpf_perf_event_output(ctx, &events,
|
||||
BPF_F_CURRENT_CPU,
|
||||
&ev, sizeof(ev));
|
||||
&evt, sizeof(evt));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
SEC("uprobe/__create_snapshot_ok")
|
||||
int uprobe_create_snapshot_ok(struct pt_regs *ctx)
|
||||
/* __sready(void); */
|
||||
SEC("uprobe//home/lian/share/9.1-kvstore/kvstore:__sready")
|
||||
int BPF_KPROBE(handle_sready)
|
||||
{
|
||||
struct event ev;
|
||||
__builtin_memset(&ev, 0, sizeof(ev));
|
||||
|
||||
const char *array_file;
|
||||
const char *rbtree_file;
|
||||
const char *hash_file;
|
||||
struct replica_event evt = {};
|
||||
|
||||
ev.type = EVENT_CREATE_SNAPSHOT_OK;
|
||||
evt.type = EVENT_SREADY;
|
||||
|
||||
array_file = (const char *)PT_REGS_PARM1(ctx);
|
||||
rbtree_file = (const char *)PT_REGS_PARM2(ctx);
|
||||
hash_file = (const char *)PT_REGS_PARM3(ctx);
|
||||
|
||||
bpf_probe_read_user_str(ev.data.ok.array_file,
|
||||
sizeof(ev.data.ok.array_file),
|
||||
array_file);
|
||||
bpf_probe_read_user_str(ev.data.ok.rbtree_file,
|
||||
sizeof(ev.data.ok.rbtree_file),
|
||||
rbtree_file);
|
||||
bpf_probe_read_user_str(ev.data.ok.hash_file,
|
||||
sizeof(ev.data.ok.hash_file),
|
||||
hash_file);
|
||||
|
||||
bpf_perf_event_output(ctx, &channel,
|
||||
bpf_perf_event_output(ctx, &events,
|
||||
BPF_F_CURRENT_CPU,
|
||||
&ev, sizeof(ev));
|
||||
&evt, sizeof(evt));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user