From patchwork Fri Sep 29 18:21:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Morten_Br=C3=B8rup?= X-Patchwork-Id: 132236 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D4A142676; Fri, 29 Sep 2023 20:21:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B36E140273; Fri, 29 Sep 2023 20:21:12 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id D2A9B4026E for ; Fri, 29 Sep 2023 20:21:11 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 74B4820602 for ; Fri, 29 Sep 2023 20:21:11 +0200 (CEST) Received: from dkrd2.smartsharesys.local ([192.168.4.12]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 29 Sep 2023 20:21:11 +0200 From: =?utf-8?q?Morten_Br=C3=B8rup?= To: dev@dpdk.org Cc: =?utf-8?q?Morten_Br=C3=B8rup?= Subject: [PATCH v2] mbuf: always use default headroom (TEST ONLY) Date: Fri, 29 Sep 2023 20:21:09 +0200 Message-Id: <20230929182109.33244-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230929175614.32855-1-mb@smartsharesystems.com> References: <20230929175614.32855-1-mb@smartsharesystems.com> MIME-Version: 1.0 X-OriginalArrivalTime: 29 Sep 2023 18:21:11.0075 (UTC) FILETIME=[B9233730:01D9F301] X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This is a test. Please ignore. It seems silly using a non-default headroom when attaching external memory. Most functions assume default headroom, so don't reset to anything less. Signed-off-by: Morten Brørup --- app/test/test_mbuf.c | 8 ++++---- drivers/net/mlx5/mlx5_rx.h | 1 - lib/mbuf/rte_mbuf.c | 4 ++-- lib/mbuf/rte_mbuf.h | 15 +++++++-------- lib/vhost/virtio_net.c | 1 - 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index d7393df7eb..f10eee6ea7 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -608,9 +608,9 @@ test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool, /* save data pointer to compare it after detach() */ c_data = rte_pktmbuf_mtod(clone, char *); - if (c_data != (char *)clone + sizeof(*clone) + MBUF2_PRIV_SIZE) + if (c_data != (char *)clone + sizeof(*clone) + MBUF2_PRIV_SIZE + RTE_PKTMBUF_HEADROOM) GOTO_FAIL("bad data pointer in clone"); - if (rte_pktmbuf_headroom(clone) != 0) + if (rte_pktmbuf_headroom(clone) != RTE_PKTMBUF_HEADROOM) GOTO_FAIL("bad headroom in clone"); rte_pktmbuf_attach(clone, m); @@ -637,9 +637,9 @@ test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool, /* save data pointer to compare it after detach() */ c_data2 = rte_pktmbuf_mtod(clone2, char *); - if (c_data2 != (char *)clone2 + sizeof(*clone2) + MBUF2_PRIV_SIZE) + if (c_data2 != (char *)clone2 + sizeof(*clone2) + MBUF2_PRIV_SIZE + RTE_PKTMBUF_HEADROOM) GOTO_FAIL("bad data pointer in clone2"); - if (rte_pktmbuf_headroom(clone2) != 0) + if (rte_pktmbuf_headroom(clone2) != RTE_PKTMBUF_HEADROOM) GOTO_FAIL("bad headroom in clone2"); rte_pktmbuf_attach(clone2, clone); diff --git a/drivers/net/mlx5/mlx5_rx.h b/drivers/net/mlx5/mlx5_rx.h index baeb4797aa..0927ac13ea 100644 --- a/drivers/net/mlx5/mlx5_rx.h +++ b/drivers/net/mlx5/mlx5_rx.h @@ -546,7 +546,6 @@ mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len, rte_pktmbuf_attach_extbuf(pkt, buf_addr, buf_iova, buf_len, shinfo); /* Set mbuf head-room. */ - SET_DATA_OFF(pkt, RTE_PKTMBUF_HEADROOM); MLX5_ASSERT(pkt->ol_flags & RTE_MBUF_F_EXTERNAL); MLX5_ASSERT(rte_pktmbuf_tailroom(pkt) >= len - (hdrm_overlap > 0 ? hdrm_overlap : 0)); diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c index 686e797c80..7ccc814a75 100644 --- a/lib/mbuf/rte_mbuf.c +++ b/lib/mbuf/rte_mbuf.c @@ -93,7 +93,7 @@ rte_pktmbuf_init(struct rte_mempool *mp, m->buf_len = (uint16_t)buf_len; /* keep some headroom between start of buffer and data */ - m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len); + rte_pktmbuf_reset_headroom(m); /* init some constant fields */ m->pool = mp; @@ -196,7 +196,7 @@ __rte_pktmbuf_init_extmem(struct rte_mempool *mp, ++ctx->ext; } /* keep some headroom between start of buffer and data */ - m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len); + rte_pktmbuf_reset_headroom(m); /* init some constant fields */ m->pool = mp; diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h index 913c459b1c..b1047bc848 100644 --- a/lib/mbuf/rte_mbuf.h +++ b/lib/mbuf/rte_mbuf.h @@ -859,8 +859,7 @@ rte_pktmbuf_priv_size(struct rte_mempool *mp) */ static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m) { - m->data_off = (uint16_t)RTE_MIN((uint16_t)RTE_PKTMBUF_HEADROOM, - (uint16_t)m->buf_len); + m->data_off = RTE_PKTMBUF_HEADROOM; } /** @@ -1028,14 +1027,14 @@ rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len, * provided via shinfo. This callback function will be called once all the * mbufs are detached from the buffer (refcnt becomes zero). * - * The headroom length of the attaching mbuf will be set to zero and this - * can be properly adjusted after attachment. For example, ``rte_pktmbuf_adj()`` - * or ``rte_pktmbuf_reset_headroom()`` might be used. - * - * Similarly, the packet length is initialized to 0. If the buffer contains + * The packet length is initialized to 0. If the buffer contains * data, the user has to adjust ``data_len`` and the ``pkt_len`` field of * the mbuf accordingly. * + * Similarly, the headroom length of the attaching mbuf will be set to the + * default (RTE_PKTMBUF_HEADROOM). This can also be properly adjusted after + * attachment. For example, ``rte_pktmbuf_adj()`` might be used. + * * More mbufs can be attached to the same external buffer by * ``rte_pktmbuf_attach()`` once the external buffer has been attached by * this API. @@ -1094,7 +1093,7 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr, m->buf_len = buf_len; m->data_len = 0; - m->data_off = 0; + rte_pktmbuf_reset_headroom(m); m->ol_flags |= RTE_MBUF_F_EXTERNAL; m->shinfo = shinfo; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 759a78e3e3..61e6fa1864 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -3042,7 +3042,6 @@ virtio_dev_extbuf_alloc(struct virtio_net *dev, struct rte_mbuf *pkt, uint32_t s iova = rte_malloc_virt2iova(buf); rte_pktmbuf_attach_extbuf(pkt, buf, iova, buf_len, shinfo); - rte_pktmbuf_reset_headroom(pkt); return 0; }