From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by dpdk.org (Postfix) with ESMTP id 2809BC360 for ; Tue, 21 Jun 2016 14:06:21 +0200 (CEST) Received: by mail-lf0-f49.google.com with SMTP id h129so20617984lfh.1 for ; Tue, 21 Jun 2016 05:06:21 -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; bh=hqYoSqobiUD6vlsWltaqxMF8Pea8CGk7X56AlCbzhZY=; b=c3P6bZPI9eEVp2SzW1culo0m3ycOIj+uZWiJLGdp9FHAK6KR6rwo5ZxAkECpZoWu64 1c91TD4+JS8uzqSoxkYVhiV3q/mnvgQiM8RtIE3yeE4ZIp+VqC/qN9TpRcPA4TD//8tE /vaZ414B7FT2bV4ndvAbOw4fzBeHWBZCrVNARMPY+ZEgA4HTQB8gBTKuaiT2CIy7FaJi CwxQNROiR7ImKX51wSf8v0B5HMTjK/v1h7gQ2VgCLbiMWpzPKDYatHKfqw3B5Cnj/QuT uo4ma6KHqCQaHNZ/SXfUqbbokBdRZP7Mwi5GXMdXoEQJPZtHzYuSybwKTQY+rqLA4lO4 HqSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hqYoSqobiUD6vlsWltaqxMF8Pea8CGk7X56AlCbzhZY=; b=HaHVty9cWN+gky1H+NPnTgv37D5F/jrTpNwmwXOXXwI4tFfv6DQEy/wN+cIGO5f8er qRFsfUa+MG+l+RVKBAflZAyl3yvjnUll8cTur1/QN3sq3Sfo6OCC07rlQ1Li7V8gbPRB VDE9YEF33K8TBm/MPeq435eimHmTnjxSCXbQyx1xAHCxRrlMA/qGaWwyr+v+rjpj1lf0 UPTuzf3Hl/huxaDdENEb6LnDo9ogXPKoViPtxv6wlK3j6xuVCFg3qRKvUWaOjfRoK3/K VLHFkbOqN03biPIXQTzi+ZuloE9T4Nxi6kL1PHzNgolzZIIGC8UnbinVfI6N8V3yLYKZ jcAQ== X-Gm-Message-State: ALyK8tIlEFLGQnUPbZomMA1uQipqDBKY7kOm/ei+NE5dRwsVEDPYVd2GyHDDaFilCWQOcw== X-Received: by 10.25.38.206 with SMTP id m197mr4968601lfm.201.1466510780658; Tue, 21 Jun 2016 05:06:20 -0700 (PDT) Received: from anpa-dpdk-2.lab.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id t10sm6613629lfd.18.2016.06.21.05.06.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jun 2016 05:06:20 -0700 (PDT) From: Jan Medala To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Jan Medala , Alexander Matushevsky , Jakub Palider Date: Tue, 21 Jun 2016 14:06:01 +0200 Message-Id: <1466510763-19569-5-git-send-email-jan@semihalf.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1466510763-19569-1-git-send-email-jan@semihalf.com> References: <1466099690-28085-1-git-send-email-jan@semihalf.com> <1466510763-19569-1-git-send-email-jan@semihalf.com> Subject: [dpdk-dev] [PATCH v2 4/6] ena: allocate coherent memory in node-aware way X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 12:06:21 -0000 Signed-off-by: Alexander Matushevsky Signed-off-by: Jakub Palider Signed-off-by: Jan Medala --- drivers/net/ena/base/ena_com.c | 51 ++++++++++++++++++++++++++---------- drivers/net/ena/base/ena_plat_dpdk.h | 23 ++++++++++++++++ drivers/net/ena/ena_ethdev.c | 15 +++++++++++ 3 files changed, 75 insertions(+), 14 deletions(-) diff --git a/drivers/net/ena/base/ena_com.c b/drivers/net/ena/base/ena_com.c index b5b8cd9..a3649d8 100644 --- a/drivers/net/ena/base/ena_com.c +++ b/drivers/net/ena/base/ena_com.c @@ -329,6 +329,7 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_dev, struct ena_com_io_sq *io_sq) { size_t size; + int dev_node; ENA_TOUCH(ctx); @@ -341,15 +342,29 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_dev, size = io_sq->desc_entry_size * io_sq->q_depth; - if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST) - ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, - size, - io_sq->desc_addr.virt_addr, - io_sq->desc_addr.phys_addr, - io_sq->desc_addr.mem_handle); - else - io_sq->desc_addr.virt_addr = - ENA_MEM_ALLOC(ena_dev->dmadev, size); + if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST) { + ENA_MEM_ALLOC_COHERENT_NODE(ena_dev->dmadev, + size, + io_sq->desc_addr.virt_addr, + io_sq->desc_addr.phys_addr, + ctx->numa_node, + dev_node); + if (!io_sq->desc_addr.virt_addr) + ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, + size, + io_sq->desc_addr.virt_addr, + io_sq->desc_addr.phys_addr, + io_sq->desc_addr.mem_handle); + } else { + ENA_MEM_ALLOC_NODE(ena_dev->dmadev, + size, + io_sq->desc_addr.virt_addr, + ctx->numa_node, + dev_node); + if (!io_sq->desc_addr.virt_addr) + io_sq->desc_addr.virt_addr = + ENA_MEM_ALLOC(ena_dev->dmadev, size); + } if (!io_sq->desc_addr.virt_addr) { ena_trc_err("memory allocation failed"); @@ -368,6 +383,7 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_dev, struct ena_com_io_cq *io_cq) { size_t size; + int prev_node; ENA_TOUCH(ctx); memset(&io_cq->cdesc_addr, 0x0, sizeof(struct ena_com_io_desc_addr)); @@ -380,11 +396,18 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_dev, size = io_cq->cdesc_entry_size_in_bytes * io_cq->q_depth; - ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, - size, - io_cq->cdesc_addr.virt_addr, - io_cq->cdesc_addr.phys_addr, - io_cq->cdesc_addr.mem_handle); + ENA_MEM_ALLOC_COHERENT_NODE(ena_dev->dmadev, + size, + io_cq->cdesc_addr.virt_addr, + io_cq->cdesc_addr.phys_addr, + ctx->numa_node, + prev_node); + if (!io_cq->cdesc_addr.virt_addr) + ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, + size, + io_cq->cdesc_addr.virt_addr, + io_cq->cdesc_addr.phys_addr, + io_cq->cdesc_addr.mem_handle); if (!io_cq->cdesc_addr.virt_addr) { ena_trc_err("memory allocation failed"); diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index 3c0203f..b1ed80c 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -196,6 +196,29 @@ typedef uint64_t dma_addr_t; ENA_TOUCH(dmadev); \ rte_free(virt); }) +#define ENA_MEM_ALLOC_COHERENT_NODE(dmadev, size, virt, phys, node, dev_node) \ + do { \ + const struct rte_memzone *mz; \ + char z_name[RTE_MEMZONE_NAMESIZE]; \ + ENA_TOUCH(dmadev); ENA_TOUCH(dev_node); \ + snprintf(z_name, sizeof(z_name), \ + "ena_alloc_%d", ena_alloc_cnt++); \ + mz = rte_memzone_reserve(z_name, size, node, 0); \ + virt = mz->addr; \ + phys = mz->phys_addr; \ + } while (0) + +#define ENA_MEM_ALLOC_NODE(dmadev, size, virt, node, dev_node) \ + do { \ + const struct rte_memzone *mz; \ + char z_name[RTE_MEMZONE_NAMESIZE]; \ + ENA_TOUCH(dmadev); ENA_TOUCH(dev_node); \ + snprintf(z_name, sizeof(z_name), \ + "ena_alloc_%d", ena_alloc_cnt++); \ + mz = rte_memzone_reserve(z_name, size, node, 0); \ + virt = mz->addr; \ + } while (0) + #define ENA_MEM_ALLOC(dmadev, size) rte_zmalloc(NULL, size, 1) #define ENA_MEM_FREE(dmadev, ptr) ({ENA_TOUCH(dmadev); rte_free(ptr); }) diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index 9ad35b3..d0927f7 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "ena_ethdev.h" #include "ena_logs.h" @@ -235,6 +236,18 @@ static struct eth_dev_ops ena_dev_ops = { .reta_query = ena_rss_reta_query, }; +#define NUMA_NO_NODE SOCKET_ID_ANY + +static inline int ena_cpu_to_node(int cpu) +{ + struct rte_config *config = rte_eal_get_configuration(); + + if (likely(cpu < RTE_MAX_MEMZONE)) + return config->mem_config->memzone[cpu].socket_id; + + return NUMA_NO_NODE; +} + static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf, struct ena_com_rx_ctx *ena_rx_ctx) { @@ -962,6 +975,7 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev, ctx.msix_vector = -1; /* admin interrupts not used */ ctx.mem_queue_type = ena_dev->tx_mem_queue_type; ctx.queue_size = adapter->tx_ring_size; + ctx.numa_node = ena_cpu_to_node(queue_idx); rc = ena_com_create_io_queue(ena_dev, &ctx); if (rc) { @@ -1052,6 +1066,7 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev, ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST; ctx.msix_vector = -1; /* admin interrupts not used */ ctx.queue_size = adapter->rx_ring_size; + ctx.numa_node = ena_cpu_to_node(queue_idx); rc = ena_com_create_io_queue(ena_dev, &ctx); if (rc) -- 2.8.2