Linux PARISC architecture development
 help / color / mirror / Atom feed
* [PATCH] parisc: Optimize switch_mm
@ 2017-07-25 21:31 John David Anglin
  2017-07-26 18:02 ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: John David Anglin @ 2017-07-25 21:31 UTC (permalink / raw)
  To: Parisc List; +Cc: Helge Deller, James Bottomley

[-- Attachment #1: Type: text/plain, Size: 173 bytes --]

We only need to switch contexts when prev != next, and we don't need to disable interrupts
to do the check.

Signed-off-by: John David Anglin <dave.anglin@bell.net>



[-- Attachment #2: mmu_context.h.d.txt --]
[-- Type: text/plain, Size: 988 bytes --]

diff --git a/arch/parisc/include/asm/mmu_context.h b/arch/parisc/include/asm/mmu_context.h
index a81226257878..b1dc6e3f0dd0 100644
--- a/arch/parisc/include/asm/mmu_context.h
+++ b/arch/parisc/include/asm/mmu_context.h
@@ -49,26 +49,19 @@ static inline void load_context(mm_context_t context)
 	mtctl(__space_to_prot(context), 8);
 }
 
-static inline void switch_mm_irqs_off(struct mm_struct *prev,
+static inline void switch_mm(struct mm_struct *prev,
 		struct mm_struct *next, struct task_struct *tsk)
 {
+	unsigned long flags;
+
 	if (prev != next) {
+		local_irq_save(flags);
 		mtctl(__pa(next->pgd), 25);
 		load_context(next->context);
+		local_irq_restore(flags);
 	}
 }
 
-static inline void switch_mm(struct mm_struct *prev,
-		struct mm_struct *next, struct task_struct *tsk)
-{
-	unsigned long flags;
-
-	local_irq_save(flags);
-	switch_mm_irqs_off(prev, next, tsk);
-	local_irq_restore(flags);
-}
-#define switch_mm_irqs_off switch_mm_irqs_off

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] parisc: Optimize switch_mm
  2017-07-25 21:31 [PATCH] parisc: Optimize switch_mm John David Anglin
@ 2017-07-26 18:02 ` Helge Deller
  2017-07-26 18:49   ` John David Anglin
  0 siblings, 1 reply; 4+ messages in thread
From: Helge Deller @ 2017-07-26 18:02 UTC (permalink / raw)
  To: John David Anglin, linux-parisc, James Bottomley

* John David Anglin <dave.anglin@bell.net>:
> We only need to switch contexts when prev != next, and we don't need to disable interrupts
> to do the check.
> 
> Signed-off-by: John David Anglin <dave.anglin@bell.net>
> 
> 

> diff --git a/arch/parisc/include/asm/mmu_context.h b/arch/parisc/include/asm/mmu_context.h
> index a81226257878..b1dc6e3f0dd0 100644
> --- a/arch/parisc/include/asm/mmu_context.h
> +++ b/arch/parisc/include/asm/mmu_context.h
> @@ -49,26 +49,19 @@ static inline void load_context(mm_context_t context)
>  	mtctl(__space_to_prot(context), 8);
>  }
>  
> -static inline void switch_mm_irqs_off(struct mm_struct *prev,
> +static inline void switch_mm(struct mm_struct *prev,
>  		struct mm_struct *next, struct task_struct *tsk)
>  {
> +	unsigned long flags;
> +
>  	if (prev != next) {
> +		local_irq_save(flags);
>  		mtctl(__pa(next->pgd), 25);
>  		load_context(next->context);
> +		local_irq_restore(flags);
>  	}
>  }
>  
> -static inline void switch_mm(struct mm_struct *prev,
> -		struct mm_struct *next, struct task_struct *tsk)
> -{
> -	unsigned long flags;
> -
> -	local_irq_save(flags);
> -	switch_mm_irqs_off(prev, next, tsk);
> -	local_irq_restore(flags);
> -}
> -#define switch_mm_irqs_off switch_mm_irqs_off
> -
>  #define deactivate_mm(tsk,mm)	do { } while (0)
>  
>  static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)


