From patchwork Wed Oct 11 14:35:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 30147 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 775051B217; Wed, 11 Oct 2017 16:42:35 +0200 (CEST) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 5BF751B216 for ; Wed, 11 Oct 2017 16:42:34 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id q124so5444950wmb.0 for ; Wed, 11 Oct 2017 07:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wjvR+y/w+PknFYk1GQZwh2CeTeLT4678WvusIUwDsq4=; b=GqYV45igJZw69Hc/sSU1i2bAk6XTyKUsfVYX5QOCTOVuHX1RkMFm1WJ8ZNDyHoT/rZ XdBdT5RT/TGP2pOWfvNYR7agqSuVuCsuGnECUCyQX58ALS1MWc+NRXcwSsXr9pWDK5Tl mbsVAoB199e8j2z3jF5gVnYQxMoacReVe5/9XQl6LX5ZG1f2voq+JeNTkyKhkHTM/Obe LlEJakDU9Ni9piX206495d75gcWzRkdCTlrBLA587kgp0mFIq8rwfUDJADOFSlNxiUxq Znc8/xbPmwcqd7awVFXAhqEKzU2A/eSgFOwG9vqDXz633c97TgNrzurFfmzVl7X84s0w wGFA== 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; bh=wjvR+y/w+PknFYk1GQZwh2CeTeLT4678WvusIUwDsq4=; b=RryN4n2Iawqz6YStmjJXm5A/qKUP5X5FOE8yDfz221dZeLACNwndIdVCCHA2XN1JKQ XWFoFeSHuKzTXpEOARE1rhLJ3Ph5NFK09I5UusjqIYGxUobXLqaRNqrFYj/2jmc0jbf+ WXItHvRsBXZtwA47KWwYxZLkB1vPl9pD5HMzwY1NJNPwzZXKo1ae9vVOI1krqms27+hY tqWCktWYvZ+3Kc/rz9w0fqpmtMSfMkYFRo30ApJ5ExRYaZESzk/c1OOWiJET5jcJT+2Z ShGkQSIhlEpctDiUOAVl+/q/0uqorYPrRGnglgXW32Eqws/FGyocztHaySZjIU7NSnC3 ij0A== X-Gm-Message-State: AMCzsaVgxZz6MJlKig4vNXaD7TuWOGH2R7XbWe6yT0oQ7fybd2YpGI75 YzGcNoStc3oC8+H+UXlGU5nL7g== X-Google-Smtp-Source: AOwi7QDr6vDNVti6hWaY8qLRSjdCotef1G1CBGhMObc8BRsD9Zc9trp+Z/7VRlpJBPeOctQ7MQ3CDA== X-Received: by 10.28.30.22 with SMTP id e22mr13670222wme.121.1507732590133; Wed, 11 Oct 2017 07:36:30 -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 133sm15569254wmu.4.2017.10.11.07.36.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 07:36:29 -0700 (PDT) From: Adrien Mazarguil To: Ferruh Yigit Cc: dev@dpdk.org Date: Wed, 11 Oct 2017 16:35:13 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 11/29] net/mlx4: allocate drop flow resources on demand 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" Verbs QP and CQ resources for drop flow rules do not need to be permanently allocated, only when at least one rule needs them. Besides, struct rte_flow_drop is outside the mlx4 PMD name space and should never have been defined there. struct rte_flow is currently the only exception to this rule. Signed-off-by: Adrien Mazarguil Acked-by: Nelio Laranjeiro --- drivers/net/mlx4/mlx4.h | 3 +- drivers/net/mlx4/mlx4_flow.c | 138 ++++++++++++++++++++------------------ 2 files changed, 74 insertions(+), 67 deletions(-) diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index 1799951..f71679b 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -88,6 +88,7 @@ enum { /** Driver name reported to lower layers and used in log output. */ #define MLX4_DRIVER_NAME "net_mlx4" +struct mlx4_drop; struct rxq; struct txq; struct rte_flow; @@ -108,7 +109,7 @@ struct priv { uint32_t intr_alarm:1; /**< An interrupt alarm is scheduled. */ uint32_t isolated:1; /**< Toggle isolated mode. */ struct rte_intr_handle intr_handle; /**< Port interrupt handle. */ - struct rte_flow_drop *flow_drop_queue; /**< Flow drop queue. */ + struct mlx4_drop *drop; /**< Shared resources for drop flow rules. */ LIST_HEAD(, rte_flow) flows; /**< Configured flow rule handles. */ }; diff --git a/drivers/net/mlx4/mlx4_flow.c b/drivers/net/mlx4/mlx4_flow.c index 0a736b1..658c92f 100644 --- a/drivers/net/mlx4/mlx4_flow.c +++ b/drivers/net/mlx4/mlx4_flow.c @@ -125,9 +125,12 @@ struct mlx4_flow_proc_item { const enum rte_flow_item_type *const next_item; }; -struct rte_flow_drop { - struct ibv_qp *qp; /**< Verbs queue pair. */ - struct ibv_cq *cq; /**< Verbs completion queue. */ +/** Shared resources for drop flow rules. */ +struct mlx4_drop { + struct ibv_qp *qp; /**< QP target. */ + struct ibv_cq *cq; /**< CQ associated with above QP. */ + struct priv *priv; /**< Back pointer to private data. */ + uint32_t refcnt; /**< Reference count. */ }; /** @@ -744,76 +747,73 @@ mlx4_flow_validate(struct rte_eth_dev *dev, } /** - * Destroy a drop queue. + * Get a drop flow rule resources instance. * * @param priv * Pointer to private structure. + * + * @return + * Pointer to drop flow resources on success, NULL otherwise and rte_errno + * is set. */ -static void -mlx4_flow_destroy_drop_queue(struct priv *priv) +static struct mlx4_drop * +mlx4_drop_get(struct priv *priv) { - if (priv->flow_drop_queue) { - struct rte_flow_drop *fdq = priv->flow_drop_queue; + struct mlx4_drop *drop = priv->drop; - priv->flow_drop_queue = NULL; - claim_zero(ibv_destroy_qp(fdq->qp)); - claim_zero(ibv_destroy_cq(fdq->cq)); - rte_free(fdq); + if (drop) { + assert(drop->refcnt); + assert(drop->priv == priv); + ++drop->refcnt; + return drop; } + drop = rte_malloc(__func__, sizeof(*drop), 0); + if (!drop) + goto error; + *drop = (struct mlx4_drop){ + .priv = priv, + .refcnt = 1, + }; + drop->cq = ibv_create_cq(priv->ctx, 1, NULL, NULL, 0); + if (!drop->cq) + goto error; + drop->qp = ibv_create_qp(priv->pd, + &(struct ibv_qp_init_attr){ + .send_cq = drop->cq, + .recv_cq = drop->cq, + .qp_type = IBV_QPT_RAW_PACKET, + }); + if (!drop->qp) + goto error; + priv->drop = drop; + return drop; +error: + if (drop->qp) + claim_zero(ibv_destroy_qp(drop->qp)); + if (drop->cq) + claim_zero(ibv_destroy_cq(drop->cq)); + if (drop) + rte_free(drop); + rte_errno = ENOMEM; + return NULL; } /** - * Create a single drop queue for all drop flows. + * Give back a drop flow rule resources instance. * - * @param priv - * Pointer to private structure. - * - * @return - * 0 on success, negative value otherwise. + * @param drop + * Pointer to drop flow rule resources. */ -static int -mlx4_flow_create_drop_queue(struct priv *priv) +static void +mlx4_drop_put(struct mlx4_drop *drop) { - struct ibv_qp *qp; - struct ibv_cq *cq; - struct rte_flow_drop *fdq; - - fdq = rte_calloc(__func__, 1, sizeof(*fdq), 0); - if (!fdq) { - ERROR("Cannot allocate memory for drop struct"); - goto err; - } - cq = ibv_create_cq(priv->ctx, 1, NULL, NULL, 0); - if (!cq) { - ERROR("Cannot create drop CQ"); - goto err_create_cq; - } - qp = ibv_create_qp(priv->pd, - &(struct ibv_qp_init_attr){ - .send_cq = cq, - .recv_cq = cq, - .cap = { - .max_recv_wr = 1, - .max_recv_sge = 1, - }, - .qp_type = IBV_QPT_RAW_PACKET, - }); - if (!qp) { - ERROR("Cannot create drop QP"); - goto err_create_qp; - } - *fdq = (struct rte_flow_drop){ - .qp = qp, - .cq = cq, - }; - priv->flow_drop_queue = fdq; - return 0; -err_create_qp: - claim_zero(ibv_destroy_cq(cq)); -err_create_cq: - rte_free(fdq); -err: - return -1; + assert(drop->refcnt); + if (--drop->refcnt) + return; + drop->priv->drop = NULL; + claim_zero(ibv_destroy_qp(drop->qp)); + claim_zero(ibv_destroy_cq(drop->cq)); + rte_free(drop); } /** @@ -846,6 +846,8 @@ mlx4_flow_toggle(struct priv *priv, return 0; claim_zero(ibv_destroy_flow(flow->ibv_flow)); flow->ibv_flow = NULL; + if (flow->drop) + mlx4_drop_put(priv->drop); return 0; } if (flow->ibv_flow) @@ -864,14 +866,21 @@ mlx4_flow_toggle(struct priv *priv, qp = rxq->qp; } if (flow->drop) { - assert(priv->flow_drop_queue); - qp = priv->flow_drop_queue->qp; + mlx4_drop_get(priv); + if (!priv->drop) { + err = rte_errno; + msg = "resources for drop flow rule cannot be created"; + goto error; + } + qp = priv->drop->qp; } assert(qp); assert(flow->ibv_attr); flow->ibv_flow = ibv_create_flow(qp, flow->ibv_attr); if (flow->ibv_flow) return 0; + if (flow->drop) + mlx4_drop_put(priv->drop); err = errno; msg = "flow rule rejected by device"; error: @@ -995,7 +1004,7 @@ mlx4_flow_stop(struct priv *priv) flow = LIST_NEXT(flow, next)) { claim_zero(mlx4_flow_toggle(priv, flow, 0, NULL)); } - mlx4_flow_destroy_drop_queue(priv); + assert(!priv->drop); } /** @@ -1013,9 +1022,6 @@ mlx4_flow_start(struct priv *priv) int ret; struct rte_flow *flow; - ret = mlx4_flow_create_drop_queue(priv); - if (ret) - return -1; for (flow = LIST_FIRST(&priv->flows); flow; flow = LIST_NEXT(flow, next)) {