diff mbox series

[6/8] riscv: use get_cpu and put_cpu in sys_riscv_flush_icache

Message ID 20190822065612.28634-7-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/8] riscv: fix the flags argument type for riscv_riscv_flush_icache | expand

Commit Message

Christoph Hellwig Aug. 22, 2019, 6:56 a.m. UTC
Use get_cpu/put_cpu instead of opencoding them.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/riscv/mm/cacheflush.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Atish Patra Aug. 22, 2019, 5:49 p.m. UTC | #1
On Thu, 2019-08-22 at 15:56 +0900, Christoph Hellwig wrote:
> Use get_cpu/put_cpu instead of opencoding them.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/riscv/mm/cacheflush.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c
> index dacf72f94d12..9180b2e93058 100644
> --- a/arch/riscv/mm/cacheflush.c
> +++ b/arch/riscv/mm/cacheflush.c
> @@ -19,11 +19,9 @@ void flush_icache_all(void)
>  
>  static void flush_icache_mm(bool local)
>  {
> -	unsigned int cpu;
> +	unsigned int cpu = get_cpu();

I thought it is recommended to put variables with assignment at the
end. But I can't find anything about it in coding guidelines. So it
might be all in my head ;-)

>  	cpumask_t others, hmask;
>  
> -	preempt_disable();
> -
>  	/*
>  	 * Mark the I$ for all harts not concurrently executing as
> needing a
>  	 * flush for this MM.
> @@ -32,7 +30,6 @@ static void flush_icache_mm(bool local)
>  		       cpu_possible_mask, mm_cpumask(current->mm));
>  
>  	/* Flush this hart's I$ now, and mark it as flushed. */
> -	cpu = smp_processor_id();
>  	local_flush_icache_all();
>  
>  	/*
> @@ -55,7 +52,7 @@ static void flush_icache_mm(bool local)
>  		smp_mb();
>  	}
>  
> -	preempt_enable();
> +	put_cpu();
>  }
>  #else
>  #define flush_icache_mm(local)	flush_icache_all()

Otherwise, looks good.
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Christoph Hellwig Aug. 26, 2019, 11:38 a.m. UTC | #2
On Thu, Aug 22, 2019 at 05:49:20PM +0000, Atish Patra wrote:
> On Thu, 2019-08-22 at 15:56 +0900, Christoph Hellwig wrote:
> > Use get_cpu/put_cpu instead of opencoding them.
> > 
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > ---
> >  arch/riscv/mm/cacheflush.c | 7 ++-----
> >  1 file changed, 2 insertions(+), 5 deletions(-)
> > 
> > diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c
> > index dacf72f94d12..9180b2e93058 100644
> > --- a/arch/riscv/mm/cacheflush.c
> > +++ b/arch/riscv/mm/cacheflush.c
> > @@ -19,11 +19,9 @@ void flush_icache_all(void)
> >  
> >  static void flush_icache_mm(bool local)
> >  {
> > -	unsigned int cpu;
> > +	unsigned int cpu = get_cpu();
> 
> I thought it is recommended to put variables with assignment at the
> end. But I can't find anything about it in coding guidelines. So it
> might be all in my head ;-)

I've never heard of that before.  In fact I usually keep them at
the beginning.
Atish Patra Aug. 27, 2019, 6:42 p.m. UTC | #3
On Mon, 2019-08-26 at 13:38 +0200, hch@lst.de wrote:
> On Thu, Aug 22, 2019 at 05:49:20PM +0000, Atish Patra wrote:
> > On Thu, 2019-08-22 at 15:56 +0900, Christoph Hellwig wrote:
> > > Use get_cpu/put_cpu instead of opencoding them.
> > > 
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > > ---
> > >  arch/riscv/mm/cacheflush.c | 7 ++-----
> > >  1 file changed, 2 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/arch/riscv/mm/cacheflush.c
> > > b/arch/riscv/mm/cacheflush.c
> > > index dacf72f94d12..9180b2e93058 100644
> > > --- a/arch/riscv/mm/cacheflush.c
> > > +++ b/arch/riscv/mm/cacheflush.c
> > > @@ -19,11 +19,9 @@ void flush_icache_all(void)
> > >  
> > >  static void flush_icache_mm(bool local)
> > >  {
> > > -	unsigned int cpu;
> > > +	unsigned int cpu = get_cpu();
> > 
> > I thought it is recommended to put variables with assignment at the
> > end. But I can't find anything about it in coding guidelines. So it
> > might be all in my head ;-)
> 
> I've never heard of that before.  In fact I usually keep them at
> the beginning.

Ok. I will keep that in mind :)
diff mbox series

Patch

diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c
index dacf72f94d12..9180b2e93058 100644
--- a/arch/riscv/mm/cacheflush.c
+++ b/arch/riscv/mm/cacheflush.c
@@ -19,11 +19,9 @@  void flush_icache_all(void)
 
 static void flush_icache_mm(bool local)
 {
-	unsigned int cpu;
+	unsigned int cpu = get_cpu();
 	cpumask_t others, hmask;
 
-	preempt_disable();
-
 	/*
 	 * Mark the I$ for all harts not concurrently executing as needing a
 	 * flush for this MM.
@@ -32,7 +30,6 @@  static void flush_icache_mm(bool local)
 		       cpu_possible_mask, mm_cpumask(current->mm));
 
 	/* Flush this hart's I$ now, and mark it as flushed. */
-	cpu = smp_processor_id();
 	local_flush_icache_all();
 
 	/*
@@ -55,7 +52,7 @@  static void flush_icache_mm(bool local)
 		smp_mb();
 	}
 
-	preempt_enable();
+	put_cpu();
 }
 #else
 #define flush_icache_mm(local)	flush_icache_all()