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 07840A034E; Tue, 22 Feb 2022 19:13:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 568D8411CE; Tue, 22 Feb 2022 19:12:31 +0100 (CET) Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by mails.dpdk.org (Postfix) with ESMTP id 33BE54115B for ; Tue, 22 Feb 2022 19:12:30 +0100 (CET) Received: by mail-ej1-f54.google.com with SMTP id hw13so45210466ejc.9 for ; Tue, 22 Feb 2022 10:12:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Quukpr87oHu5zHTSVmMY3v/pn3oK0i492+xvTSigoe4=; b=uiPctX0A3+YnxZviNoEzweZ8jtNXe/D+m6cwrC2/7OyMhTlVHPI+HWc06enWpTHGLr ap/NHL8fCoX+Z1wyrcitwt81eXQv2hDt7iz2wOfQoYa/yJAMNtQx+JWduf8IUOGO9GrN eRZy8mL52LfvQOWEfyhZcsT8kjiLo698XNi+lK/M8ppamxyZ9j98sEmN98EjEQybnWqJ 07rnLIBnwVOidxfAOOYgZacKw2xhxwwKV4mUFFf3IjYd7HqJ6TbPq7XMz77kn8omIQv/ i/Z8My4xEjNDv5wEZcKf88gs8ejRG1656DUQKg7XRMBav0duP5iu/X4qlzb1sCr7mCjL yvCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Quukpr87oHu5zHTSVmMY3v/pn3oK0i492+xvTSigoe4=; b=IVUExp536qBcRw5F+ZNj05Xssn5un8gOd+uvqZ4aSzpBCYPGYk4eGC0U8VPFzdy7lg qqWmI0u9I7URZkf7uk+Cr6BwdukFqYhU0Di39DmzNbhSoOpo+yqbFUsWhO60ZKp82/nJ qG28EK+Id2yIuD8tD9Ci/+S2qUx8qg940M13fDM73TP15hE8cnzr5Mmw+gSqlIdI2kDl 4oZBSGZEj//EOmctB/CYs7aa4IGCavnm2+jP1yrxez65JSAySjFZ7fQzXpo4MAWyC6pR 9sQI1fysWN2c1YtNecNpVYJY2lZj/X44Euteh1P2HsjZ69vFbR3oWW3AAl2QAIaX0k26 bkuA== X-Gm-Message-State: AOAM533l54akjyDog1ZAERXxnExrvDAi82fqRuJzXRLYYqRo8uxH/H07 RngG7FBBCxOkZlRDu2qaf15dUMZa2NxdCw== X-Google-Smtp-Source: ABdhPJw7QFx03iGGicdvq596EiQAQrgFfhW8dOIEbvfcJtt+ItOczKVgVg4xzmq+gWog4X9ihjbeoQ== X-Received: by 2002:a17:906:4116:b0:6cd:1980:5ad0 with SMTP id j22-20020a170906411600b006cd19805ad0mr21575323ejk.595.1645553546149; Tue, 22 Feb 2022 10:12:26 -0800 (PST) Received: from DESKTOP-U5LNN3J.localdomain (89-79-181-52.dynamic.chello.pl. [89.79.181.52]) by smtp.gmail.com with ESMTPSA id y21sm10610153eda.38.2022.02.22.10.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 10:12:25 -0800 (PST) From: Michal Krawczyk To: dev@dpdk.org Cc: shaibran@amazon.com, upstream@semihalf.com, Michal Krawczyk , Dawid Gorecki Subject: [PATCH v2 12/21] net/ena/base: make IO memzone unique per port Date: Tue, 22 Feb 2022 19:11:37 +0100 Message-Id: <20220222181146.28882-13-mk@semihalf.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220222181146.28882-1-mk@semihalf.com> References: <20220222160634.24489-1-mk@semihalf.com> <20220222181146.28882-1-mk@semihalf.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 Originally, the ena_com memzone counter was shared by ports, which caused the memzones to be harder to identify and could potentially lead to race and because of that the counter had to be atomic. This atomic counter was global variable and it couldn't work in the multiprocess implementation. The memzone is now being identified by the local to port memzone counter and the port ID - both of those information can be found in the shared data, so it can be probed easily. Signed-off-by: Michal Krawczyk Reviewed-by: Dawid Gorecki Reviewed-by: Shai Brandes --- doc/guides/nics/features/ena.ini | 1 + drivers/net/ena/base/ena_plat_dpdk.h | 62 ++++++++-------------------- drivers/net/ena/ena_ethdev.c | 52 ++++++++++++++++++++++- drivers/net/ena/ena_ethdev.h | 2 + 4 files changed, 71 insertions(+), 46 deletions(-) diff --git a/doc/guides/nics/features/ena.ini b/doc/guides/nics/features/ena.ini index 4db1db11f4..55690aaf5a 100644 --- a/doc/guides/nics/features/ena.ini +++ b/doc/guides/nics/features/ena.ini @@ -17,6 +17,7 @@ L3 checksum offload = Y L4 checksum offload = Y Basic stats = Y Extended stats = Y +Multiprocess aware = Y Linux = Y ARMv8 = Y x86-32 = Y diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index 41db883c63..8f2b3a87c2 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -202,35 +203,20 @@ typedef struct { #define ENA_GET_SYSTEM_TIMEOUT(timeout_us) \ ((timeout_us) * rte_get_timer_hz() / 1000000 + rte_get_timer_cycles()) -/* - * 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; +const struct rte_memzone * +ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size, + int socket_id, unsigned int alignment, void **virt_addr, + dma_addr_t *phys_addr); #define ENA_MEM_ALLOC_COHERENT_ALIGNED( \ dmadev, size, virt, phys, mem_handle, alignment) \ do { \ - const struct rte_memzone *mz = NULL; \ - ENA_TOUCH(dmadev); \ - 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)); \ - mz = rte_memzone_reserve_aligned(z_name, (size), \ - SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG,\ - alignment); \ - mem_handle = mz; \ - } \ - if (mz == NULL) { \ - virt = NULL; \ - phys = 0; \ - } else { \ - memset(mz->addr, 0, (size)); \ - virt = mz->addr; \ - phys = mz->iova; \ - } \ + void *virt_addr; \ + dma_addr_t phys_addr; \ + (mem_handle) = ena_mem_alloc_coherent((dmadev), (size), \ + SOCKET_ID_ANY, (alignment), &virt_addr, &phys_addr); \ + (virt) = virt_addr; \ + (phys) = phys_addr; \ } while (0) #define ENA_MEM_ALLOC_COHERENT(dmadev, size, virt, phys, mem_handle) \ ENA_MEM_ALLOC_COHERENT_ALIGNED(dmadev, size, virt, phys, \ @@ -242,25 +228,13 @@ extern rte_atomic64_t ena_alloc_cnt; #define ENA_MEM_ALLOC_COHERENT_NODE_ALIGNED( \ dmadev, size, virt, phys, mem_handle, node, dev_node, alignment) \ do { \ - const struct rte_memzone *mz = NULL; \ - ENA_TOUCH(dmadev); ENA_TOUCH(dev_node); \ - 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)); \ - mz = rte_memzone_reserve_aligned(z_name, (size), \ - node, RTE_MEMZONE_IOVA_CONTIG, alignment); \ - mem_handle = mz; \ - } \ - if (mz == NULL) { \ - virt = NULL; \ - phys = 0; \ - } else { \ - memset(mz->addr, 0, (size)); \ - virt = mz->addr; \ - phys = mz->iova; \ - } \ + void *virt_addr; \ + dma_addr_t phys_addr; \ + ENA_TOUCH(dev_node); \ + (mem_handle) = ena_mem_alloc_coherent((dmadev), (size), \ + (node), (alignment), &virt_addr, &phys_addr); \ + (virt) = virt_addr; \ + (phys) = phys_addr; \ } while (0) #define ENA_MEM_ALLOC_COHERENT_NODE( \ dmadev, size, virt, phys, mem_handle, node, dev_node) \ diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index ff6f27e4ad..8f30718f2c 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -2110,8 +2110,10 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev) } ena_dev->reg_bar = adapter->regs; - /* This is a dummy pointer for ena_com functions. */ - ena_dev->dmadev = adapter; + /* Pass device data as a pointer which can be passed to the IO functions + * by the ena_com (for example - the memory allocation). + */ + ena_dev->dmadev = eth_dev->data; adapter->id_number = adapters_found; @@ -3488,6 +3490,52 @@ int ena_mp_indirect_table_get(struct ena_adapter *adapter, indirect_table); } +/********************************************************************* + * ena_plat_dpdk.h functions implementations + *********************************************************************/ + +const struct rte_memzone * +ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size, + int socket_id, unsigned int alignment, void **virt_addr, + dma_addr_t *phys_addr) +{ + char z_name[RTE_MEMZONE_NAMESIZE]; + struct ena_adapter *adapter = data->dev_private; + const struct rte_memzone *memzone; + int rc; + + rc = snprintf(z_name, RTE_MEMZONE_NAMESIZE, "ena_p%d_mz%" PRIu64 "", + data->port_id, adapter->memzone_cnt); + if (rc >= RTE_MEMZONE_NAMESIZE) { + PMD_DRV_LOG(ERR, + "Name for the ena_com memzone is too long. Port: %d, mz_num: %" PRIu64 "\n", + data->port_id, adapter->memzone_cnt); + goto error; + } + adapter->memzone_cnt++; + + memzone = rte_memzone_reserve_aligned(z_name, size, socket_id, + RTE_MEMZONE_IOVA_CONTIG, alignment); + if (memzone == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate ena_com memzone: %s\n", + z_name); + goto error; + } + + memset(memzone->addr, 0, size); + *virt_addr = memzone->addr; + *phys_addr = memzone->iova; + + return memzone; + +error: + *virt_addr = NULL; + *phys_addr = 0; + + return NULL; +} + + /********************************************************************* * PMD configuration *********************************************************************/ diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h index 01cf0ef5db..ca3e5ed691 100644 --- a/drivers/net/ena/ena_ethdev.h +++ b/drivers/net/ena/ena_ethdev.h @@ -308,6 +308,8 @@ struct ena_adapter { uint64_t missing_tx_completion_to; uint64_t missing_tx_completion_budget; uint64_t tx_cleanup_stall_delay; + + uint64_t memzone_cnt; }; int ena_mp_indirect_table_set(struct ena_adapter *adapter); -- 2.25.1