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 37CCAA0524; Thu, 6 May 2021 16:27:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E6D441168; Thu, 6 May 2021 16:26:09 +0200 (CEST) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by mails.dpdk.org (Postfix) with ESMTP id EB3C84115F for ; Thu, 6 May 2021 16:26:05 +0200 (CEST) Received: by mail-lf1-f41.google.com with SMTP id t11so8023865lfl.11 for ; Thu, 06 May 2021 07:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ukRfbvKC/YDCGyLZxijrxJ6E6jo2SKIcvP2YjC+olqo=; b=iTLV1F12r9iT63xo+szlhxtq1grpNEszNOu4JDGgfMrRbaudcwESUSqycxrjaWkp7U 1ivz7fSOq84BA/iCMPp7isehfOjaLBhjOLALY6Zezro2WWz59ZdiHkewsatL+rsGpxZD bN8dOU4YrzBrQiZ7x09QY7zgMy+sxUXzuOrBfeqiJvQbM/jqUIqgJmqL6ItJrI0jbhlK 77BrUvcDlyAdqxY9KapOB2t5ZIIuxvkdn78E7TZKYmM1QGMCJMdr1b0vhKXgCbnl1VOA L0TW3+L+pKr69Gr8kbPTf0h+iyBdvlHUHcqaQvpwMu0Bms5JD9VPc2ggxvgsJcj5JxCn 7a5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ukRfbvKC/YDCGyLZxijrxJ6E6jo2SKIcvP2YjC+olqo=; b=lHVmUZofeAfQoK5doZpTgAhuVIoFssPoTl0wpLY2CyU36i2Z0/kW/YmG3JrKqWK/iI 5pZrFGM9wW3AQ92t/tUyX6HfhbEDWunvfLHAKjMDSWqaK4Gh06+reOvRS6NkG6lI68Hs AXZs076EJsajKlxu3EPntoPN6W9m6GpCPEeeh/UiL60bc/LJ5pjRtgF6/ffjJMTSDQ+b kZjgyuPhAG9H/11qDru/PAiOQEnjqfoeusfNObt9fsqq5KY5gGJGJut8rEWn4JU8URqa n7fZeiXOSYpS09lgYsRUz2GhtydMZJRrsHjghn4B3XZTzO5ZZP57rt6EXusZ1PYHHol4 nVpQ== X-Gm-Message-State: AOAM531qwKLDQjKEx8XyV0j0lqaH4N4GlTtkREW4/2r8Cn8nzAHdrcB/ NzhatW4EBg75j9fW9K1aAgTljd0PyH8fD7jd X-Google-Smtp-Source: ABdhPJyOgWqoPnbYkrK2xWB2+ua4MUIFtha0wY381wh4cG9XVkjFFZWfn0Wxxt0jxXmCgQbBbCeM9Q== X-Received: by 2002:a05:6512:b90:: with SMTP id b16mr3067231lfv.483.1620311165074; Thu, 06 May 2021 07:26:05 -0700 (PDT) Received: from DESKTOP-U5LNN3J.localdomain (89-79-189-199.dynamic.chello.pl. [89.79.189.199]) by smtp.gmail.com with ESMTPSA id b40sm892908ljr.101.2021.05.06.07.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 07:26:04 -0700 (PDT) From: Michal Krawczyk To: dev@dpdk.org Cc: ndagan@amazon.com, gtzalik@amazon.com, igorch@amazon.com, upstream@semihalf.com, Stanislaw Kardach , Michal Krawczyk , Shay Agroskin Date: Thu, 6 May 2021 16:25:21 +0200 Message-Id: <20210506142526.28245-18-mk@semihalf.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210506142526.28245-1-mk@semihalf.com> References: <20210505073348.6394-1-mk@semihalf.com> <20210506142526.28245-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 17/22] net/ena: support SMP for mz alloc counter 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 Sender: "dev" From: Stanislaw Kardach Introduce a memory area for ENA driver shared between all the processes of a same prefix (memzone backed). Move the memzone allocation counter for ENA_MEM_ALLOC_COHERENT there so that all processes may utilize it. Signed-off-by: Stanislaw Kardach Reviewed-by: Michal Krawczyk Reviewed-by: Igor Chauskin Reviewed-by: Shay Agroskin --- drivers/net/ena/base/ena_plat_dpdk.h | 6 ++-- drivers/net/ena/ena_ethdev.c | 46 +++++++++++++++++++++++++++- drivers/net/ena/ena_ethdev.h | 8 +++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index 1d0454bebe..e17970361a 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -209,7 +209,7 @@ typedef struct { * Each rte_memzone should have unique name. * To satisfy it, count number of allocations and add it to name. */ -extern rte_atomic64_t ena_alloc_cnt; +extern rte_atomic64_t *ena_alloc_cnt; #define ENA_MEM_ALLOC_COHERENT_ALIGNED( \ dmadev, size, virt, phys, mem_handle, alignment) \ @@ -219,7 +219,7 @@ extern rte_atomic64_t ena_alloc_cnt; if (size > 0) { \ char z_name[RTE_MEMZONE_NAMESIZE]; \ snprintf(z_name, sizeof(z_name), "ena_alloc_%"PRIi64"",\ - rte_atomic64_add_return(&ena_alloc_cnt, 1)); \ + rte_atomic64_add_return(ena_alloc_cnt, 1)); \ mz = rte_memzone_reserve_aligned(z_name, size, \ SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG,\ alignment); \ @@ -249,7 +249,7 @@ extern rte_atomic64_t ena_alloc_cnt; if (size > 0) { \ char z_name[RTE_MEMZONE_NAMESIZE]; \ snprintf(z_name, sizeof(z_name), "ena_alloc_%"PRIi64"",\ - rte_atomic64_add_return(&ena_alloc_cnt, 1)); \ + rte_atomic64_add_return(ena_alloc_cnt, 1)); \ mz = rte_memzone_reserve_aligned(z_name, size, \ node, RTE_MEMZONE_IOVA_CONTIG, alignment); \ mem_handle = mz; \ diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index 5d107775f4..0780e2fee2 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -83,11 +83,15 @@ struct ena_stats { /* Device arguments */ #define ENA_DEVARG_LARGE_LLQ_HDR "large_llq_hdr" +#define ENA_MZ_SHARED_DATA "ena_shared_data" + /* * Each rte_memzone should have unique name. * To satisfy it, count number of allocation and add it to name. */ -rte_atomic64_t ena_alloc_cnt; +rte_atomic64_t *ena_alloc_cnt; + +struct ena_shared_data *ena_shared_data; static const struct ena_stats ena_stats_global_strings[] = { ENA_STAT_GLOBAL_ENTRY(wd_expired), @@ -1752,6 +1756,42 @@ static uint32_t ena_calc_max_io_queue_num(struct ena_com_dev *ena_dev, return max_num_io_queues; } +static void ena_prepare_shared_data(struct ena_shared_data *shared_data) +{ + memset(shared_data, 0, sizeof(*shared_data)); +} + +static int ena_shared_data_init(void) +{ + const struct rte_memzone *mz; + + if (ena_shared_data != NULL) + return 0; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* Allocate shared memory. */ + mz = rte_memzone_reserve(ENA_MZ_SHARED_DATA, + sizeof(*ena_shared_data), + SOCKET_ID_ANY, 0); + if (mz == NULL) { + PMD_INIT_LOG(CRIT, "Cannot allocate ena shared data"); + return -rte_errno; + } + ena_prepare_shared_data(mz->addr); + } else { + /* Lookup allocated shared memory. */ + mz = rte_memzone_lookup(ENA_MZ_SHARED_DATA); + if (mz == NULL) { + PMD_INIT_LOG(CRIT, "Cannot attach ena shared data"); + return -rte_errno; + } + } + ena_shared_data = mz->addr; + /* Setup ENA_MEM memzone name counter. */ + ena_alloc_cnt = &ena_shared_data->mz_alloc_cnt; + return 0; +} + static int eth_ena_dev_init(struct rte_eth_dev *eth_dev) { struct ena_calc_queue_size_ctx calc_queue_ctx = { 0 }; @@ -1773,6 +1813,10 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev) eth_dev->tx_pkt_burst = ð_ena_xmit_pkts; eth_dev->tx_pkt_prepare = ð_ena_prep_pkts; + rc = ena_shared_data_init(); + if (rc != 0) + return rc; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h index ae235897ee..e8858c6118 100644 --- a/drivers/net/ena/ena_ethdev.h +++ b/drivers/net/ena/ena_ethdev.h @@ -207,6 +207,14 @@ struct ena_offloads { bool rx_csum_supported; }; +/* Holds data shared between all instances of ENA PMD. */ +struct ena_shared_data { + /* Each rte_memzone should have unique name. + * To satisfy it, count number of allocation and add it to name. + */ + rte_atomic64_t mz_alloc_cnt; +}; + /* board specific private data structure */ struct ena_adapter { /* OS defined structs */ -- 2.25.1