1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * ibumad BPF sample kernel side
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * Copyright(c) 2018 Ira Weiny, Intel Corporation
13 #define KBUILD_MODNAME "ibumad_count_pkts_by_class"
14 #include <uapi/linux/bpf.h>
16 #include <bpf/bpf_helpers.h>
20 __uint(type, BPF_MAP_TYPE_ARRAY);
21 __type(key, u32); /* class; u32 required */
22 __type(value, u64); /* count of mads read */
23 __uint(max_entries, 256); /* Room for all Classes */
24 } read_count SEC(".maps");
27 __uint(type, BPF_MAP_TYPE_ARRAY);
28 __type(key, u32); /* class; u32 required */
29 __type(value, u64); /* count of mads written */
30 __uint(max_entries, 256); /* Room for all Classes */
31 } write_count SEC(".maps");
36 #define bpf_printk(fmt, ...)
39 /* Taken from the current format defined in
40 * include/trace/events/ib_umad.h
42 * /sys/kernel/tracing/events/ib_umad/ib_umad_read/format
43 * /sys/kernel/tracing/events/ib_umad/ib_umad_write/format
45 struct ib_umad_rw_args {
77 SEC("tracepoint/ib_umad/ib_umad_read_recv")
78 int on_ib_umad_read_recv(struct ib_umad_rw_args *ctx)
81 u8 class = ctx->mgmt_class;
83 bpf_printk("ib_umad read recv : class 0x%x\n", class);
85 val = bpf_map_lookup_elem(&read_count, &class);
87 bpf_map_update_elem(&read_count, &class, &zero, BPF_NOEXIST);
88 val = bpf_map_lookup_elem(&read_count, &class);
97 SEC("tracepoint/ib_umad/ib_umad_read_send")
98 int on_ib_umad_read_send(struct ib_umad_rw_args *ctx)
101 u8 class = ctx->mgmt_class;
103 bpf_printk("ib_umad read send : class 0x%x\n", class);
105 val = bpf_map_lookup_elem(&read_count, &class);
107 bpf_map_update_elem(&read_count, &class, &zero, BPF_NOEXIST);
108 val = bpf_map_lookup_elem(&read_count, &class);
117 SEC("tracepoint/ib_umad/ib_umad_write")
118 int on_ib_umad_write(struct ib_umad_rw_args *ctx)
121 u8 class = ctx->mgmt_class;
123 bpf_printk("ib_umad write : class 0x%x\n", class);
125 val = bpf_map_lookup_elem(&write_count, &class);
127 bpf_map_update_elem(&write_count, &class, &zero, BPF_NOEXIST);
128 val = bpf_map_lookup_elem(&write_count, &class);
138 char _license[] SEC("license") = "GPL";