DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Leroy <maxime.leroy@6wind.com>
To: Matan Azrad <matan@nvidia.com>,
	Shahaf Shuler <shahafs@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Olivier Matz <olivier.matz@6wind.com>
Cc: dev@dpdk.org, Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Subject: [dpdk-dev] [PATCH 2/4] net/mlx5: fixed used initialization in rx_queue_count
Date: Tue, 10 Nov 2020 15:09:36 +0100	[thread overview]
Message-ID: <20201110140938.15046-3-maxime.leroy@6wind.com> (raw)
In-Reply-To: <20201110140938.15046-1-maxime.leroy@6wind.com>

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 <maxime.leroy@6wind.com>
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
 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


  parent reply	other threads:[~2020-11-10 14:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10 14:09 [dpdk-dev] [PATCH 0/4] net/mlx5: fixes for rx queue count calculation Maxime Leroy
2020-11-10 14:09 ` [dpdk-dev] [PATCH 1/4] Revert "net/mlx5: fix Rx queue count calculation" Maxime Leroy
2020-11-11 19:51   ` Slava Ovsiienko
2020-11-12 15:43     ` Maxime Leroy
2020-11-10 14:09 ` Maxime Leroy [this message]
2020-11-10 14:09 ` [dpdk-dev] [PATCH 3/4] net/mlx5: fix Rx descriptor status returned value Maxime Leroy
2020-11-10 14:09 ` [dpdk-dev] [PATCH 4/4] mlx5: re-add support of rx_queue_count for mlx5_rx_burst_mprq Maxime Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201110140938.15046-3-maxime.leroy@6wind.com \
    --to=maxime.leroy@6wind.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=nelio.laranjeiro@6wind.com \
    --cc=olivier.matz@6wind.com \
    --cc=shahafs@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).