From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id DFC4F8F9D for ; Mon, 23 Nov 2015 15:45:25 +0100 (CET) Received: by wmuu63 with SMTP id u63so57117047wmu.0 for ; Mon, 23 Nov 2015 06:45:25 -0800 (PST) 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=OG/8VeQtYkl8qQQ3tFxWSncr1VIdtnAVvQuPCKORKVw=; b=ZEa9Tuud1RPFJUs+WvYD8+wViNimQB9YIAZ66W1W/KdqSFlCXDvKpF48JQIAf/HMv1 D2lA2o6i+XGDzlAAbDuMcQit1bBXcTi+IenzdZlLs7Jt6SrLY6Fc6zKhSCG7Bo+7bzIZ hhLw+ZcremCJbg8s+pL3JViqClh7Fh8NqraevS/OALUvIk3Uo8tMODZUZrV/SuXnHLMb m49S1oCyQJy/2B1p7bRQQQOjeoUWQsSAoOa5VMQ07UExbX/mMyvvqdlwaVgCFAF12sB6 3tAL0vO9gCF0H7hSz+SCcR1WpuJpfvYvMSijRvdq1X6r0yA/wAEShh3plTo+PKXMEmDU anCw== 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=OG/8VeQtYkl8qQQ3tFxWSncr1VIdtnAVvQuPCKORKVw=; b=JonXVHkX310m7VSn9F6ycV49T0XMm73wPdAlelx9APy6R62NfUJT+WbBiDUgd+VpKw hACIVeDJdU0jbKaqFjB6iNCEarPEjP3AE2O2eKY7lSyQ9GFXiLObRGTKBhVOpjB41AwW 82iT3S1jcJ4YvgpzRrEPYg1ZPOH8npeT8zHCcEAVSCVArRKQlxwpZCavFK2Sn8d2qoj0 37w5Pef3JwX4c/v+X9v6G4VlSqyozXR5P5KJu9rHuX2I1Yw+yZHgzcmJBfKLFyN1JMQS PgPO7E2YEaXJB8ZjPe8TUcSGSP64W5Rr7ooGEJL5F3fE/swf8a/h6KSRdaIFOMgF0zYu DqqA== X-Gm-Message-State: ALoCoQm5wJcAGbaIRRf7ENtYzlLwQTAlIKtm08Z0YpUD2b7IhyfwDiG+IclelhJ0q6OT17EQ4oTg X-Received: by 10.28.47.212 with SMTP id v203mr18535189wmv.37.1448289925760; Mon, 23 Nov 2015 06:45:25 -0800 (PST) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id 186sm13586675wmv.9.2015.11.23.06.45.24 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Nov 2015 06:45:25 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Mon, 23 Nov 2015 15:44:39 +0100 Message-Id: <1448289889-9590-5-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1448289889-9590-1-git-send-email-adrien.mazarguil@6wind.com> References: <1448289889-9590-1-git-send-email-adrien.mazarguil@6wind.com> Subject: [dpdk-dev] [PATCH 04/14] mlx4: fix TX packet loss after initialization 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: Mon, 23 Nov 2015 14:45:26 -0000 From: Olga Shern Pre-registering mbuf memory pools when creating TX queues avoids costly registrations later in the data path. Fixes: 7fae69eeff13 ("mlx4: new poll mode driver") Signed-off-by: Olga Shern Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 75543bb..4bd0ecd 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -229,7 +229,7 @@ typedef uint8_t linear_t[16384]; struct txq { struct priv *priv; /* Back pointer to private data. */ struct { - struct rte_mempool *mp; /* Cached Memory Pool. */ + const struct rte_mempool *mp; /* Cached Memory Pool. */ struct ibv_mr *mr; /* Memory Region (for mp). */ uint32_t lkey; /* mr->lkey */ } mp2mr[MLX4_PMD_TX_MP_CACHE]; /* MP to MR translation table. */ @@ -1016,7 +1016,7 @@ txq_mb2mp(struct rte_mbuf *buf) * mr->lkey on success, (uint32_t)-1 on failure. */ static uint32_t -txq_mp2mr(struct txq *txq, struct rte_mempool *mp) +txq_mp2mr(struct txq *txq, const struct rte_mempool *mp) { unsigned int i; struct ibv_mr *mr; @@ -1033,7 +1033,8 @@ txq_mp2mr(struct txq *txq, struct rte_mempool *mp) } } /* Add a new entry, register MR first. */ - DEBUG("%p: discovered new memory pool %p", (void *)txq, (void *)mp); + DEBUG("%p: discovered new memory pool \"%s\" (%p)", + (void *)txq, mp->name, (const void *)mp); mr = ibv_reg_mr(txq->priv->pd, (void *)mp->elt_va_start, (mp->elt_va_end - mp->elt_va_start), @@ -1056,11 +1057,87 @@ txq_mp2mr(struct txq *txq, struct rte_mempool *mp) txq->mp2mr[i].mp = mp; txq->mp2mr[i].mr = mr; txq->mp2mr[i].lkey = mr->lkey; - DEBUG("%p: new MR lkey for MP %p: 0x%08" PRIu32, - (void *)txq, (void *)mp, txq->mp2mr[i].lkey); + DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32, + (void *)txq, mp->name, (const void *)mp, txq->mp2mr[i].lkey); return txq->mp2mr[i].lkey; } +struct txq_mp2mr_mbuf_check_data { + const struct rte_mempool *mp; + int ret; +}; + +/** + * Callback function for rte_mempool_obj_iter() to check whether a given + * mempool object looks like a mbuf. + * + * @param[in, out] arg + * Context data (struct txq_mp2mr_mbuf_check_data). Contains mempool pointer + * and return value. + * @param[in] start + * Object start address. + * @param[in] end + * Object end address. + * @param index + * Unused. + * + * @return + * Nonzero value when object is not a mbuf. + */ +static void +txq_mp2mr_mbuf_check(void *arg, void *start, void *end, + uint32_t index __rte_unused) +{ + struct txq_mp2mr_mbuf_check_data *data = arg; + struct rte_mbuf *buf = + (void *)((uintptr_t)start + data->mp->header_size); + + (void)index; + /* Check whether mbuf structure fits element size and whether mempool + * pointer is valid. */ + if (((uintptr_t)end >= (uintptr_t)(buf + 1)) && + (buf->pool == data->mp)) + data->ret = 0; + else + data->ret = -1; +} + +/** + * Iterator function for rte_mempool_walk() to register existing mempools and + * fill the MP to MR cache of a TX queue. + * + * @param[in] mp + * Memory Pool to register. + * @param *arg + * Pointer to TX queue structure. + */ +static void +txq_mp2mr_iter(const struct rte_mempool *mp, void *arg) +{ + struct txq *txq = arg; + struct txq_mp2mr_mbuf_check_data data = { + .mp = mp, + .ret = -1, + }; + + /* Discard empty mempools. */ + if (mp->size == 0) + return; + /* Register mempool only if the first element looks like a mbuf. */ + rte_mempool_obj_iter((void *)mp->elt_va_start, + 1, + mp->header_size + mp->elt_size + mp->trailer_size, + 1, + mp->elt_pa, + mp->pg_num, + mp->pg_shift, + txq_mp2mr_mbuf_check, + &data); + if (data.ret) + return; + txq_mp2mr(txq, mp); +} + #if MLX4_PMD_SGE_WR_N > 1 /** @@ -1571,6 +1648,8 @@ txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc, txq_cleanup(txq); *txq = tmpl; DEBUG("%p: txq updated with %p", (void *)txq, (void *)&tmpl); + /* Pre-register known mempools. */ + rte_mempool_walk(txq_mp2mr_iter, txq); assert(ret == 0); return 0; error: -- 2.1.0