[PATCH v4 27/40] ethernet: rocker: optimize ofdpa_port_internal_vlan_id_get()

Yury Norov
2024-06-20T17:58:26Z

Optimize ofdpa_port_internal_vlan_id_get() by using find_and_set_bit(),
instead of polling every bit from bitmap in a for-loop.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
drivers/net/ethernet/rocker/rocker_ofdpa.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c
index 826990459fa4..d8fe018001b9 100644
--- a/drivers/net/ethernet/rocker/rocker_ofdpa.c
+++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c
@@ -6,6 +6,7 @@
* Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com>
*/

+#include <linux/find_atomic.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/spinlock.h>
@@ -2249,14 +2250,11 @@ static __be16 ofdpa_port_internal_vlan_id_get(struct ofdpa_port *ofdpa_port,
found = entry;
hash_add(ofdpa->internal_vlan_tbl, &found->entry, found->ifindex);

- for (i = 0; i < OFDPA_N_INTERNAL_VLANS; i++) {
- if (test_and_set_bit(i, ofdpa->internal_vlan_bitmap))
- continue;
+ i = find_and_set_bit(ofdpa->internal_vlan_bitmap, OFDPA_N_INTERNAL_VLANS);
+ if (i < OFDPA_N_INTERNAL_VLANS)
found->vlan_id = htons(OFDPA_INTERNAL_VLAN_ID_BASE + i);
- goto found;
- }
-
- netdev_err(ofdpa_port->dev, "Out of internal VLAN IDs\n");
+ else
+ netdev_err(ofdpa_port->dev, "Out of internal VLAN IDs\n");

found:
found->ref_count++;
--
2.43.0