From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A27EC45FE6; Wed, 29 Jan 2025 00:12:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5BAB940430; Wed, 29 Jan 2025 00:12:07 +0100 (CET) Received: from mail-lf1-f97.google.com (mail-lf1-f97.google.com [209.85.167.97]) by mails.dpdk.org (Postfix) with ESMTP id 55AF1402E4 for ; Wed, 29 Jan 2025 00:12:03 +0100 (CET) Received: by mail-lf1-f97.google.com with SMTP id 2adb3069b0e04-5439e331cceso7499805e87.1 for ; Tue, 28 Jan 2025 15:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1738105923; x=1738710723; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kI0q9WmXcnd5b2Cjb0cFZezJQA/n13Kt7dfYig3zuqA=; b=Z0cDxnbRUPhkh3HqTNgiS2tpXdYmR79MF0qCC3t7OShuG6RKzg4cLEH0EDuJDT7Ulr E2i7eM/XTV0a+jHjCRIdf31DwjHDGn/1aEMCxuMjlrJjSKoR8B0/BfZokrSzhHEUwMLY 8OrgO0FooC3Nc1ryj1mCy0DkbwMAEDO/OTvNgwamx1wNWEuqlX2pqEOzZj6NemtYLBj8 SLOb8lH2quAJws7OXJ6DYZB3sze7BgrsZChQW2bPey7h6iahkSYRzx759gQtQuz1lI4B HGoPrP4qwoBfZzQofnQtwdGcOSKPtV4Sa2tstOrFTdOpjEO0ZWtqJ14QMMLCDXOJwgjM kY6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738105923; x=1738710723; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kI0q9WmXcnd5b2Cjb0cFZezJQA/n13Kt7dfYig3zuqA=; b=GogAA6aK3XJ5f7OfaVZnhTH8bdAMwvMZcpNuAqfG57WbPujPBpRPVuLCv8YreBf8uY 8Ly/r4pf4nupbG11UtH+ne69j3T6aN4MAtcC0sR3FsfPf9sfNMq70NHvLORnXRfJHlQc 7doWlw+HvXiAUyM320lMAKZTziLzXnRMaS4+VsT3LaO1MBCRDL/FGzJ+oypLX4dUrstI fQqCYvokqWvGVo+QtU8IfDc/7z+ALCGMAarz1cxR8vyhyOLMNaI3h3fcZXAYePJyAdKE pMnss0Vf9C4ymrk6mrZMTxwZ2oMOaDtcVCiEa9LxZOf9360+S+J/AL5RvbRcKVtFukpF vLpA== X-Gm-Message-State: AOJu0Yw5sCzQvBpEStzZXrmEujzZeQxzaHsJzt8bRFyDP3W1BksIo9K6 hyKipjj6VvwggWLLsShBDkcpIFwVuU1KEHsVkGCfNiqZw5NnZkATORS4KCf8sB29pY7JEDcOQMc oTOHb5xS3hxtW/6ZJSEVf8zOe903eHYukesZQunHV X-Gm-Gg: ASbGncuT1gNWnr1X1sfBxk8v/klYWgnSwOSEL5E+d1O7Gsk2oRlJZxJcJRaJHXV6nmY avopHVjUpwz08HlcQNnFDNPm0tFi1sG2t0CVhq5Ul7gQLBDq3+IJZ4fQOPIivHzHcXYwhdoDHUm c8cLrYxTDFBLWeB/o/flGKWz9BLW9sH+vsP+Z1W5OxdPkmTtq3jl79cAYigd2obYs6FnHMNZkUU fb2DTwXZUUAhnK6J7vQ8wmPSoBkeAqtinOeh+CbfNwL+DGHvqMnkaNXJOltObeKDtcHJe8hkFC/ 1xt3ImzA7QkzJvACe1vYFoS1efj0Ru6y3C63OCWcb9I/HPqGKA== X-Google-Smtp-Source: AGHT+IEX8ZfeT9M1pHs0GFOXRCAUlYIqenSzy9PffDEvLIjpXHcvRJsxrPn6lakrIEO5LRPWO2BF9zIEGjPt X-Received: by 2002:a05:6512:3409:b0:53e:fa8b:8227 with SMTP id 2adb3069b0e04-543e4c3cab5mr310651e87.45.1738105922487; Tue, 28 Jan 2025 15:12:02 -0800 (PST) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id 2adb3069b0e04-543c838c80fsm174630e87.102.2025.01.28.15.12.02; Tue, 28 Jan 2025 15:12:02 -0800 (PST) X-Relaying-Domain: 6wind.com Received: from localhost (rainbow.dev.6wind.com [10.17.1.165]) by smtpservice.6wind.com (Postfix) with ESMTP id 096661824B; Wed, 29 Jan 2025 00:12:02 +0100 (CET) From: Ariel Otilibili To: dev@dpdk.org Cc: stable@dpdk.org, Thomas Monjalon , David Marchand , Stephen Hemminger , Ciara Loftus , Maryam Tahhan , Ariel Otilibili Subject: [PATCH v3 2/2] net/af_xdp: Refactor af_xdp_tx_zc() Date: Wed, 29 Jan 2025 00:11:52 +0100 Message-Id: <20250128231152.249497-3-ariel.otilibili@6wind.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250128231152.249497-1-ariel.otilibili@6wind.com> References: <20250116195640.68885-1-ariel.otilibili@6wind.com> <20250128231152.249497-1-ariel.otilibili@6wind.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Both legs of the loop share the same logic: either to go out of the function, or to fall through to the next instructions. For that, maybe_cpy_pkt() is introduced. Bugzilla ID: 1440 Signed-off-by: Ariel Otilibili --- drivers/net/af_xdp/rte_eth_af_xdp.c | 131 ++++++++++++++++++---------- 1 file changed, 84 insertions(+), 47 deletions(-) diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 092bcb73aa0a..efe23283fb52 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -536,13 +536,80 @@ kick_tx(struct pkt_tx_queue *txq, struct xsk_ring_cons *cq) } } +static inline uint64_t +update_addr(struct rte_mbuf *mbuf, struct xsk_umem_info *umem) +{ + return (uint64_t)mbuf - (uint64_t)umem->buffer + - umem->mb_pool->header_size; +} + +static inline uint64_t +update_offset(struct rte_mbuf *mbuf, struct xsk_umem_info *umem) +{ + uint64_t offset; + + offset = rte_pktmbuf_mtod(mbuf, uint64_t) - (uint64_t)mbuf + + umem->mb_pool->header_size; + return offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; +} + +static struct rte_mbuf * +maybe_kick_tx(struct pkt_tx_queue *txq, uint32_t *idx_tx, struct rte_mbuf *mbuf) +{ + struct rte_mbuf *ret = mbuf; + + if (!xsk_ring_prod__reserve(&txq->tx, 1, idx_tx)) { + kick_tx(txq, &txq->pair->cq); + if (!xsk_ring_prod__reserve(&txq->tx, 1, idx_tx)) + ret = NULL; + } + + return ret; +} + +static struct rte_mbuf * +maybe_create_mbuf(struct pkt_tx_queue *txq, uint32_t *idx_tx, + struct xsk_umem_info *umem) { + struct rte_mbuf *local_mbuf = rte_pktmbuf_alloc(umem->mb_pool); + + if (local_mbuf == NULL) + goto out; + + if (!xsk_ring_prod__reserve(&txq->tx, 1, idx_tx)) { + rte_pktmbuf_free(local_mbuf); + local_mbuf = NULL; + goto out; + } + +out: + return local_mbuf; +} + +static void +maybe_cpy_pkt(bool is_mbuf_equal, struct xsk_umem_info *umem, + uint64_t addr_plus_offset, struct rte_mbuf *mbuf, + struct xdp_desc *desc) +{ + void *pkt; + + if(is_mbuf_equal) + goto out; + + pkt = xsk_umem__get_data(umem->buffer, addr_plus_offset); + rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->len); + rte_pktmbuf_free(mbuf); + +out: + return; +} + #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG) static uint16_t af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) { struct pkt_tx_queue *txq = queue; struct xsk_umem_info *umem = txq->umem; - struct rte_mbuf *mbuf; + struct rte_mbuf *mbuf, *local_mbuf; unsigned long tx_bytes = 0; int i; uint32_t idx_tx; @@ -551,61 +618,31 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) uint64_t addr, offset; struct xsk_ring_cons *cq = &txq->pair->cq; uint32_t free_thresh = cq->size >> 1; + bool is_true; if (xsk_cons_nb_avail(cq, free_thresh) >= free_thresh) pull_umem_cq(umem, XSK_RING_CONS__DEFAULT_NUM_DESCS, cq); for (i = 0; i < nb_pkts; i++) { mbuf = bufs[i]; + is_true = mbuf->pool == umem->mb_pool; - if (mbuf->pool == umem->mb_pool) { - if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) { - kick_tx(txq, cq); - if (!xsk_ring_prod__reserve(&txq->tx, 1, - &idx_tx)) - goto out; - } - desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx); - desc->len = mbuf->pkt_len; - addr = (uint64_t)mbuf - (uint64_t)umem->buffer - - umem->mb_pool->header_size; - offset = rte_pktmbuf_mtod(mbuf, uint64_t) - - (uint64_t)mbuf + - umem->mb_pool->header_size; - offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; - desc->addr = addr | offset; - tx_bytes += desc->len; - count++; - } else { - struct rte_mbuf *local_mbuf = - rte_pktmbuf_alloc(umem->mb_pool); - void *pkt; - - if (local_mbuf == NULL) - goto out; + if (is_true) + local_mbuf = maybe_kick_tx(txq, &idx_tx, mbuf); + else + local_mbuf = maybe_create_mbuf(txq, &idx_tx, umem); - if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) { - rte_pktmbuf_free(local_mbuf); - goto out; - } + if (!local_mbuf) + goto out; - desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx); - desc->len = mbuf->pkt_len; - - addr = (uint64_t)local_mbuf - (uint64_t)umem->buffer - - umem->mb_pool->header_size; - offset = rte_pktmbuf_mtod(local_mbuf, uint64_t) - - (uint64_t)local_mbuf + - umem->mb_pool->header_size; - pkt = xsk_umem__get_data(umem->buffer, addr + offset); - offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; - desc->addr = addr | offset; - rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), - desc->len); - tx_bytes += desc->len; - rte_pktmbuf_free(mbuf); - count++; - } + desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx); + desc->len = mbuf->pkt_len; + addr = update_addr(local_mbuf, umem); + offset = update_offset(local_mbuf, umem); + desc->addr = addr | offset; + maybe_cpy_pkt(is_true, umem, addr + offset, mbuf, desc); + tx_bytes += desc->len; + count++; } out: -- 2.30.2