[32/34] m68k: rework get_mmu_context()

Message ID 20231118155105.25678-33-yury.norov@gmail.com
State New
Headers
Series biops: add atomig find_bit() operations |

Commit Message

Yury Norov Nov. 18, 2023, 3:51 p.m. UTC
  ALSA code opencodes atomic find_and_set_bit_wrap(). Switch it to
dedicated function.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/m68k/include/asm/mmu_context.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
  

Comments

Geert Uytterhoeven Nov. 19, 2023, 7:29 p.m. UTC | #1
Hi Yuri,

Thanks for your patch!

On Sat, Nov 18, 2023 at 4:51 PM Yury Norov <yury.norov@gmail.com> wrote:
> ALSA code opencodes atomic find_and_set_bit_wrap(). Switch it to

ALSA?

> dedicated function.
>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

The rest LGTM, but as it's Coldfire code, I'd like to defer to Greg.

Gr{oetje,eeting}s,

                        Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
  
Greg Ungerer Nov. 21, 2023, 2:39 p.m. UTC | #2
Hi Yury,

On 19/11/23 01:51, Yury Norov wrote:
> ALSA code opencodes atomic find_and_set_bit_wrap(). Switch it to
   ^^^^
m68k?


> dedicated function.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Looks ok to me:

Acked-by: Greg Ungerer <gerg@linux-m68k.org>

Regards
Greg



> ---
>   arch/m68k/include/asm/mmu_context.h | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/m68k/include/asm/mmu_context.h b/arch/m68k/include/asm/mmu_context.h
> index 141bbdfad960..0419ad87a1c1 100644
> --- a/arch/m68k/include/asm/mmu_context.h
> +++ b/arch/m68k/include/asm/mmu_context.h
> @@ -35,12 +35,11 @@ static inline void get_mmu_context(struct mm_struct *mm)
>   		atomic_inc(&nr_free_contexts);
>   		steal_context();
>   	}
> -	ctx = next_mmu_context;
> -	while (test_and_set_bit(ctx, context_map)) {
> -		ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);
> -		if (ctx > LAST_CONTEXT)
> -			ctx = 0;
> -	}
> +
> +	do {
> +		ctx = find_and_set_bit_wrap(context_map, LAST_CONTEXT + 1, next_mmu_context);
> +	} while (ctx > LAST_CONTEXT);
> +
>   	next_mmu_context = (ctx + 1) & LAST_CONTEXT;
>   	mm->context = ctx;
>   	context_mm[ctx] = mm;
  

Patch

diff --git a/arch/m68k/include/asm/mmu_context.h b/arch/m68k/include/asm/mmu_context.h
index 141bbdfad960..0419ad87a1c1 100644
--- a/arch/m68k/include/asm/mmu_context.h
+++ b/arch/m68k/include/asm/mmu_context.h
@@ -35,12 +35,11 @@  static inline void get_mmu_context(struct mm_struct *mm)
 		atomic_inc(&nr_free_contexts);
 		steal_context();
 	}
-	ctx = next_mmu_context;
-	while (test_and_set_bit(ctx, context_map)) {
-		ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);
-		if (ctx > LAST_CONTEXT)
-			ctx = 0;
-	}
+
+	do {
+		ctx = find_and_set_bit_wrap(context_map, LAST_CONTEXT + 1, next_mmu_context);
+	} while (ctx > LAST_CONTEXT);
+
 	next_mmu_context = (ctx + 1) & LAST_CONTEXT;
 	mm->context = ctx;
 	context_mm[ctx] = mm;