From: Tariq Toukan <tariqt@nvidia.com>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@google.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
Jiri Pirko <jiri@nvidia.com>
Cc: Cosmin Ratiu <cratiu@nvidia.com>,
Carolina Jubran <cjubran@nvidia.com>,
Gal Pressman <gal@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
Donald Hunter <donald.hunter@gmail.com>,
Jiri Pirko <jiri@resnulli.us>, Jonathan Corbet <corbet@lwn.net>,
Saeed Mahameed <saeedm@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
Tariq Toukan <tariqt@nvidia.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<linux-rdma@vger.kernel.org>
Subject: [PATCH net-next 07/10] net/mlx5: qos: Introduce shared esw qos domains
Date: Thu, 13 Feb 2025 20:01:31 +0200 [thread overview]
Message-ID: <20250213180134.323929-8-tariqt@nvidia.com> (raw)
In-Reply-To: <20250213180134.323929-1-tariqt@nvidia.com>
From: Cosmin Ratiu <cratiu@nvidia.com>
Introduce shared esw qos domains, capable of holding rate groups for
multiple E-Switches of the same NIC. Shared qos domains are reference
counted and can be discovered via devcom. The devcom comp lock is used
in write-mode to prevent init/cleanup races.
When initializing a shared qos domain fails due to devcom errors,
the code falls back to using a private qos domain while logging a
message that cross-esw scheduling cannot be supported.
Shared esw qos domains will be used in a future patch to support
cross-eswitch scheduling.
Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/esw/qos.c | 73 +++++++++++++++++--
1 file changed, 67 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c
index 8b7c843446e1..6a469f214187 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c
@@ -11,10 +11,17 @@
/* Minimum supported BW share value by the HW is 1 Mbit/sec */
#define MLX5_MIN_BW_SHARE 1
-/* Holds rate nodes associated with an E-Switch. */
+/* Holds rate nodes associated with one or more E-Switches.
+ * If cross-esw scheduling is supported, this is shared between all
+ * E-Switches of a NIC.
+ */
struct mlx5_qos_domain {
/* Serializes access to all qos changes in the qos domain. */
struct mutex lock;
+ /* Whether this domain is shared with other E-Switches. */
+ bool shared;
+ /* The reference count is only used for shared qos domains. */
+ refcount_t refcnt;
/* List of all mlx5_esw_sched_nodes. */
struct list_head nodes;
};
@@ -34,7 +41,7 @@ static void esw_assert_qos_lock_held(struct mlx5_eswitch *esw)
lockdep_assert_held(&esw->qos.domain->lock);
}
-static struct mlx5_qos_domain *esw_qos_domain_alloc(void)
+static struct mlx5_qos_domain *esw_qos_domain_alloc(bool shared)
{
struct mlx5_qos_domain *qos_domain;
@@ -44,21 +51,75 @@ static struct mlx5_qos_domain *esw_qos_domain_alloc(void)
mutex_init(&qos_domain->lock);
INIT_LIST_HEAD(&qos_domain->nodes);
+ qos_domain->shared = shared;
+ if (shared)
+ refcount_set(&qos_domain->refcnt, 1);
return qos_domain;
}
-static int esw_qos_domain_init(struct mlx5_eswitch *esw)
+static void esw_qos_devcom_lock(struct mlx5_devcom_comp_dev *devcom, bool shared)
{
- esw->qos.domain = esw_qos_domain_alloc();
+ if (shared)
+ mlx5_devcom_comp_lock(devcom);
+}
+
+static void esw_qos_devcom_unlock(struct mlx5_devcom_comp_dev *devcom, bool shared)
+{
+ if (shared)
+ mlx5_devcom_comp_unlock(devcom);
+}
+
+static int esw_qos_domain_init(struct mlx5_eswitch *esw, bool shared)
+{
+ struct mlx5_devcom_comp_dev *devcom = esw->dev->priv.hca_devcom_comp;
+
+ if (shared && IS_ERR_OR_NULL(devcom)) {
+ esw_info(esw->dev, "Cross-esw QoS cannot be initialized because devcom is unavailable.");
+ shared = false;
+ }
+
+ esw_qos_devcom_lock(devcom, shared);
+ if (shared) {
+ struct mlx5_devcom_comp_dev *pos;
+ struct mlx5_core_dev *peer_dev;
+
+ mlx5_devcom_for_each_peer_entry(devcom, peer_dev, pos) {
+ struct mlx5_eswitch *peer_esw = peer_dev->priv.eswitch;
+
+ if (peer_esw->qos.domain && peer_esw->qos.domain->shared) {
+ esw->qos.domain = peer_esw->qos.domain;
+ refcount_inc(&esw->qos.domain->refcnt);
+ goto unlock;
+ }
+ }
+ }
+
+ /* If no shared domain found, this esw will create one.
+ * Doing it with the devcom comp lock held prevents races with other
+ * eswitches doing concurrent init.
+ */
+ esw->qos.domain = esw_qos_domain_alloc(shared);
+unlock:
+ esw_qos_devcom_unlock(devcom, shared);
return esw->qos.domain ? 0 : -ENOMEM;
}
static void esw_qos_domain_release(struct mlx5_eswitch *esw)
{
- kfree(esw->qos.domain);
+ struct mlx5_devcom_comp_dev *devcom = esw->dev->priv.hca_devcom_comp;
+ struct mlx5_qos_domain *domain = esw->qos.domain;
+ bool shared = domain->shared;
+
+ /* Shared domains are released with the devcom comp lock held to
+ * prevent races with other eswitches doing concurrent init.
+ */
+ esw_qos_devcom_lock(devcom, shared);
+ if (!shared || refcount_dec_and_test(&domain->refcnt))
+ kfree(domain);
esw->qos.domain = NULL;
+ esw_qos_devcom_unlock(devcom, shared);
}
enum sched_node_type {
@@ -829,7 +890,7 @@ int mlx5_esw_qos_init(struct mlx5_eswitch *esw)
if (esw->qos.domain)
return 0; /* Nothing to change. */
- return esw_qos_domain_init(esw);
+ return esw_qos_domain_init(esw, false);
}
void mlx5_esw_qos_cleanup(struct mlx5_eswitch *esw)
--
2.45.0
next prev parent reply other threads:[~2025-02-13 18:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 18:01 [PATCH net-next 00/10] devlink and mlx5: Introduce rate domains Tariq Toukan
2025-02-13 18:01 ` [PATCH net-next 01/10] devlink: Remove unused param of devlink_rate_nodes_check Tariq Toukan
2025-02-18 2:54 ` Kalesh Anakkur Purayil
2025-02-13 18:01 ` [PATCH net-next 02/10] devlink: Store devlink rates in a rate domain Tariq Toukan
2025-02-13 18:01 ` [PATCH net-next 03/10] devlink: Serialize access to rate domains Tariq Toukan
2025-02-14 12:54 ` Jiri Pirko
2025-02-19 2:21 ` Jakub Kicinski
2025-02-25 13:36 ` Jiri Pirko
2025-02-26 1:40 ` Jakub Kicinski
2025-02-26 14:44 ` Jiri Pirko
2025-02-27 2:53 ` Jakub Kicinski
2025-02-27 12:22 ` Jiri Pirko
2025-03-03 22:06 ` Jakub Kicinski
2025-03-04 13:11 ` Jiri Pirko
2025-03-05 0:04 ` Jakub Kicinski
2025-03-05 11:48 ` Jiri Pirko
2025-02-13 18:01 ` [PATCH net-next 04/10] devlink: Introduce shared " Tariq Toukan
2025-02-13 18:01 ` [PATCH net-next 05/10] devlink: Allow specifying parent device for rate commands Tariq Toukan
2025-02-13 18:01 ` [PATCH net-next 06/10] devlink: Allow rate node parents from other devlinks Tariq Toukan
2025-02-13 18:01 ` Tariq Toukan [this message]
2025-02-13 18:01 ` [PATCH net-next 08/10] net/mlx5: qos: Support cross-esw tx scheduling Tariq Toukan
2025-02-13 18:01 ` [PATCH net-next 09/10] net/mlx5: qos: Init shared devlink rate domain Tariq Toukan
2025-02-13 18:01 ` [PATCH net-next 10/10] net/mlx5: Document devlink rates and cross-esw scheduling Tariq Toukan
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=20250213180134.323929-8-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=cjubran@nvidia.com \
--cc=corbet@lwn.net \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=jiri@nvidia.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@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