net/mlx5e: Optimize modulo in mlx5e_select_queue
authorMaxim Mikityanskiy <maximmi@nvidia.com>
Tue, 25 Jan 2022 10:52:59 +0000 (12:52 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 15 Feb 2022 06:30:51 +0000 (22:30 -0800)
commit3a9e5fff2ab0d6f4af701757d35b9453dc563b78
tree2fd85358826bf473a5369c4410f9750b596bc842
parent3c87aedd48997f9ab3afdeb2084f6b6163a21db8
net/mlx5e: Optimize modulo in mlx5e_select_queue

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>
drivers/net/ethernet/mellanox/mlx5/core/en/selq.c
drivers/net/ethernet/mellanox/mlx5/core/en/selq.h