From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, Tariq Toukan <tariqt@nvidia.com>,
Maxim Mikityanskiy <maximmi@nvidia.com>,
Saeed Mahameed <saeedm@nvidia.com>
Subject: [net-next 14/15] net/mlx5e: Optimize modulo in mlx5e_select_queue
Date: Mon, 14 Feb 2022 22:32:28 -0800 [thread overview]
Message-ID: <20220215063229.737960-15-saeed@kernel.org> (raw)
In-Reply-To: <20220215063229.737960-1-saeed@kernel.org>
From: Maxim Mikityanskiy <maximmi@nvidia.com>
To improve the performance of the modulo operation (%), it's replaced by
a subtracting the divisor in a loop. The modulo is used to fix up an
out-of-bounds value that might be returned by netdev_pick_tx or to
convert the queue number to the channel number when num_tcs > 1. Both
situations are unlikely, because XPS is configured not to pick higher
queues (qid >= num_channels) by default, so under normal circumstances
the flow won't go inside the loop, and it will be faster than %.
num_tcs == 8 adds at most 7 iterations to the loop. PTP adds at most 1
iteration to the loop. HTB would add at most 256 iterations (when
num_channels == 1), so there is an additional boundary check in the HTB
flow, which falls back to % if more than 7 iterations are expected.
Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/en/selq.c | 7 ++++---
.../net/ethernet/mellanox/mlx5/core/en/selq.h | 20 +++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/selq.c b/drivers/net/ethernet/mellanox/mlx5/core/en/selq.c
index b3ed5262d2a1..667bc95a0d44 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/selq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/selq.c
@@ -178,7 +178,8 @@ u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
* So we can return a txq_ix that matches the channel and
* packet UP.
*/
- return txq_ix % selq->num_channels + up * selq->num_channels;
+ return mlx5e_txq_to_ch_ix(txq_ix, selq->num_channels) +
+ up * selq->num_channels;
}
if (unlikely(selq->is_htb)) {
@@ -198,7 +199,7 @@ u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
* Driver to select these queues only at mlx5e_select_ptpsq()
* and mlx5e_select_htb_queue().
*/
- return txq_ix % selq->num_channels;
+ return mlx5e_txq_to_ch_ix_htb(txq_ix, selq->num_channels);
}
/* PTP is enabled */
@@ -214,7 +215,7 @@ u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
* If netdev_pick_tx() picks ptp_channel, switch to a regular queue,
* because driver should select the PTP only at mlx5e_select_ptpsq().
*/
- txq_ix %= selq->num_channels;
+ txq_ix = mlx5e_txq_to_ch_ix(txq_ix, selq->num_channels);
if (selq->num_tcs <= 1)
return txq_ix;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/selq.h b/drivers/net/ethernet/mellanox/mlx5/core/en/selq.h
index b1c73b509f6b..6c070141d8f1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/selq.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/selq.h
@@ -25,6 +25,26 @@ void mlx5e_selq_prepare(struct mlx5e_selq *selq, struct mlx5e_params *params, bo
void mlx5e_selq_apply(struct mlx5e_selq *selq);
void mlx5e_selq_cancel(struct mlx5e_selq *selq);
+static inline u16 mlx5e_txq_to_ch_ix(u16 txq, u16 num_channels)
+{
+ while (unlikely(txq >= num_channels))
+ txq -= num_channels;
+ return txq;
+}
+
+static inline u16 mlx5e_txq_to_ch_ix_htb(u16 txq, u16 num_channels)
+{
+ if (unlikely(txq >= num_channels)) {
+ if (unlikely(txq >= num_channels << 3))
+ txq %= num_channels;
+ else
+ do
+ txq -= num_channels;
+ while (txq >= num_channels);
+ }
+ return txq;
+}
+
u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
struct net_device *sb_dev);
--
2.34.1
next prev parent reply other threads:[~2022-02-15 6:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-15 6:32 [pull request][net-next 00/15] mlx5 updates 2022-02-14 Saeed Mahameed
2022-02-15 6:32 ` [net-next 01/15] net/mlx5e: Remove unused tstamp SQ field Saeed Mahameed
2022-02-15 10:50 ` patchwork-bot+netdevbpf
2022-02-15 6:32 ` [net-next 02/15] net/mlx5e: Read max WQEBBs on the SQ from firmware Saeed Mahameed
2022-02-15 6:32 ` [net-next 03/15] net/mlx5e: Use FW limitation for max MPW WQEBBs Saeed Mahameed
2022-02-15 6:32 ` [net-next 04/15] net/mlx5e: Cleanup of start/stop all queues Saeed Mahameed
2022-02-15 6:32 ` [net-next 05/15] net/mlx5e: Disable TX queues before registering the netdev Saeed Mahameed
2022-02-15 6:32 ` [net-next 06/15] net/mlx5e: Use a barrier after updating txq2sq Saeed Mahameed
2022-02-15 6:32 ` [net-next 07/15] net/mlx5e: Sync txq2sq updates with mlx5e_xmit for HTB queues Saeed Mahameed
2022-02-15 6:32 ` [net-next 08/15] net/mlx5e: Introduce select queue parameters Saeed Mahameed
2022-02-15 6:32 ` [net-next 09/15] net/mlx5e: Move mlx5e_select_queue to en/selq.c Saeed Mahameed
2022-02-15 6:32 ` [net-next 10/15] net/mlx5e: Use select queue parameters to sync with control flow Saeed Mahameed
2022-02-15 6:32 ` [net-next 11/15] net/mlx5e: Move repeating code that gets TC prio into a function Saeed Mahameed
2022-02-15 6:32 ` [net-next 12/15] net/mlx5e: Use READ_ONCE/WRITE_ONCE for DCBX trust state Saeed Mahameed
2022-02-15 6:32 ` [net-next 13/15] net/mlx5e: Optimize mlx5e_select_queue Saeed Mahameed
2022-02-15 6:32 ` Saeed Mahameed [this message]
2022-02-15 6:32 ` [net-next 15/15] net/mlx5e: Optimize the common case condition in mlx5e_select_queue Saeed Mahameed
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=20220215063229.737960-15-saeed@kernel.org \
--to=saeed@kernel.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=maximmi@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.com \
--cc=tariqt@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).