From f4a08731978050e1eebb8936db7d41c41fdd5526 Mon Sep 17 00:00:00 2001 From: Michael Baum Date: Tue, 21 Jul 2020 12:03:38 +0000 Subject: [PATCH] net/mlx5: optimize critical section in device free When PMD releases shared IB device context, It locks the mlx5_ibv_list_mutex lock throughout the function so that it does not happen while removing a device from the list, another process will try to insert another device into it. On the other hand, having removed the device from the list even if it has not yet released all of its resources, it should not care about other processes and can release the lock. However, the PMD does not release the lock even though it can, and performs a number of operations, some of which include sleep and may be long. To improve this, shorten the lock time to the minimum necessary. Signed-off-by: Michael Baum Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 2560ae1f5f..81476e2d96 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -939,6 +939,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) mlx5_mr_release_cache(&sh->share_cache); /* Remove context from the global device list. */ LIST_REMOVE(sh, next); + pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex); /* * Ensure there is no async event handler installed. * Only primary process handles async device events. @@ -968,6 +969,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) mlx5_flow_id_pool_release(sh->flow_id_pool); pthread_mutex_destroy(&sh->txpp.mutex); mlx5_free(sh); + return; exit: pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex); } -- 2.20.1