|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +#include <linux/bpf.h> |
| 3 | +#include <bpf/bpf_helpers.h> |
| 4 | +#include <bpf/bpf_tracing.h> |
| 5 | +#include <linux/blkdev.h> |
| 6 | +#define __TARGET_ARCH_aarch64 |
| 7 | +#define u64 unsigned long long |
| 8 | + |
| 9 | +struct { |
| 10 | + __uint(type, BPF_MAP_TYPE_HASH); |
| 11 | + __uint(max_entries, 10240); |
| 12 | + __type(key, struct request *); |
| 13 | + __type(value, u64); |
| 14 | +} start SEC(".maps"); |
| 15 | + |
| 16 | +SEC("kprobe/blk_start_request") |
| 17 | +int BPF_KPROBE(trace_start_req, struct request *req) |
| 18 | +{ |
| 19 | + u64 ts = bpf_ktime_get_ns(); |
| 20 | + bpf_map_update_elem(&start, &req, &ts, BPF_ANY); |
| 21 | + return 0; |
| 22 | +} |
| 23 | + |
| 24 | +SEC("kprobe/blk_mq_start_request") |
| 25 | +int BPF_KPROBE(trace_start_mq, struct request *req) |
| 26 | +{ |
| 27 | + u64 ts = bpf_ktime_get_ns(); |
| 28 | + bpf_map_update_elem(&start, &req, &ts, BPF_ANY); |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | +SEC("kprobe/blk_account_io_completion") |
| 33 | +int BPF_KPROBE(trace_completion, struct request *req) |
| 34 | +{ |
| 35 | + u64 *tsp, delta; |
| 36 | + |
| 37 | + tsp = bpf_map_lookup_elem(&start, &req); |
| 38 | + if (tsp) { |
| 39 | + delta = bpf_ktime_get_ns() - *tsp; |
| 40 | + bpf_printk("%d %x %d\n", req->__data_len, |
| 41 | + req->cmd_flags, delta / 1000); |
| 42 | + bpf_map_delete_elem(&start, &req); |
| 43 | + } |
| 44 | + return 0; |
| 45 | +} |
| 46 | + |
| 47 | +char LICENSE[] SEC("license") = "GPL"; |
0 commit comments