From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6751AA04B1; Tue, 10 Nov 2020 15:10:39 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 27EBC5947; Tue, 10 Nov 2020 15:09:59 +0100 (CET) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by dpdk.org (Postfix) with ESMTP id 561E75947 for ; Tue, 10 Nov 2020 15:09:57 +0100 (CET) Received: by mail-wm1-f68.google.com with SMTP id 19so1591153wmf.1 for ; Tue, 10 Nov 2020 06:09:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=khhITRCsAnotN8ZNWDrIsRDBeDKcSEpVbDbBPR7bEy0=; b=BiueMvY25vgFTKasskHUwEc+LiFnyrvH9Jga6Q8F1XwWJjaet/F0nK2J5UmTvqHoed ++sOrC1AmXqpN9Uah6Z1j9M4SVL9wDzXLeXxNN2Ijojj93HImaKtYvKr/jzFtRMYecJI RXxpJceQyEm4CqX8XL7DeiApVmt0ejdaVG8+I4yuNRvBLEHzQSN9VWupeeVntDcmP2kA qIbePxQO4eejqCYWTbNB/4YpkstvpJ/AS3xgVOFPz7axXdjWfaIbvpldsF5tPXZLI0X0 m15rpwHogdQ8S/qGyktrGACzIU0SwnEBFfo+y4PFWH01eEkp+xiBdfji1WzZsH3pnFYK Z0yQ== 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:mime-version:content-transfer-encoding; bh=khhITRCsAnotN8ZNWDrIsRDBeDKcSEpVbDbBPR7bEy0=; b=YIIXiW6Ig4zB67GHm7QbCznjPnqf8b7ZCHlPXKE5Y7NwoGamAnZ8lXgR+2GQSfRpkh hubwBnXBWLMOf7F10pV9Eff2HGFxPGbAC8vFepmvUOn06HXCqxsls6cQ/lC9OrGZ82vb N4OQ5YrOVzgNiRqehW7sM2Ly1HhJHiWrpmoP+uqhPjcNTxULHa2J7nPygFTEIcH+G8w+ JYFKiFfhoX8qLz18znhr3hP0sQZGF3TAbGkCj1UzSN3NhTRbIluugtyYx8+2ZwgwfNUD jAK28AGeCDNxeXL6WAN+57IS77mZy7R//uQtaONFVivSFQsO6oM7wyJfskeyQxBiK4iP V21g== X-Gm-Message-State: AOAM530mA3K9p2x8wNZEspiqBqMiL7VXp9Ef1A9kycnfmbm6FrAiPXeu epvvdZ3kLCfUwdnAlN/sOaXQfw== X-Google-Smtp-Source: ABdhPJxqr3zNlRpO3bE76tGqtWBJQStpXHl0GdV/Fx7G5DYLjbpYaY5O8GyeoswPsjhqmIaLTH8TFQ== X-Received: by 2002:a1c:35c7:: with SMTP id c190mr5020022wma.146.1605017396048; Tue, 10 Nov 2020 06:09:56 -0800 (PST) Received: from bolet.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id y187sm3112158wmg.33.2020.11.10.06.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:09:55 -0800 (PST) From: Maxime Leroy To: Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko , Olivier Matz Cc: dev@dpdk.org, Nelio Laranjeiro Date: Tue, 10 Nov 2020 15:09:36 +0100 Message-Id: <20201110140938.15046-3-maxime.leroy@6wind.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201110140938.15046-1-maxime.leroy@6wind.com> References: <20201110140938.15046-1-maxime.leroy@6wind.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/4] net/mlx5: fixed used initialization in rx_queue_count 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" Mini (compressed) completion queue entries (CQEs) are returned by the NIC when PCI back pressure is detected, in which case the first CQE64 contains common packet information followed by a number of CQE8 providing the rest, followed by a matching number of empty CQE64 entries to be used by software for decompression. CQE already decompressed in software are not used/holded anymore by the nic. In the rx_queue_count function, if rx poll function has already started to decompress some CQes. We need to count the number of CQEs not yet decompressed, this CQEs are still holded by the hardware. The context of the CQEs decompression is stored in the zip structure. To get the number of cpe not decompressed yet (i.e. still holded by the hadware), the following formula is used: zip->cqe_cnt - zip->ca in rx_queue_count function. The zip->cqe_cnt is the number of CQes compressed and zip->ca is the current index of the cqe to decompress. Thus, we can easily have cqe_cnt < ca. So this method to compute the number of cqes still holded by the hardware is wrong. The proper way to get the number of cqes not yet decrompressed is: - First, we need to know the current packet index to decompress: zip->ca + zip->ai. In the example below, the current packet index is 2. - Then the index of the last packet index to decompress: zip->ci + zip->cqe_cnt. In the example below, the last packet index is 3. - Thus the number of packets used by the hardware (i.e. not decompress yet) is: (zip->ci + zip->cqe_cnt) - (zip->ca + zip->ai). In the example below, the number of packets used by the hardware for the current cqe in decompression is 1. :: zip->cq_ci = 0 /* Current CQE */ zip->ca = 1 /* Current array index for decompression */ zip->ai = 1 /* array index in the mini cqe table in CQE1 below */ zip->cqe_cnt = 3 /* number of CQEs set in the first CQE */ 0 1 2 6 7 +---------+ +---------+ +-------+ +---------+ +-------+ | CQE64 | | CQE64 | | CQE64 | | CQE64 | | CQE64 | |---------| |---------| |-------| |------- | |-------| |cqe_cnt=3| | cqe8[0] | | | . |cqe_cnt=X| |cqe8[0]| | ..... | | cqe8[1] | | | . | | | ... | ... | ..... | | cqe8[2] | | | . | | | | | ..... | | | | | | | | | +---------+ +---------+ +-------+ +-------+++ +-------+ Fixes: 8788fec1f269 ("net/mlx5: implement descriptor status API") Signed-off-by: Maxime Leroy Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_rxtx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c index 4c566486..511003d1 100644 --- a/drivers/net/mlx5/mlx5_rxtx.c +++ b/drivers/net/mlx5/mlx5_rxtx.c @@ -464,13 +464,15 @@ rx_queue_count(struct mlx5_rxq_data *rxq) volatile struct mlx5_cqe *cqe; const unsigned int cqe_n = (1 << rxq->cqe_n); const unsigned int cqe_cnt = cqe_n - 1; - unsigned int cq_ci; + unsigned int cq_ci, cq_end, cq_cur; unsigned int used; /* if we are processing a compressed cqe */ if (zip->ai) { - used = zip->cqe_cnt - zip->ca; cq_ci = zip->cq_ci; + cq_end = cq_ci + zip->cqe_cnt; + cq_cur = zip->ca + zip->ai; + used = cq_end - cq_cur; } else { used = 0; cq_ci = rxq->cq_ci; -- 2.27.0