#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
-struct key_t {
- struct request *req;
-};
-BPF_HASH(start, struct key_t);
+BPF_HASH(start, struct request *);
int kprobe__blk_start_request(struct pt_regs *ctx, struct request *req) {
- struct key_t key = {};
u64 ts;
// stash start timestamp by request ptr
ts = bpf_ktime_get_ns();
- key.req = req;
- start.update(&key, &ts);
+ start.update(&req, &ts);
return 0;
}
int kprobe__blk_update_request(struct pt_regs *ctx, struct request *req) {
- struct key_t key = {};
u64 *tsp, delta;
- key.req = req;
- tsp = start.lookup(&key);
+ tsp = start.lookup(&req);
if (tsp != 0) {
delta = bpf_ktime_get_ns() - *tsp;
bpf_trace_printk("%d %x %d\n", req->__data_len,
req->cmd_flags, delta / 1000);
- start.delete(&key);
+ start.delete(&req);
}
return 0;
#include <uapi/linux/ptrace.h>
-struct key_t {
- u32 pid;
-};
-
-BPF_HASH(start, struct key_t);
+BPF_HASH(start, u32);
BPF_TABLE("array", int, u64, dist, 64);
static unsigned int log2(unsigned int v)
int do_entry(struct pt_regs *ctx)
{
- struct key_t key = {};
+ u32 pid;
u64 ts, *val, zero = 0;
- key.pid = bpf_get_current_pid_tgid();
+ pid = bpf_get_current_pid_tgid();
ts = bpf_ktime_get_ns();
- start.update(&key, &ts);
+ start.update(&pid, &ts);
return 0;
}
int do_return(struct pt_regs *ctx)
{
- struct key_t key = {};
+ u32 pid;
u64 *tsp, delta;
- key.pid = bpf_get_current_pid_tgid();
- tsp = start.lookup(&key);
+ pid = bpf_get_current_pid_tgid();
+ tsp = start.lookup(&pid);
if (tsp != 0) {
delta = bpf_ktime_get_ns() - *tsp;
int index = log2l(delta / 1000);
u64 *leaf = dist.lookup(&index);
if (leaf) (*leaf)++;
- start.delete(&key);
+ start.delete(&pid);
}
return 0;