From: Adrian Moreno <amorenoz@redhat.com>
To: netdev@vger.kernel.org
Cc: aconole@redhat.com, echaudro@redhat.com, horms@kernel.org,
i.maximets@ovn.org, Adrian Moreno <amorenoz@redhat.com>,
Yotam Gigi <yotam.gi@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next 4/8] net: psample: add tracepoint
Date: Wed, 24 Apr 2024 15:50:51 +0200 [thread overview]
Message-ID: <20240424135109.3524355-5-amorenoz@redhat.com> (raw)
In-Reply-To: <20240424135109.3524355-1-amorenoz@redhat.com>
Currently there are no widely-available tools to dump the metadata and
group information when a packet is sampled, making it difficult to
troubleshoot related issues.
This makes psample use the event tracing framework to log the sampling
of a packet so that it's easier to quickly identify the source
(i.e: group) and context (i.e: metadata) of a packet being sampled.
This patch creates some checkpatch splats, but the style of the
tracepoint definition mimics that of other modules so it seems
acceptable.
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
net/psample/psample.c | 9 +++++++
net/psample/trace.h | 62 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+)
create mode 100644 net/psample/trace.h
diff --git a/net/psample/psample.c b/net/psample/psample.c
index 476aaad7a885..92db8ffa2ba2 100644
--- a/net/psample/psample.c
+++ b/net/psample/psample.c
@@ -18,6 +18,12 @@
#include <net/ip_tunnels.h>
#include <net/dst_metadata.h>
+#ifndef __CHECKER__
+#define CREATE_TRACE_POINTS
+#endif
+
+#include "trace.h"
+
#define PSAMPLE_MAX_PACKET_SIZE 0xffff
static LIST_HEAD(psample_groups_list);
@@ -470,6 +476,9 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
void *data;
int ret;
+ if (trace_psample_sample_packet_enabled())
+ trace_psample_sample_packet(group, skb, sample_rate, md);
+
meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) +
(out_ifindex ? nla_total_size(sizeof(u16)) : 0) +
(md->out_tc_valid ? nla_total_size(sizeof(u16)) : 0) +
diff --git a/net/psample/trace.h b/net/psample/trace.h
new file mode 100644
index 000000000000..2d32a846989b
--- /dev/null
+++ b/net/psample/trace.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM psample
+
+#if !defined(_TRACE_PSAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_PSAMPLE__H
+
+#include <linux/skbuff.h>
+#include <linux/tracepoint.h>
+#include <net/psample.h>
+
+TRACE_EVENT(psample_sample_packet,
+
+ TP_PROTO(struct psample_group *group, struct sk_buff *skb,
+ u32 sample_rate, const struct psample_metadata *md),
+
+ TP_ARGS(group, skb, sample_rate, md),
+
+ TP_STRUCT__entry(
+ __field(u32, group_num)
+ __field(u32, refcount)
+ __field(u32, seq)
+ __field(void *, skbaddr)
+ __field(unsigned int, len)
+ __field(unsigned int, data_len)
+ __field(u32, sample_rate)
+ __field(int, in_ifindex)
+ __field(int, out_ifindex)
+ __field(const void *, user_cookie)
+ __field(u32, user_cookie_len)
+ ),
+
+ TP_fast_assign(
+ __entry->group_num = group->group_num;
+ __entry->refcount = group->refcount;
+ __entry->seq = group->seq;
+ __entry->skbaddr = skb;
+ __entry->len = skb->len;
+ __entry->data_len = skb->data_len;
+ __entry->sample_rate = sample_rate;
+ __entry->in_ifindex = md->in_ifindex;
+ __entry->out_ifindex = md->out_ifindex;
+ __entry->user_cookie = &md->user_cookie[0];
+ __entry->user_cookie_len = md->user_cookie_len;
+ ),
+
+ TP_printk("group_num=%u refcount=%u seq=%u skbaddr=%p len=%u data_len=%u sample_rate=%u in_ifindex=%d out_ifindex=%d user_cookie=%p user_cookie_len=%u",
+ __entry->group_num, __entry->refcount, __entry->seq,
+ __entry->skbaddr, __entry->len, __entry->data_len,
+ __entry->sample_rate, __entry->in_ifindex,
+ __entry->out_ifindex, __entry->user_cookie,
+ __entry->user_cookie_len)
+);
+
+#endif /* _TRACE_PSAMPLE_H */
+
+/* This part must be outside protection */
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH ../../net/psample
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE trace
+#include <trace/define_trace.h>
--
2.44.0
next prev parent reply other threads:[~2024-04-24 13:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-24 13:50 [PATCH net-next 0/8] net: openvswitch: Add sample multicasting Adrian Moreno
2024-04-24 13:50 ` [PATCH net-next 1/8] net: netlink: export genl private pointer getters Adrian Moreno
2024-04-24 13:50 ` [PATCH net-next 2/8] net: psample: add multicast filtering on group_id Adrian Moreno
2024-04-24 14:54 ` Jiri Pirko
2024-04-25 7:23 ` Adrian Moreno
2024-04-24 13:50 ` [PATCH net-next 3/8] net: psample: add user cookie Adrian Moreno
2024-04-25 7:32 ` Ido Schimmel
2024-04-25 8:09 ` Adrian Moreno
2024-04-24 13:50 ` Adrian Moreno [this message]
2024-04-25 7:18 ` [PATCH net-next 4/8] net: psample: add tracepoint Ido Schimmel
2024-04-25 8:06 ` Adrian Moreno
2024-04-25 15:25 ` Ido Schimmel
2024-04-29 5:33 ` Adrian Moreno
2024-04-30 12:53 ` Ido Schimmel
2024-04-24 13:50 ` [PATCH net-next 5/8] net: sched: act_sample: add action cookie to sample Adrian Moreno
2024-04-25 7:39 ` Ido Schimmel
2024-04-25 21:43 ` Jamal Hadi Salim
2024-04-24 13:50 ` [PATCH net-next 6/8] net:openvswitch: add psample support Adrian Moreno
2024-04-30 7:29 ` Dan Carpenter
2024-05-03 9:43 ` Eelco Chaudron
2024-05-07 14:18 ` Adrian Moreno
2024-05-08 9:48 ` Eelco Chaudron
2024-05-08 15:25 ` Aaron Conole
2024-04-24 13:50 ` [PATCH net-next 7/8] selftests: openvswitch: add sample action Adrian Moreno
2024-04-24 13:50 ` [PATCH net-next 8/8] selftests: openvswitch: add psample test Adrian Moreno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240424135109.3524355-5-amorenoz@redhat.com \
--to=amorenoz@redhat.com \
--cc=aconole@redhat.com \
--cc=davem@davemloft.net \
--cc=echaudro@redhat.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=i.maximets@ovn.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yotam.gi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®