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>
Cc: Gal Pressman <gal@nvidia.com>,
Leon Romanovsky <leonro@nvidia.com>,
"Saeed Mahameed" <saeedm@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
Tariq Toukan <tariqt@nvidia.com>, <netdev@vger.kernel.org>,
<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Moshe Shemesh <moshe@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
Vlad Dogaru <vdogaru@nvidia.com>,
Yevgeny Kliteynik <kliteyn@nvidia.com>,
Michal Kubiak <michal.kubiak@intel.com>
Subject: [PATCH net-next V2 06/12] net/mlx5: HWS, Add fullness tracking to pool
Date: Thu, 10 Apr 2025 22:17:36 +0300 [thread overview]
Message-ID: <1744312662-356571-7-git-send-email-tariqt@nvidia.com> (raw)
In-Reply-To: <1744312662-356571-1-git-send-email-tariqt@nvidia.com>
From: Vlad Dogaru <vdogaru@nvidia.com>
Future users will need to query whether a pool is empty.
Signed-off-by: Vlad Dogaru <vdogaru@nvidia.com>
Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>
---
.../mellanox/mlx5/core/steering/hws/pool.c | 7 ++++++
.../mellanox/mlx5/core/steering/hws/pool.h | 25 +++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c
index 270b333faab3..26d85fe3c417 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c
@@ -324,6 +324,8 @@ int mlx5hws_pool_chunk_alloc(struct mlx5hws_pool *pool,
mutex_lock(&pool->lock);
ret = pool->p_get_chunk(pool, chunk);
+ if (ret == 0)
+ pool->available_elems -= 1 << chunk->order;
mutex_unlock(&pool->lock);
return ret;
@@ -334,6 +336,7 @@ void mlx5hws_pool_chunk_free(struct mlx5hws_pool *pool,
{
mutex_lock(&pool->lock);
pool->p_put_chunk(pool, chunk);
+ pool->available_elems += 1 << chunk->order;
mutex_unlock(&pool->lock);
}
@@ -360,6 +363,7 @@ mlx5hws_pool_create(struct mlx5hws_context *ctx, struct mlx5hws_pool_attr *pool_
res_db_type = MLX5HWS_POOL_DB_TYPE_BITMAP;
pool->alloc_log_sz = pool_attr->alloc_log_sz;
+ pool->available_elems = 1 << pool_attr->alloc_log_sz;
if (hws_pool_db_init(pool, res_db_type))
goto free_pool;
@@ -377,6 +381,9 @@ void mlx5hws_pool_destroy(struct mlx5hws_pool *pool)
{
mutex_destroy(&pool->lock);
+ if (pool->available_elems != 1 << pool->alloc_log_sz)
+ mlx5hws_err(pool->ctx, "Attempting to destroy non-empty pool\n");
+
if (pool->resource)
hws_pool_resource_free(pool);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.h b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.h
index 9a781a87f097..c82760d53e1a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.h
@@ -71,6 +71,7 @@ struct mlx5hws_pool {
enum mlx5hws_pool_flags flags;
struct mutex lock; /* protect the pool */
size_t alloc_log_sz;
+ size_t available_elems;
enum mlx5hws_table_type tbl_type;
enum mlx5hws_pool_optimize opt_type;
struct mlx5hws_pool_resource *resource;
@@ -103,4 +104,28 @@ static inline u32 mlx5hws_pool_get_base_mirror_id(struct mlx5hws_pool *pool)
{
return pool->mirror_resource->base_id;
}
+
+static inline bool
+mlx5hws_pool_empty(struct mlx5hws_pool *pool)
+{
+ bool ret;
+
+ mutex_lock(&pool->lock);
+ ret = pool->available_elems == 0;
+ mutex_unlock(&pool->lock);
+
+ return ret;
+}
+
+static inline bool
+mlx5hws_pool_full(struct mlx5hws_pool *pool)
+{
+ bool ret;
+
+ mutex_lock(&pool->lock);
+ ret = pool->available_elems == (1 << pool->alloc_log_sz);
+ mutex_unlock(&pool->lock);
+
+ return ret;
+}
#endif /* MLX5HWS_POOL_H_ */
--
2.31.1
next prev parent reply other threads:[~2025-04-10 19:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-10 19:17 [PATCH net-next V2 00/12] net/mlx5: HWS, Refactor action STE handling Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 01/12] net/mlx5: HWS, Fix matcher action template attach Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 02/12] net/mlx5: HWS, Remove unused element array Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 03/12] net/mlx5: HWS, Make pool single resource Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 04/12] net/mlx5: HWS, Refactor pool implementation Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 05/12] net/mlx5: HWS, Cleanup after pool refactoring Tariq Toukan
2025-04-10 19:17 ` Tariq Toukan [this message]
2025-04-10 19:17 ` [PATCH net-next V2 07/12] net/mlx5: HWS, Fix pool size optimization Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 08/12] net/mlx5: HWS, Implement action STE pool Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 09/12] net/mlx5: HWS, Use the new " Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 10/12] net/mlx5: HWS, Cleanup matcher action STE table Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 11/12] net/mlx5: HWS, Free unused action STE tables Tariq Toukan
2025-04-10 19:17 ` [PATCH net-next V2 12/12] net/mlx5: HWS, Export action STE tables to debugfs Tariq Toukan
2025-04-11 11:29 ` [PATCH net-next V2 00/12] net/mlx5: HWS, Refactor action STE handling Michal Kubiak
2025-04-15 0:40 ` patchwork-bot+netdevbpf
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=1744312662-356571-7-git-send-email-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=kliteyn@nvidia.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=leonro@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=michal.kubiak@intel.com \
--cc=moshe@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=vdogaru@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