0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #define KBUILD_MODNAME "ibumad_count_pkts_by_class"
0014 #include <uapi/linux/bpf.h>
0015
0016 #include <bpf/bpf_helpers.h>
0017
0018
0019 struct {
0020 __uint(type, BPF_MAP_TYPE_ARRAY);
0021 __type(key, u32);
0022 __type(value, u64);
0023 __uint(max_entries, 256);
0024 } read_count SEC(".maps");
0025
0026 struct {
0027 __uint(type, BPF_MAP_TYPE_ARRAY);
0028 __type(key, u32);
0029 __type(value, u64);
0030 __uint(max_entries, 256);
0031 } write_count SEC(".maps");
0032
0033 #undef DEBUG
0034 #ifndef DEBUG
0035 #undef bpf_printk
0036 #define bpf_printk(fmt, ...)
0037 #endif
0038
0039
0040
0041
0042
0043
0044
0045 struct ib_umad_rw_args {
0046 u64 pad;
0047 u8 port_num;
0048 u8 sl;
0049 u8 path_bits;
0050 u8 grh_present;
0051 u32 id;
0052 u32 status;
0053 u32 timeout_ms;
0054 u32 retires;
0055 u32 length;
0056 u32 qpn;
0057 u32 qkey;
0058 u8 gid_index;
0059 u8 hop_limit;
0060 u16 lid;
0061 u16 attr_id;
0062 u16 pkey_index;
0063 u8 base_version;
0064 u8 mgmt_class;
0065 u8 class_version;
0066 u8 method;
0067 u32 flow_label;
0068 u16 mad_status;
0069 u16 class_specific;
0070 u32 attr_mod;
0071 u64 tid;
0072 u8 gid[16];
0073 u32 dev_index;
0074 u8 traffic_class;
0075 };
0076
0077 SEC("tracepoint/ib_umad/ib_umad_read_recv")
0078 int on_ib_umad_read_recv(struct ib_umad_rw_args *ctx)
0079 {
0080 u64 zero = 0, *val;
0081 u8 class = ctx->mgmt_class;
0082
0083 bpf_printk("ib_umad read recv : class 0x%x\n", class);
0084
0085 val = bpf_map_lookup_elem(&read_count, &class);
0086 if (!val) {
0087 bpf_map_update_elem(&read_count, &class, &zero, BPF_NOEXIST);
0088 val = bpf_map_lookup_elem(&read_count, &class);
0089 if (!val)
0090 return 0;
0091 }
0092
0093 (*val) += 1;
0094
0095 return 0;
0096 }
0097 SEC("tracepoint/ib_umad/ib_umad_read_send")
0098 int on_ib_umad_read_send(struct ib_umad_rw_args *ctx)
0099 {
0100 u64 zero = 0, *val;
0101 u8 class = ctx->mgmt_class;
0102
0103 bpf_printk("ib_umad read send : class 0x%x\n", class);
0104
0105 val = bpf_map_lookup_elem(&read_count, &class);
0106 if (!val) {
0107 bpf_map_update_elem(&read_count, &class, &zero, BPF_NOEXIST);
0108 val = bpf_map_lookup_elem(&read_count, &class);
0109 if (!val)
0110 return 0;
0111 }
0112
0113 (*val) += 1;
0114
0115 return 0;
0116 }
0117 SEC("tracepoint/ib_umad/ib_umad_write")
0118 int on_ib_umad_write(struct ib_umad_rw_args *ctx)
0119 {
0120 u64 zero = 0, *val;
0121 u8 class = ctx->mgmt_class;
0122
0123 bpf_printk("ib_umad write : class 0x%x\n", class);
0124
0125 val = bpf_map_lookup_elem(&write_count, &class);
0126 if (!val) {
0127 bpf_map_update_elem(&write_count, &class, &zero, BPF_NOEXIST);
0128 val = bpf_map_lookup_elem(&write_count, &class);
0129 if (!val)
0130 return 0;
0131 }
0132
0133 (*val) += 1;
0134
0135 return 0;
0136 }
0137
0138 char _license[] SEC("license") = "GPL";