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_helpers.h"
19 struct bpf_map_def
SEC("maps") read_count
= {
20 .type
= BPF_MAP_TYPE_ARRAY
,
21 .key_size
= sizeof(u32
), /* class; u32 required */
22 .value_size
= sizeof(u64
), /* count of mads read */
23 .max_entries
= 256, /* Room for all Classes */
26 struct bpf_map_def
SEC("maps") write_count
= {
27 .type
= BPF_MAP_TYPE_ARRAY
,
28 .key_size
= sizeof(u32
), /* class; u32 required */
29 .value_size
= sizeof(u64
), /* count of mads written */
30 .max_entries
= 256, /* Room for all Classes */
35 #define bpf_debug(fmt, ...) \
37 char ____fmt[] = fmt; \
38 bpf_trace_printk(____fmt, sizeof(____fmt), \
42 #define bpf_debug(fmt, ...)
45 /* Taken from the current format defined in
46 * include/trace/events/ib_umad.h
48 * /sys/kernel/debug/tracing/events/ib_umad/ib_umad_read/format
49 * /sys/kernel/debug/tracing/events/ib_umad/ib_umad_write/format
51 struct ib_umad_rw_args
{
83 SEC("tracepoint/ib_umad/ib_umad_read_recv")
84 int on_ib_umad_read_recv(struct ib_umad_rw_args
*ctx
)
87 u8
class = ctx
->mgmt_class
;
89 bpf_debug("ib_umad read recv : class 0x%x\n", class);
91 val
= bpf_map_lookup_elem(&read_count
, &class);
93 bpf_map_update_elem(&read_count
, &class, &zero
, BPF_NOEXIST
);
94 val
= bpf_map_lookup_elem(&read_count
, &class);
103 SEC("tracepoint/ib_umad/ib_umad_read_send")
104 int on_ib_umad_read_send(struct ib_umad_rw_args
*ctx
)
107 u8
class = ctx
->mgmt_class
;
109 bpf_debug("ib_umad read send : class 0x%x\n", class);
111 val
= bpf_map_lookup_elem(&read_count
, &class);
113 bpf_map_update_elem(&read_count
, &class, &zero
, BPF_NOEXIST
);
114 val
= bpf_map_lookup_elem(&read_count
, &class);
123 SEC("tracepoint/ib_umad/ib_umad_write")
124 int on_ib_umad_write(struct ib_umad_rw_args
*ctx
)
127 u8
class = ctx
->mgmt_class
;
129 bpf_debug("ib_umad write : class 0x%x\n", class);
131 val
= bpf_map_lookup_elem(&write_count
, &class);
133 bpf_map_update_elem(&write_count
, &class, &zero
, BPF_NOEXIST
);
134 val
= bpf_map_lookup_elem(&write_count
, &class);
144 char _license
[] SEC("license") = "GPL";