From: Ederson de Souza <ederson.desouza@intel.com>
To: xdp-hints@xdp-project.net
Cc: bpf@vger.kernel.org
Subject: [[RFC xdp-hints] 09/16] net/xdp: Support for generic XDP hints
Date: Mon, 2 Aug 2021 18:03:24 -0700 [thread overview]
Message-ID: <20210803010331.39453-10-ederson.desouza@intel.com> (raw)
In-Reply-To: <20210803010331.39453-1-ederson.desouza@intel.com>
XDP hints are meta information about an XDP packet. This patch provides
macros that define a base set of hints, that drivers can use to
implement XDP hints support - as well as expand on that.
A future patch will show these macros being used by the igc driver.
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
---
include/net/xdp.h | 62 +++++++++++++++++++++++++++++++++++++
include/uapi/linux/if_xdp.h | 3 ++
2 files changed, 65 insertions(+)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index ad5b02dcb6f4..59a0b91e1975 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -76,6 +76,68 @@ struct xdp_buff {
u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
};
+/*
+ * This is what the generic xdp hints struct looks like:
+ *
+ * struct xdp_hints {
+ * u64 rx_timestamp;
+ * u64 tx_timestamp;
+ * u64 valid_map;
+ * u32 btf_id;
+ * };
+ */
+
+/* New fields need to be added at the beginning, not at the end,
+ * as the known position on the metadata is the end (just before
+ * the data starts) */
+
+#define XDP_GENERIC_HINTS_STRUCT_MEMBERS \
+ u64 rx_timestamp; \
+ u64 tx_timestamp; \
+ u64 valid_map; \
+ u32 btf_id;
+
+#define BTF_INFO_ENC(kind, kind_flag, vlen) \
+ ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
+
+#define BTF_TYPE_ENC(name, info, size_or_type) \
+ (name), (info), (size_or_type)
+
+#define BTF_INT_ENC(encoding, bits_offset, nr_bits) \
+ ((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
+
+#define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz) \
+ BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \
+ BTF_INT_ENC(encoding, bits_offset, bits)
+
+#define BTF_STRUCT_ENC(name, nr_elems, sz) \
+ BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, nr_elems), sz)
+
+#define BTF_MEMBER_ENC(name, type, bits_offset) \
+ (name), (type), (bits_offset)
+
+#define XDP_GENERIC_MD_SUPPORTED_HINTS_NUM_MMBRS 4
+#define XDP_GENERIC_HINTS_NAME_OFFSET 62
+
+#define XDP_GENERIC_HINTS_NAMES "\0xdp_hints\0u32\0u64\0rx_timestamp\0" \
+ "tx_timestamp\0valid_map\0btf_id\0"
+
+#define XDP_GENERIC_HINTS_TYPES \
+ BTF_TYPE_INT_ENC(15, 0, 0, 64, 8), \
+ BTF_TYPE_INT_ENC(11, 0, 0, 32, 4)
+
+#define XDP_GENERIC_HINTS_STRUCT(nr_elems, sz) \
+ BTF_STRUCT_ENC(1, XDP_GENERIC_MD_SUPPORTED_HINTS_NUM_MMBRS + nr_elems, \
+ 8 + 8 + 8 + 4 + sz)
+
+#define XDP_GENERIC_HINTS_MEMBERS(offset) \
+ BTF_MEMBER_ENC(19, 1, offset + 0), \
+ BTF_MEMBER_ENC(32, 1, offset + 64), \
+ BTF_MEMBER_ENC(45, 1, offset + 128), \
+ BTF_MEMBER_ENC(55, 2, offset + 192)
+
+#define XDP_GENERIC_HINTS_BIT_MAX XDP_GENERIC_HINTS_TX_TIMESTAMP
+
static __always_inline void
xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
{
diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
index a78a8096f4ce..345c757b8c3e 100644
--- a/include/uapi/linux/if_xdp.h
+++ b/include/uapi/linux/if_xdp.h
@@ -12,6 +12,9 @@
#include <linux/types.h>
+#define XDP_GENERIC_HINTS_RX_TIMESTAMP (1 << 0)
+#define XDP_GENERIC_HINTS_TX_TIMESTAMP (1 << 1)
+
/* Options for the sxdp_flags field */
#define XDP_SHARED_UMEM (1 << 0)
#define XDP_COPY (1 << 1) /* Force copy-mode */
--
2.32.0
next prev parent reply other threads:[~2021-08-03 1:03 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 1:03 [[RFC xdp-hints] 00/16] XDP hints and AF_XDP support Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 01/16] bpf: add btf register/unregister API Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 02/16] net/core: XDP metadata BTF netlink API Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 03/16] tools/bpf: Query XDP metadata BTF ID Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 04/16] tools/bpf: Add xdp set command for md btf Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 05/16] igc: Fix race condition in PTP Tx code Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 06/16] igc: Retrieve the TX timestamp directly (instead of in a interrupt) Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 07/16] igc: Add support for multiple in-flight TX timestamps Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 08/16] igc: Use irq safe locks for timestamping Ederson de Souza
2021-08-03 1:03 ` Ederson de Souza [this message]
2021-08-03 1:03 ` [[RFC xdp-hints] 10/16] igc: XDP packet RX timestamp Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 11/16] igc: XDP packet TX timestamp Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 12/16] ethtool,igc: Add "xdp_headroom" driver info Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 13/16] libbpf: Helpers to access XDP frame metadata Ederson de Souza
2021-08-06 22:59 ` Andrii Nakryiko
2021-08-19 11:47 ` Toke Høiland-Jørgensen
2021-08-03 1:03 ` [[RFC xdp-hints] 14/16] libbpf: Helpers to access XDP hints based on BTF definitions Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 15/16] samples/bpf: XDP hints AF_XDP example Ederson de Souza
2021-08-03 1:03 ` [[RFC xdp-hints] 16/16] samples/bpf: Show XDP hints usage Ederson de Souza
2021-08-06 23:14 ` Andrii Nakryiko
2021-08-03 9:12 ` [[RFC xdp-hints] 00/16] XDP hints and AF_XDP support Alexander Lobakin
2021-08-03 15:23 ` John Fastabend
2021-08-04 15:15 ` Alexander Lobakin
2021-08-04 23:45 ` John Fastabend
2021-08-13 22:04 ` Desouza, Ederson
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
List information: https://lists.xdp-project.net/postorius/lists/xdp-hints.xdp-project.net/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210803010331.39453-10-ederson.desouza@intel.com \
--to=ederson.desouza@intel.com \
--cc=bpf@vger.kernel.org \
--cc=xdp-hints@xdp-project.net \
/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