From: Ederson de Souza <ederson.desouza@intel.com> To: xdp-hints@xdp-project.net Cc: bpf@vger.kernel.org Subject: [[RFC xdp-hints] 13/16] libbpf: Helpers to access XDP frame metadata Date: Mon, 2 Aug 2021 18:03:28 -0700 [thread overview] Message-ID: <20210803010331.39453-14-ederson.desouza@intel.com> (raw) In-Reply-To: <20210803010331.39453-1-ederson.desouza@intel.com> Two new pairs of helpers: `xsk_umem__adjust_prod_data` and `xsk_umem__adjust_prod_data_meta` for data that is being produced by the application - such as data that will be sent; and `xsk_umem__adjust_cons_data` and `xsk_umem__adjust_cons_data_meta`, for data being consumed - such as data obtained from the completion queue. Those function should usually be used on data obtained via `xsk_umem__get_data`. Didn't change this function to avoid API breaks. Signed-off-by: Ederson de Souza <ederson.desouza@intel.com> --- tools/lib/bpf/libbpf.map | 4 ++++ tools/lib/bpf/xsk.c | 26 ++++++++++++++++++++++++++ tools/lib/bpf/xsk.h | 7 +++++++ 3 files changed, 37 insertions(+) diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 492db50a4cd7..663585f7f186 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -375,4 +375,8 @@ LIBBPF_0.5.0 { bpf_map_lookup_and_delete_elem_flags; bpf_object__gen_loader; libbpf_set_strict_mode; + xsk_umem__adjust_cons_data; + xsk_umem__adjust_cons_data_meta; + xsk_umem__adjust_prod_data; + xsk_umem__adjust_prod_data_meta; } LIBBPF_0.4.0; diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index e9b619aa0cdf..17e8045eac0e 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -119,6 +119,30 @@ int xsk_socket__fd(const struct xsk_socket *xsk) return xsk ? xsk->fd : -EINVAL; } +void *xsk_umem__adjust_prod_data(void *umem_data, const struct xsk_umem *umem) +{ + return umem_data + umem->config.frame_headroom + umem->config.xdp_headroom; +} + +void *xsk_umem__adjust_prod_data_meta(void *umem_data, const struct xsk_umem *umem) +{ + if (!umem->config.xdp_headroom) + return NULL; + return umem_data; +} + +void *xsk_umem__adjust_cons_data(void *umem_data, const struct xsk_umem *umem) +{ + return umem_data; +} + +void *xsk_umem__adjust_cons_data_meta(void *umem_data, const struct xsk_umem *umem) +{ + if (!umem->config.xdp_headroom) + return NULL; + return umem_data; +} + static bool xsk_page_aligned(void *buffer) { unsigned long addr = (unsigned long)buffer; @@ -135,6 +159,7 @@ static void xsk_set_umem_config(struct xsk_umem_config *cfg, cfg->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE; cfg->frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM; cfg->flags = XSK_UMEM__DEFAULT_FLAGS; + cfg->xdp_headroom = XSK_UMEM__DEFAULT_XDP_HEADROOM; return; } @@ -143,6 +168,7 @@ static void xsk_set_umem_config(struct xsk_umem_config *cfg, cfg->frame_size = usr_cfg->frame_size; cfg->frame_headroom = usr_cfg->frame_headroom; cfg->flags = usr_cfg->flags; + cfg->xdp_headroom = usr_cfg->xdp_headroom; } static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg, diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h index 01c12dca9c10..7f4143150746 100644 --- a/tools/lib/bpf/xsk.h +++ b/tools/lib/bpf/xsk.h @@ -248,12 +248,18 @@ static inline __u64 xsk_umem__add_offset_to_addr(__u64 addr) LIBBPF_API int xsk_umem__fd(const struct xsk_umem *umem); LIBBPF_API int xsk_socket__fd(const struct xsk_socket *xsk); +LIBBPF_API void *xsk_umem__adjust_prod_data(void *umem_data, const struct xsk_umem *umem); +LIBBPF_API void *xsk_umem__adjust_prod_data_meta(void *umem_data, const struct xsk_umem *umem); +LIBBPF_API void *xsk_umem__adjust_cons_data(void *umem_data, const struct xsk_umem *umem); +LIBBPF_API void *xsk_umem__adjust_cons_data_meta(void *umem_data, const struct xsk_umem *umem); + #define XSK_RING_CONS__DEFAULT_NUM_DESCS 2048 #define XSK_RING_PROD__DEFAULT_NUM_DESCS 2048 #define XSK_UMEM__DEFAULT_FRAME_SHIFT 12 /* 4096 bytes */ #define XSK_UMEM__DEFAULT_FRAME_SIZE (1 << XSK_UMEM__DEFAULT_FRAME_SHIFT) #define XSK_UMEM__DEFAULT_FRAME_HEADROOM 0 #define XSK_UMEM__DEFAULT_FLAGS 0 +#define XSK_UMEM__DEFAULT_XDP_HEADROOM 0 struct xsk_umem_config { __u32 fill_size; @@ -261,6 +267,7 @@ struct xsk_umem_config { __u32 frame_size; __u32 frame_headroom; __u32 flags; + __u32 xdp_headroom; }; LIBBPF_API int xsk_setup_xdp_prog(int ifindex, -- 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 ` [[RFC xdp-hints] 09/16] net/xdp: Support for generic XDP hints Ederson de Souza 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 ` Ederson de Souza [this message] 2021-08-06 22:59 ` [[RFC xdp-hints] 13/16] libbpf: Helpers to access XDP frame metadata 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-14-ederson.desouza@intel.com \ --to=ederson.desouza@intel.com \ --cc=bpf@vger.kernel.org \ --cc=xdp-hints@xdp-project.net \ --subject='Re: [[RFC xdp-hints] 13/16] libbpf: Helpers to access XDP frame metadata' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox