]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: HWS, Add fullness tracking to pool
authorVlad Dogaru <vdogaru@nvidia.com>
Thu, 10 Apr 2025 19:17:36 +0000 (22:17 +0300)
committerJakub Kicinski <kuba@kernel.org>
Tue, 15 Apr 2025 00:29:16 +0000 (17:29 -0700)
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>
Link: https://patch.msgid.link/1744312662-356571-7-git-send-email-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.h

index 270b333faab3b5e51a856ef4f339fc59ba623669..26d85fe3c417d81811380f958b92cdb2953de3ee 100644 (file)
@@ -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);
 
index 9a781a87f097b50750e1972e8c94e325d2242e75..c82760d53e1a09901ae00fa78a7da5f3c2843e14 100644 (file)
@@ -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_ */