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 32EEEA0567; Fri, 13 Mar 2020 10:20:44 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 68A9C1C036; Fri, 13 Mar 2020 10:20:15 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 24A811C06C for ; Fri, 13 Mar 2020 10:20:13 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AB39731B; Fri, 13 Mar 2020 02:20:12 -0700 (PDT) Received: from net-arm-thunderx2-04.shanghai.arm.com (net-arm-thunderx2-04.shanghai.arm.com [10.169.40.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 07F7D3F67D; Fri, 13 Mar 2020 02:20:08 -0700 (PDT) From: Gavin Hu To: dev@dpdk.org Cc: nd@arm.com, david.marchand@redhat.com, thomas@monjalon.net, mk@semihalf.com, gtzalik@amazon.com, evgenys@amazon.com, igorch@amazon.com, mw@semihalf.com, Honnappa.Nagarahalli@arm.com, ruifeng.wang@arm.com, phil.yang@arm.com, joyce.kong@arm.com Date: Fri, 13 Mar 2020 17:18:34 +0800 Message-Id: <20200313091835.58039-7-gavin.hu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313091835.58039-1-gavin.hu@arm.com> References: <20200313091835.58039-1-gavin.hu@arm.com> Subject: [dpdk-dev] [PATCH RFC v1 6/7] net/ena: use c11 atomic for statistics 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" The statistics logging are in the data path, as rte_atomic APIs enforce unnecessary barriers on aarch64, this patch uses c11 atomic APIs with the __ATOMIC_RELAXED memory ordering to give CPU more freedom to optimize by making use of out-of-order execution. Signed-off-by: Gavin Hu Reviewed-by: Honnappa Nagarahalli --- drivers/net/ena/ena_ethdev.c | 38 ++++++++++++++++++++++++------------ drivers/net/ena/ena_ethdev.h | 8 ++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index c268788fd..8b566aecd 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -902,10 +901,14 @@ static void ena_stats_restart(struct rte_eth_dev *dev) { struct ena_adapter *adapter = dev->data->dev_private; - rte_atomic64_init(&adapter->drv_stats->ierrors); - rte_atomic64_init(&adapter->drv_stats->oerrors); - rte_atomic64_init(&adapter->drv_stats->rx_nombuf); - rte_atomic64_init(&adapter->drv_stats->rx_drops); + __atomic_store_n(&adapter->drv_stats->ierrors, 1, + __ATOMIC_RELAXED); + __atomic_store_n(&adapter->drv_stats->oerrors, 1, + __ATOMIC_RELAXED); + __atomic_store_n(&adapter->drv_stats->rx_nombuf, 1, + __ATOMIC_RELAXED); + __atomic_store_n(&adapter->drv_stats->rx_drops, 1, + __ATOMIC_RELAXED); } static int ena_stats_get(struct rte_eth_dev *dev, @@ -939,10 +942,14 @@ static int ena_stats_get(struct rte_eth_dev *dev, ena_stats.tx_bytes_low); /* Driver related stats */ - stats->imissed = rte_atomic64_read(&adapter->drv_stats->rx_drops); - stats->ierrors = rte_atomic64_read(&adapter->drv_stats->ierrors); - stats->oerrors = rte_atomic64_read(&adapter->drv_stats->oerrors); - stats->rx_nombuf = rte_atomic64_read(&adapter->drv_stats->rx_nombuf); + stats->imissed = __atomic_load_n(&adapter->drv_stats->rx_drops, + __ATOMIC_RELAXED); + stats->ierrors = __atomic_load_n(&adapter->drv_stats->ierrors, + __ATOMIC_RELAXED); + stats->oerrors = __atomic_load_n(&adapter->drv_stats->oerrors, + __ATOMIC_RELAXED); + stats->rx_nombuf = __atomic_load_n(&adapter->drv_stats->rx_nombuf, + __ATOMIC_RELAXED); max_rings_stats = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); @@ -1376,7 +1383,8 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count) /* get resources for incoming packets */ rc = rte_mempool_get_bulk(rxq->mb_pool, (void **)mbufs, count); if (unlikely(rc < 0)) { - rte_atomic64_inc(&rxq->adapter->drv_stats->rx_nombuf); + __atomic_add_fetch(&rxq->adapter->drv_stats->rx_nombuf, 1, + __ATOMIC_RELAXED); ++rxq->rx_stats.mbuf_alloc_fail; PMD_RX_LOG(DEBUG, "there are no enough free buffers"); return 0; @@ -2074,7 +2082,9 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, if (unlikely(mbuf_head->ol_flags & (PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD))) { - rte_atomic64_inc(&rx_ring->adapter->drv_stats->ierrors); + __atomic_add_fetch + (&rx_ring->adapter->drv_stats->ierrors, + 1, __ATOMIC_RELAXED); ++rx_ring->rx_stats.bad_csum; } @@ -2214,7 +2224,8 @@ static int ena_check_and_linearize_mbuf(struct ena_ring *tx_ring, rc = rte_pktmbuf_linearize(mbuf); if (unlikely(rc)) { PMD_DRV_LOG(WARNING, "Mbuf linearize failed\n"); - rte_atomic64_inc(&tx_ring->adapter->drv_stats->ierrors); + __atomic_add_fetch(&tx_ring->adapter->drv_stats->ierrors, + 1, __ATOMIC_RELAXED); ++tx_ring->tx_stats.linearize_failed; return rc; } @@ -2682,7 +2693,8 @@ static void ena_keep_alive(void *adapter_data, desc = (struct ena_admin_aenq_keep_alive_desc *)aenq_e; rx_drops = ((uint64_t)desc->rx_drops_high << 32) | desc->rx_drops_low; - rte_atomic64_set(&adapter->drv_stats->rx_drops, rx_drops); + __atomic_store_n(&adapter->drv_stats->rx_drops, rx_drops, + __ATOMIC_RELAXED); } /** diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h index af5eeea28..e7d39c09f 100644 --- a/drivers/net/ena/ena_ethdev.h +++ b/drivers/net/ena/ena_ethdev.h @@ -129,10 +129,10 @@ enum ena_adapter_state { }; struct ena_driver_stats { - rte_atomic64_t ierrors; - rte_atomic64_t oerrors; - rte_atomic64_t rx_nombuf; - rte_atomic64_t rx_drops; + uint64_t ierrors; + uint64_t oerrors; + uint64_t rx_nombuf; + uint64_t rx_drops; }; struct ena_stats_dev { -- 2.17.1