diff mbox series

[09/34] dmaengine: idxd: optimize perfmon_assign_event()

Message ID 20231118155105.25678-10-yury.norov@gmail.com (mailing list archive)
State Handled Elsewhere
Headers show
Series biops: add atomig find_bit() operations | expand

Commit Message

Yury Norov Nov. 18, 2023, 3:50 p.m. UTC
The function searches used_mask for a set bit in a for-loop bit by bit.
We can do it faster by using atomic find_and_set_bit().

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/dma/idxd/perfmon.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Dave Jiang Nov. 20, 2023, 3:34 p.m. UTC | #1
On 11/18/23 08:50, Yury Norov wrote:
> The function searches used_mask for a set bit in a for-loop bit by bit.
> We can do it faster by using atomic find_and_set_bit().
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/dma/idxd/perfmon.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c
> index fdda6d604262..4dd9c0d979c3 100644
> --- a/drivers/dma/idxd/perfmon.c
> +++ b/drivers/dma/idxd/perfmon.c
> @@ -134,13 +134,9 @@ static void perfmon_assign_hw_event(struct idxd_pmu *idxd_pmu,
>  static int perfmon_assign_event(struct idxd_pmu *idxd_pmu,
>  				struct perf_event *event)
>  {
> -	int i;
> -
> -	for (i = 0; i < IDXD_PMU_EVENT_MAX; i++)
> -		if (!test_and_set_bit(i, idxd_pmu->used_mask))
> -			return i;
> +	int i = find_and_set_bit(idxd_pmu->used_mask, IDXD_PMU_EVENT_MAX);
>  
> -	return -EINVAL;
> +	return i < IDXD_PMU_EVENT_MAX ? i : -EINVAL;
>  }
>  
>  /*
Vinod Koul Nov. 24, 2023, 12:15 p.m. UTC | #2
On 18-11-23, 07:50, Yury Norov wrote:
> The function searches used_mask for a set bit in a for-loop bit by bit.
> We can do it faster by using atomic find_and_set_bit().

Acked-by: Vinod Koul <vkoul@kernel.org>
diff mbox series

Patch

diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c
index fdda6d604262..4dd9c0d979c3 100644
--- a/drivers/dma/idxd/perfmon.c
+++ b/drivers/dma/idxd/perfmon.c
@@ -134,13 +134,9 @@  static void perfmon_assign_hw_event(struct idxd_pmu *idxd_pmu,
 static int perfmon_assign_event(struct idxd_pmu *idxd_pmu,
 				struct perf_event *event)
 {
-	int i;
-
-	for (i = 0; i < IDXD_PMU_EVENT_MAX; i++)
-		if (!test_and_set_bit(i, idxd_pmu->used_mask))
-			return i;
+	int i = find_and_set_bit(idxd_pmu->used_mask, IDXD_PMU_EVENT_MAX);
 
-	return -EINVAL;
+	return i < IDXD_PMU_EVENT_MAX ? i : -EINVAL;
 }
 
 /*