All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maor Gottlieb <maorg@mellanox.com>
To: davem@davemloft.net, jgg@mellanox.com, dledford@redhat.com,
	j.vosburgh@gmail.com, vfalico@gmail.com, andy@greyhouse.net,
	kuba@kernel.org, jiri@mellanox.com, dsahern@kernel.org
Cc: leonro@mellanox.com, saeedm@mellanox.com,
	linux-rdma@vger.kernel.org, netdev@vger.kernel.org,
	alexr@mellanox.com, Maor Gottlieb <maorg@mellanox.com>
Subject: [PATCH V3 mlx5-next 12/15] net/mlx5: Change lag mutex lock to spin lock
Date: Tue, 21 Apr 2020 13:28:41 +0300	[thread overview]
Message-ID: <20200421102844.23640-13-maorg@mellanox.com> (raw)
In-Reply-To: <20200421102844.23640-1-maorg@mellanox.com>

The lag lock could be a mutex, the critical section is short
and there is no need that the thread will sleep.
Change the lock that protects the LAG structure from mutex
to spin lock. It is required for next patch that need to
access this structure from context that we can't sleep.
In addition there is no need to hold this lock when query the
congestion counters.

Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/lag.c | 42 +++++++++----------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag.c
index 93052b07c76c..496a3408d771 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag.c
@@ -42,7 +42,7 @@
  * Beware of lock dependencies (preferably, no locks should be acquired
  * under it).
  */
-static DEFINE_MUTEX(lag_mutex);
+static DEFINE_SPINLOCK(lag_lock);
 
 static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, u8 remap_port1,
 			       u8 remap_port2)
@@ -297,9 +297,9 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
 	if (!dev0 || !dev1)
 		return;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	tracker = ldev->tracker;
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 
 	do_bond = tracker.is_bonded && mlx5_lag_check_prereq(ldev);
 
@@ -481,9 +481,9 @@ static int mlx5_lag_netdev_event(struct notifier_block *this,
 		break;
 	}
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev->tracker = tracker;
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 
 	if (changed)
 		mlx5_queue_bond_work(ldev, 0);
@@ -525,7 +525,7 @@ static void mlx5_lag_dev_add_pf(struct mlx5_lag *ldev,
 	if (fn >= MLX5_MAX_PORTS)
 		return;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev->pf[fn].dev    = dev;
 	ldev->pf[fn].netdev = netdev;
 	ldev->tracker.netdev_state[fn].link_up = 0;
@@ -533,7 +533,7 @@ static void mlx5_lag_dev_add_pf(struct mlx5_lag *ldev,
 
 	dev->priv.lag = ldev;
 
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 }
 
 static void mlx5_lag_dev_remove_pf(struct mlx5_lag *ldev,
@@ -548,11 +548,11 @@ static void mlx5_lag_dev_remove_pf(struct mlx5_lag *ldev,
 	if (i == MLX5_MAX_PORTS)
 		return;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	memset(&ldev->pf[i], 0, sizeof(*ldev->pf));
 
 	dev->priv.lag = NULL;
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 }
 
 /* Must be called with intf_mutex held */
@@ -630,10 +630,10 @@ bool mlx5_lag_is_roce(struct mlx5_core_dev *dev)
 	struct mlx5_lag *ldev;
 	bool res;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev = mlx5_lag_dev_get(dev);
 	res  = ldev && __mlx5_lag_is_roce(ldev);
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 
 	return res;
 }
@@ -644,10 +644,10 @@ bool mlx5_lag_is_active(struct mlx5_core_dev *dev)
 	struct mlx5_lag *ldev;
 	bool res;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev = mlx5_lag_dev_get(dev);
 	res  = ldev && __mlx5_lag_is_active(ldev);
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 
 	return res;
 }
@@ -658,10 +658,10 @@ bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev)
 	struct mlx5_lag *ldev;
 	bool res;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev = mlx5_lag_dev_get(dev);
 	res  = ldev && __mlx5_lag_is_sriov(ldev);
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 
 	return res;
 }
@@ -687,7 +687,7 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev)
 	struct net_device *ndev = NULL;
 	struct mlx5_lag *ldev;
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev = mlx5_lag_dev_get(dev);
 
 	if (!(ldev && __mlx5_lag_is_roce(ldev)))
