Commit f92e6683 authored by Brendan Gregg's avatar Brendan Gregg

improve and shorten BPF_HASH usage

parent c7edcd5e
......@@ -13,35 +13,28 @@
#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;
......
......@@ -13,11 +13,7 @@
#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)
......@@ -44,29 +40,29 @@ static unsigned int log2l(unsigned long 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment