From patchwork Tue Aug 1 16:54:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 27352 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id A8453A28E; Tue, 1 Aug 2017 18:56:09 +0200 (CEST) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id E97D1A1A6 for ; Tue, 1 Aug 2017 18:55:42 +0200 (CEST) Received: by mail-wm0-f47.google.com with SMTP id t201so20386456wmt.0 for ; Tue, 01 Aug 2017 09:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=DY7B3gYlC4XWE9a27qKu20XEPHe0S73Uz7tDnK726nI=; b=1oCgZv93twVlo2lsYrAC5MACDwB3QDuiIJvd8fqninYp8iToWuKHO2H+3ZGZlvks8Y I4FlB88mXRqm+xKML4Gom53xfsTgo3hyr9RvKKhtfQQB+LbXgZTsHg24Y4+QkzvC/4Ox Wy0WOts4kP0K05YXp9wOOWZfiC24v5oL1Apwa2VJukRRr61EcTyy3ax/Ee2HrQv8syPh PWbG+WNXK+XpyOE3xbcsJfABdZrBMYjrOR9EtisfpRvHcJ1taUrCxg4nZ7Hyo08EK8/t 427hLvH8zFtzGRcnckBURYYJxIG5DtDPq21LOhMEMwXlOz4l5bV24vb08VTPMH2R69VX KiTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=DY7B3gYlC4XWE9a27qKu20XEPHe0S73Uz7tDnK726nI=; b=OZ/uOWAGE8Cbgk8MAC+vH3q4xTMipbY/Uy/RxOzspWW4T6oH/hPY8wACP01GL5Kfmy OwV6F1Du8QaQmLYEOw+iK/DdzRhInMQ1tvhxzx2vJ3R7AcgiEdRr+6N5Bhk9Jo3x5JUQ 9pYmhG0PoKMgB/q4PnU3PVNMz7gO2jwBAYWuUtSKF9u0jku1dYAE/zNLdffAKqvs3gCC NQPp67FkzDb7JxJSgOYsHOa+DC20wyrGkknEUHIPmlHAPQ761/aiueRPI0QT90lL1GLW vzjJOdcjerseL6UweFjMD4qeNVQvhxzAt8Krau2SZtbuGJR92y+tpkf6NzjCjXM98rER K4tA== X-Gm-Message-State: AIVw113r7aBXlIGL7VKo2L3Mqwts78liNgBFNp5QtJHtbBRtOfFlQb+V Enhx1vhBq8+A2uK1l7Y= X-Received: by 10.28.175.135 with SMTP id y129mr1830011wme.87.1501606542135; Tue, 01 Aug 2017 09:55:42 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id x98sm48960511wrb.47.2017.08.01.09.55.40 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Aug 2017 09:55:41 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Tue, 1 Aug 2017 18:54:23 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 36/48] net/mlx4: refactor interrupt FD settings 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" File descriptors used for interrupts processing must be made non-blocking. Doing so as soon as they are opened instead of waiting until they are needed is more efficient as it avoids performing redundant system calls and run through their associated error-handling code later on. Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/Makefile | 1 + drivers/net/mlx4/mlx4.c | 63 ++++++++++++++---------------------- drivers/net/mlx4/mlx4.h | 4 +++ drivers/net/mlx4/mlx4_utils.c | 66 ++++++++++++++++++++++++++++++++++++++ drivers/net/mlx4/mlx4_utils.h | 4 +++ 5 files changed, 99 insertions(+), 39 deletions(-) diff --git a/drivers/net/mlx4/Makefile b/drivers/net/mlx4/Makefile index 78ea350..77aaad2 100644 --- a/drivers/net/mlx4/Makefile +++ b/drivers/net/mlx4/Makefile @@ -37,6 +37,7 @@ LIB = librte_pmd_mlx4.a # Sources. SRCS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += mlx4.c SRCS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += mlx4_flow.c +SRCS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += mlx4_utils.c # Basic CFLAGS. CFLAGS += -O3 diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 9f1eb4e..d6d4be7 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include @@ -1871,6 +1870,12 @@ rxq_setup(struct rte_eth_dev *dev, struct rxq *rxq, uint16_t desc, (void *)dev, strerror(rte_errno)); goto error; } + if (mlx4_fd_set_non_blocking(tmpl.channel->fd) < 0) { + ERROR("%p: unable to make Rx interrupt completion" + " channel non-blocking: %s", + (void *)dev, strerror(rte_errno)); + goto error; + } } tmpl.cq = ibv_create_cq(priv->ctx, desc, NULL, tmpl.channel, 0); if (tmpl.cq == NULL) { @@ -2907,7 +2912,6 @@ static int priv_dev_interrupt_handler_install(struct priv *priv, struct rte_eth_dev *dev) { - int flags; int rc; /* @@ -2918,29 +2922,17 @@ priv_dev_interrupt_handler_install(struct priv *priv, priv->intr_conf.rmv && priv->intr_handle.fd) return 0; - assert(priv->ctx->async_fd > 0); - flags = fcntl(priv->ctx->async_fd, F_GETFL); - rc = fcntl(priv->ctx->async_fd, F_SETFL, flags | O_NONBLOCK); - if (rc < 0) { - rte_errno = errno ? errno : EINVAL; - INFO("failed to change file descriptor async event queue"); - dev->data->dev_conf.intr_conf.lsc = 0; - dev->data->dev_conf.intr_conf.rmv = 0; - return -rte_errno; - } else { - priv->intr_handle.fd = priv->ctx->async_fd; - rc = rte_intr_callback_register(&priv->intr_handle, - mlx4_dev_interrupt_handler, - dev); - if (rc) { - rte_errno = -rc; - ERROR("rte_intr_callback_register failed " - " (rte_errno: %s)", strerror(rte_errno)); - priv->intr_handle.fd = -1; - return -rte_errno; - } - } - return 0; + priv->intr_handle.fd = priv->ctx->async_fd; + rc = rte_intr_callback_register(&priv->intr_handle, + mlx4_dev_interrupt_handler, + dev); + if (!rc) + return 0; + rte_errno = -rc; + ERROR("rte_intr_callback_register failed (rte_errno: %s)", + strerror(rte_errno)); + priv->intr_handle.fd = -1; + return -rte_errno; } /** @@ -3081,9 +3073,6 @@ priv_rx_intr_vec_enable(struct priv *priv) } for (i = 0; i != n; ++i) { struct rxq *rxq = (*priv->rxqs)[i]; - int fd; - int flags; - int rc; /* Skip queues that cannot request interrupts. */ if (!rxq || !rxq->channel) { @@ -3101,18 +3090,8 @@ priv_rx_intr_vec_enable(struct priv *priv) priv_rx_intr_vec_disable(priv); return -rte_errno; } - fd = rxq->channel->fd; - flags = fcntl(fd, F_GETFL); - rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK); - if (rc < 0) { - rte_errno = errno; - ERROR("failed to make Rx interrupt file descriptor" - " %d non-blocking for queue index %d", fd, i); - priv_rx_intr_vec_disable(priv); - return -rte_errno; - } intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + count; - intr_handle->efds[count] = fd; + intr_handle->efds[count] = rxq->channel->fd; count++; } if (!count) @@ -3423,6 +3402,12 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) DEBUG("port %d is not active: \"%s\" (%d)", port, ibv_port_state_str(port_attr.state), port_attr.state); + /* Make asynchronous FD non-blocking to handle interrupts. */ + if (mlx4_fd_set_non_blocking(ctx->async_fd) < 0) { + ERROR("cannot make asynchronous FD non-blocking: %s", + strerror(rte_errno)); + goto port_error; + } /* Allocate protection domain. */ pd = ibv_alloc_pd(ctx); if (pd == NULL) { diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index ed0e6cd..6104842 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -46,6 +46,10 @@ #pragma GCC diagnostic error "-Wpedantic" #endif +#include +#include +#include + /* Request send completion once in every 64 sends, might be less. */ #define MLX4_PMD_TX_PER_COMP_REQ 64 diff --git a/drivers/net/mlx4/mlx4_utils.c b/drivers/net/mlx4/mlx4_utils.c new file mode 100644 index 0000000..fcf76c9 --- /dev/null +++ b/drivers/net/mlx4/mlx4_utils.c @@ -0,0 +1,66 @@ +/*- + * BSD LICENSE + * + * Copyright 2017 6WIND S.A. + * Copyright 2017 Mellanox + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of 6WIND S.A. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * Utility functions used by the mlx4 driver. + */ + +#include +#include +#include + +#include + +#include "mlx4_utils.h" + +/** + * Make a file descriptor non-blocking. + * + * @param fd + * File descriptor to alter. + * + * @return + * 0 on success, negative errno value otherwise and rte_errno is set. + */ +int +mlx4_fd_set_non_blocking(int fd) +{ + int ret = fcntl(fd, F_GETFL); + + if (ret != -1 && !fcntl(fd, F_SETFL, ret | O_NONBLOCK)) + return 0; + assert(errno); + rte_errno = errno; + return -rte_errno; +} diff --git a/drivers/net/mlx4/mlx4_utils.h b/drivers/net/mlx4/mlx4_utils.h index c404de2..0b9a96a 100644 --- a/drivers/net/mlx4/mlx4_utils.h +++ b/drivers/net/mlx4/mlx4_utils.h @@ -89,4 +89,8 @@ pmd_drv_log_basename(const char *s) #define WARN(...) PMD_DRV_LOG(WARNING, __VA_ARGS__) #define ERROR(...) PMD_DRV_LOG(ERR, __VA_ARGS__) +/* mlx4_utils.c */ + +int mlx4_fd_set_non_blocking(int fd); + #endif /* MLX4_UTILS_H_ */