From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4BDDDA04B7; Sun, 20 Sep 2020 08:02:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A08651D9A6; Sun, 20 Sep 2020 08:02:20 +0200 (CEST) Received: from baidu.com (mx22.baidu.com [220.181.50.185]) by dpdk.org (Postfix) with ESMTP id 2E2991D998 for ; Sun, 20 Sep 2020 08:02:18 +0200 (CEST) Received: from BJHW-Mail-Ex14.internal.baidu.com (unknown [10.127.64.37]) by Forcepoint Email with ESMTPS id 4A59C6941943952C57B8; Sun, 20 Sep 2020 14:02:08 +0800 (CST) Received: from BJHW-Mail-Ex15.internal.baidu.com (10.127.64.38) by BJHW-Mail-Ex14.internal.baidu.com (10.127.64.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Sun, 20 Sep 2020 14:02:08 +0800 Received: from BJHW-Mail-Ex15.internal.baidu.com ([100.100.100.38]) by BJHW-Mail-Ex15.internal.baidu.com ([100.100.100.38]) with mapi id 15.01.1979.006; Sun, 20 Sep 2020 14:02:08 +0800 From: "Li,Rongqing" To: "Loftus, Ciara" CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH 2/2] af_xdp: avoid to unnecessary allocation and free mbuf Thread-Index: AQHWjLEEV4v8TBv8l0q6KKHcoHZI/aluJHQQgALkYvA= Date: Sun, 20 Sep 2020 06:02:07 +0000 Message-ID: References: <1600319462-2053-1-git-send-email-lirongqing@baidu.com> <1600319462-2053-2-git-send-email-lirongqing@baidu.com> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.22.197.253] x-baidu-bdmsfe-datecheck: 1_BJHW-Mail-Ex14_2020-09-20 14:02:08:283 Content-Type: text/plain; charset="utf-7" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 2/2] af_xdp: avoid to unnecessary allocation and free mbuf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" +AD4- -----Original Message----- +AD4- From: Loftus, Ciara +AFs-mailto:ciara.loftus+AEA-intel.com+AF0- +AD4- Sent: Friday, September 18, 2020 5:39 PM +AD4- To: Li,Rongqing +ADw-lirongqing+AEA-baidu.com+AD4- +AD4- Cc: dev+AEA-dpdk.org +AD4- Subject: RE: +AFs-dpdk-dev+AF0- +AFs-PATCH 2/2+AF0- af+AF8-xdp: avoid= to unnecessary allocation and +AD4- free mbuf +AD4-=20 +AD4- +AD4- +AD4- +AD4- optimize rx performance, by allocating mbuf based on result of +AD4- +AD4- xsk+AF8-ring+AF8-cons+AF8AXw-peek, to avoid to redundancy alloc= ation, and free mbuf +AD4- +AD4- when receive packets +AD4- +AD4- +AD4- +AD4- Signed-off-by: Li RongQing +ADw-lirongqing+AEA-baidu.com+AD4- +AD4- +AD4- Signed-off-by: Dongsheng Rong +ADw-rongdongsheng+AEA-baidu.com+= AD4- +AD4- +AD4- --- +AD4- +AD4- drivers/net/af+AF8-xdp/rte+AF8-eth+AF8-af+AF8-xdp.c +AHw- 64 +AD4- +AD4- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---------------- +AD4- +AD4- ------ +AD4- +AD4- 1 file changed, 27 insertions(+-), 37 deletions(-) +AD4- +AD4- +AD4- +AD4- diff --git a/drivers/net/af+AF8-xdp/rte+AF8-eth+AF8-af+AF8-xdp.= c +AD4- +AD4- b/drivers/net/af+AF8-xdp/rte+AF8-eth+AF8-af+AF8-xdp.c +AD4- +AD4- index 7ce4ad04a..48824050e 100644 +AD4- +AD4- --- a/drivers/net/af+AF8-xdp/rte+AF8-eth+AF8-af+AF8-xdp.c +AD4- +AD4- +-+-+- b/drivers/net/af+AF8-xdp/rte+AF8-eth+AF8-af+AF8-xdp.c +AD4- +AD4- +AEAAQA- -229,28 +-229,29 +AEAAQA- af+AF8-xdp+AF8-rx+AF8-zc(voi= d +ACo-queue, struct rte+AF8-mbuf +AD4- +AD4- +ACoAKg-bufs, uint16+AF8-t nb+AF8-pkts) +AD4- +AD4- struct xsk+AF8-umem+AF8-info +ACo-umem +AD0- rxq-+AD4-umem+AD= s- +AD4- +AD4- uint32+AF8-t idx+AF8-rx +AD0- 0+ADs- +AD4- +AD4- unsigned long rx+AF8-bytes +AD0- 0+ADs- +AD4- +AD4- - int rcvd, i+ADs- +AD4- +AD4- +- int i+ADs- +AD4- +AD4- struct rte+AF8-mbuf +ACo-fq+AF8-bufs+AFs-ETH+AF8-AF+AF8-XDP+A= F8-RX+AF8-BATCH+AF8-SIZE+AF0AOw- +AD4- +AD4- +AD4- +AD4- - /+ACo- allocate bufs for fill queue replenishment after rx +A= Co-/ +AD4- +AD4- - if (rte+AF8-pktmbuf+AF8-alloc+AF8-bulk(umem-+AD4-mb+AF8-pool,= fq+AF8-bufs, nb+AF8-pkts)) +AHs- +AD4- +AD4- - AF+AF8-XDP+AF8-LOG(DEBUG, +AD4- +AD4- - +ACI-Failed to get enough buffers for fq.+AFw-n+ACI-)+ADs- +AD4- +AD4- - return 0+ADs- +AD4- +AD4- - +AH0- +AD4- +AD4- +AD4- +AD4- - rcvd +AD0- xsk+AF8-ring+AF8-cons+AF8AXw-peek(rx, nb+AF8-pkts,= +ACY-idx+AF8-rx)+ADs- +AD4- +AD4- +- nb+AF8-pkts +AD0- xsk+AF8-ring+AF8-cons+AF8AXw-peek(rx, nb+A= F8-pkts, +ACY-idx+AF8-rx)+ADs- +AD4- +AD4- +AD4- +AD4- - if (rcvd +AD0APQ- 0) +AHs- +AD4- +AD4- +- if (nb+AF8-pkts +AD0APQ- 0) +AHs- +AD4- +AD4- +ACM-if defined(XDP+AF8-USE+AF8-NEED+AF8-WAKEUP) +AD4- +AD4- if (xsk+AF8-ring+AF8-prod+AF8AXw-needs+AF8-wakeup(+ACY-umem-= +AD4-fq)) +AD4- +AD4- (void)poll(rxq-+AD4-fds, 1, 1000)+ADs- +AD4- +AD4- +ACM-endif +AD4- +AD4- +AD4- +AD4- - goto out+ADs- +AD4- +AD4- +- return 0+ADs- +AD4- +AD4- +AH0- +AD4- +AD4- +AD4- +AD4- - for (i +AD0- 0+ADs- i +ADw- rcvd+ADs- i+-+-) +AHs- +AD4- +AD4- +- /+ACo- allocate bufs for fill queue replenishment after rx += ACo-/ +AD4- +AD4- +- if (rte+AF8-pktmbuf+AF8-alloc+AF8-bulk(umem-+AD4-mb+AF8-pool= , fq+AF8-bufs, nb+AF8-pkts)) +AHs- +AD4- +AD4- +- AF+AF8-XDP+AF8-LOG(DEBUG, +AD4- +AD4- +- +ACI-Failed to get enough buffers for fq.+AFw-n+ACI-)+ADs- +AD4-=20 +AD4- Thanks for this patch. I've considered this in the past. +AD4- There is a problem if we hit this condition. +AD4- We advance the rx producer +AEA- xsk+AF8-ring+AF8-cons+AF8AXw-peek. +AD4- But if we have no mbufs to hold the rx data, it is lost. +AD4- That's why we allocate the mbufs up front now. +AD4- Agree that we might have wasteful allocations and it's not the most o= ptimal, +AD4- but we don't drop packets due to failed mbuf allocs. +AD4-=20 +AD4- +AD4- +- return 0+ADs- xsk+AF8-ring+AF8-cons+AF8AXw-peek advance rx cached+AF8-cons and rx cached+= AF8-prod, I think it is harmless to advance cached+AF8-prod, so we can restore rx cached+AF8-cons if mbuf fail to be allocated, to fix, = like: if (unlikely(rte+AF8-pktmbuf+AF8-alloc+AF8-bulk(rxq-+AD4-mb+AF8-pool, m= bufs, nb+AF8-pkts) +ACEAPQ- 0)) +AHs- rx-+AD4-cached+AF8-cons -+AD0- rcvd+ADs- return 0+ADs- +AH0- Is it right? -Li