@@ -704,7 +704,7 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev)
 		dev_hold(ndev);
 
 unlock:
-	mutex_unlock(&lag_mutex);
+	spin_unlock(&lag_lock);
 
 	return ndev;
 }
@@ -746,7 +746,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
 
 	memset(values, 0, sizeof(*values) * num_counters);
 
-	mutex_lock(&lag_mutex);
+	spin_lock(&lag_lock);
 	ldev = mlx5_lag_dev_get(dev);
 	if (ldev && __mlx5_lag_is_roce(ldev)) {
 		num_ports = MLX5_MAX_PORTS;
@@ -756,18 +756,18 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
 		num_ports = 1;
 		mdev[MLX5_LAG_P1] = dev;
 	}
+	spin_unlock(&lag_lock);
 
 	for (i = 0; i < num_ports; ++i) {
 		ret = mlx5_cmd_query_cong_counter(mdev[i], false, out, outlen);
 		if (ret)
-			goto unlock;
+			goto free;
 
 		for (j = 0; j < num_counters; ++j)
 			values[j] += be64_to_cpup((__be64 *)(out + offsets[j]));
 	}
 
-unlock:
-	mutex_unlock(&lag_mutex);
+free:
 	kvfree(out);
 	return ret;
 }
-- 
2.17.2


  parent reply	other threads:[~2020-04-21 10:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 10:28 [PATCH V3 mlx5-next 00/15] Add support to get xmit slave Maor Gottlieb
2020-04-21 10:28 ` [PATCH V3 mlx5-next 01/15] net/core: Introduce master_get_xmit_slave Maor Gottlieb
2020-04-21 15:05   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 02/15] bonding: Export skip slave logic to function Maor Gottlieb
2020-04-21 15:50   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 03/15] bonding: Rename slave_arr to usable_slaves Maor Gottlieb
2020-04-21 15:52   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 04/15] bonding/alb: Add helper functions to get the xmit slave Maor Gottlieb
2020-04-21 16:02   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 05/15] bonding: Add helper function to get the xmit slave based on hash Maor Gottlieb
2020-04-21 16:10   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 06/15] bonding: Add helper function to get the xmit slave in rr mode Maor Gottlieb
2020-04-21 16:30   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 07/15] bonding: Add function to get the xmit slave in active-backup mode Maor Gottlieb
2020-04-21 18:02   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 08/15] bonding: Add array of all salves Maor Gottlieb
2020-04-21 19:47   ` Jiri Pirko
2020-04-21 20:33   ` Jay Vosburgh
2020-04-21 10:28 ` [PATCH V3 mlx5-next 09/15] bonding: Implement ndo_get_xmit_slave Maor Gottlieb
2020-04-21 19:49   ` Jiri Pirko
2020-04-21 10:28 ` [PATCH V3 mlx5-next 10/15] RDMA/core: Add LAG functionality Maor Gottlieb
2020-04-21 10:28 ` [PATCH V3 mlx5-next 11/15] RDMA/core: Get xmit slave for LAG Maor Gottlieb
2020-04-21 10:28 ` Maor Gottlieb [this message]
2020-04-21 10:28 ` [PATCH V3 mlx5-next 13/15] net/mlx5: Add support to get lag physical port Maor Gottlieb
2020-04-21 10:28 ` [PATCH V3 mlx5-next 14/15] RDMA/mlx5: Refactor affinity related code Maor Gottlieb
2020-04-21 10:28 ` [PATCH V3 mlx5-next 15/15] RDMA/mlx5: Set lag tx affinity according to slave Maor Gottlieb

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=20200421102844.23640-13-maorg@mellanox.com \
    --to=maorg@mellanox.com \
    --cc=alexr@mellanox.com \
    --cc=andy@greyhouse.net \
    --cc=davem@davemloft.net \
    --cc=dledford@redhat.com \
    --cc=dsahern@kernel.org \
    --cc=j.vosburgh@gmail.com \
    --cc=jgg@mellanox.com \
    --cc=jiri@mellanox.com \
    --cc=kuba@kernel.org \
    --cc=leonro@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=vfalico@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.