Instead I'd then suggest the patch below.
The if-clause in switch_mm_irqs_off() will then probably be optimized
away by the compiler.

diff --git a/arch/parisc/include/asm/mmu_context.h b/arch/parisc/include/asm/mmu_context.h
index a812262..e4a6570 100644
--- a/arch/parisc/include/asm/mmu_context.h
+++ b/arch/parisc/include/asm/mmu_context.h
@@ -63,6 +63,9 @@ static inline void switch_mm(struct mm_struct *prev,
 {
 	unsigned long flags;
 
+	if (prev == next)
+		return;
+
 	local_irq_save(flags);
 	switch_mm_irqs_off(prev, next, tsk);
 	local_irq_restore(flags);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] parisc: Optimize switch_mm
  2017-07-26 18:02 ` Helge Deller
@ 2017-07-26 18:49   ` John David Anglin
  2017-07-26 19:13     ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: John David Anglin @ 2017-07-26 18:49 UTC (permalink / raw)
  To: Helge Deller; +Cc: linux-parisc, James Bottomley

On 2017-07-26, at 2:02 PM, Helge Deller wrote:

> Instead I'd then suggest the patch below.
> The if-clause in switch_mm_irqs_off() will then probably be optimized
> away by the compiler.
> 
> diff --git a/arch/parisc/include/asm/mmu_context.h b/arch/parisc/include/asm/mmu_context.h
> index a812262..e4a6570 100644
> --- a/arch/parisc/include/asm/mmu_context.h
> +++ b/arch/parisc/include/asm/mmu_context.h
> @@ -63,6 +63,9 @@ static inline void switch_mm(struct mm_struct *prev,
> {
> 	unsigned long flags;
> 
> +	if (prev == next)
> +		return;
> +
> 	local_irq_save(flags);
> 	switch_mm_irqs_off(prev, next, tsk);
> 	local_irq_restore(flags);

You are correct.  I missed the fact that switch_mm_irqs_off() is used by kernel/sched/core.c.

Maybe we should replace the "switch_mm_irqs_off(prev, next, tsk);" with the mtctl and load_context
lines to ensure that the if-clause is optimized?

Dave
--
John David Anglin	dave.anglin@bell.net




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] parisc: Optimize switch_mm
  2017-07-26 18:49   ` John David Anglin
@ 2017-07-26 19:13     ` Helge Deller
  0 siblings, 0 replies; 4+ messages in thread
From: Helge Deller @ 2017-07-26 19:13 UTC (permalink / raw)
  To: John David Anglin; +Cc: linux-parisc, James Bottomley

On 26.07.2017 20:49, John David Anglin wrote:
> On 2017-07-26, at 2:02 PM, Helge Deller wrote:
> 
>> Instead I'd then suggest the patch below.
>> The if-clause in switch_mm_irqs_off() will then probably be optimized
>> away by the compiler.
>>
>> diff --git a/arch/parisc/include/asm/mmu_context.h b/arch/parisc/include/asm/mmu_context.h
>> index a812262..e4a6570 100644
>> --- a/arch/parisc/include/asm/mmu_context.h
>> +++ b/arch/parisc/include/asm/mmu_context.h
>> @@ -63,6 +63,9 @@ static inline void switch_mm(struct mm_struct *prev,
>> {
>> 	unsigned long flags;
>>
>> +	if (prev == next)
>> +		return;
>> +
>> 	local_irq_save(flags);
>> 	switch_mm_irqs_off(prev, next, tsk);
>> 	local_irq_restore(flags);
> 
> You are correct.  I missed the fact that switch_mm_irqs_off() is used by kernel/sched/core.c.
> 
> Maybe we should replace the "switch_mm_irqs_off(prev, next, tsk);" with the mtctl and load_context
> lines to ensure that the if-clause is optimized?

I think we should look at the generated assembly, and if it's not optimized away replace it with mtctl/load_context.

Helge

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-26 19:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 21:31 [PATCH] parisc: Optimize switch_mm John David Anglin
2017-07-26 18:02 ` Helge Deller
2017-07-26 18:49   ` John David Anglin
2017-07-26 19:13     ` Helge Deller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox