Re: [guv v2 20/31] powerpc: Replace __get_cpu_var uses

2013-08-27 Thread Christoph Lameter
On Tue, 27 Aug 2013, Geert Uytterhoeven wrote:

> On Mon, Aug 26, 2013 at 10:44 PM, Christoph Lameter  wrote:
> > __get_cpu_var() is used for multiple purposes in the kernel source. One of 
> > them is
> > address calculation via the form &__get_cpu_var(x). This calculates the 
> > address for
> > the instance of the percpu variable of the current processor based on an 
> > offset.
> >
> > Others usage cases are for storing and retrieving data from the current 
> > processors percpu area.
>
> use cases
>
> > __get_cpu_var() always only does a address determination. However, store 
> > and retrieve operations
>
> an address
>
> > This patch converts __get_cpu_var into either and explicit address 
> > calculation using this_cpu_ptr()
>
> an explicit
>
> > 4. Retrieve the content of a percpu struct
> >
> > DEFINE_PER_CPU(struct mystruct, y);
> > struct mystruct x = __get_cpu_var(y);
> >
> >Converts to
> >
> > memcpy(this_cpu_ptr(), x, sizeof(x));
>
> Let's hope the actual code copies in the other direction ;-)

Ok fixed that as well.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [guv v2 20/31] powerpc: Replace __get_cpu_var uses

2013-08-27 Thread Geert Uytterhoeven
On Mon, Aug 26, 2013 at 10:44 PM, Christoph Lameter  wrote:
> __get_cpu_var() is used for multiple purposes in the kernel source. One of 
> them is
> address calculation via the form &__get_cpu_var(x). This calculates the 
> address for
> the instance of the percpu variable of the current processor based on an 
> offset.
>
> Others usage cases are for storing and retrieving data from the current 
> processors percpu area.

use cases

> __get_cpu_var() always only does a address determination. However, store and 
> retrieve operations

an address

> This patch converts __get_cpu_var into either and explicit address 
> calculation using this_cpu_ptr()

an explicit

> 4. Retrieve the content of a percpu struct
>
> DEFINE_PER_CPU(struct mystruct, y);
> struct mystruct x = __get_cpu_var(y);
>
>Converts to
>
> memcpy(this_cpu_ptr(), x, sizeof(x));

Let's hope the actual code copies in the other direction ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [guv v2 20/31] powerpc: Replace __get_cpu_var uses

2013-08-27 Thread Geert Uytterhoeven
On Mon, Aug 26, 2013 at 10:44 PM, Christoph Lameter c...@linux.com wrote:
 __get_cpu_var() is used for multiple purposes in the kernel source. One of 
 them is
 address calculation via the form __get_cpu_var(x). This calculates the 
 address for
 the instance of the percpu variable of the current processor based on an 
 offset.

 Others usage cases are for storing and retrieving data from the current 
 processors percpu area.

use cases

 __get_cpu_var() always only does a address determination. However, store and 
 retrieve operations

an address

 This patch converts __get_cpu_var into either and explicit address 
 calculation using this_cpu_ptr()

an explicit

 4. Retrieve the content of a percpu struct

 DEFINE_PER_CPU(struct mystruct, y);
 struct mystruct x = __get_cpu_var(y);

Converts to

 memcpy(this_cpu_ptr(y), x, sizeof(x));

Let's hope the actual code copies in the other direction ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@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
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [guv v2 20/31] powerpc: Replace __get_cpu_var uses

2013-08-27 Thread Christoph Lameter
On Tue, 27 Aug 2013, Geert Uytterhoeven wrote:

 On Mon, Aug 26, 2013 at 10:44 PM, Christoph Lameter c...@linux.com wrote:
  __get_cpu_var() is used for multiple purposes in the kernel source. One of 
  them is
  address calculation via the form __get_cpu_var(x). This calculates the 
  address for
  the instance of the percpu variable of the current processor based on an 
  offset.
 
  Others usage cases are for storing and retrieving data from the current 
  processors percpu area.

 use cases

  __get_cpu_var() always only does a address determination. However, store 
  and retrieve operations

 an address

  This patch converts __get_cpu_var into either and explicit address 
  calculation using this_cpu_ptr()

 an explicit

  4. Retrieve the content of a percpu struct
 
  DEFINE_PER_CPU(struct mystruct, y);
  struct mystruct x = __get_cpu_var(y);
 
 Converts to
 
  memcpy(this_cpu_ptr(y), x, sizeof(x));

 Let's hope the actual code copies in the other direction ;-)

Ok fixed that as well.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[guv v2 20/31] powerpc: Replace __get_cpu_var uses

2013-08-26 Thread Christoph Lameter
__get_cpu_var() is used for multiple purposes in the kernel source. One of them 
is
address calculation via the form &__get_cpu_var(x). This calculates the address 
for
the instance of the percpu variable of the current processor based on an offset.

Others usage cases are for storing and retrieving data from the current 
processors percpu area.
__get_cpu_var() can be used as an lvalue when writing data or on the right side 
of an assignment.

__get_cpu_var() is defined as :


#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))



__get_cpu_var() always only does a address determination. However, store and 
retrieve operations
could use a segment prefix (or global register on other platforms) to avoid the 
address calculation.

this_cpu_write() and this_cpu_read() can directly take an offset into a percpu 
area and use
optimized assembly code to read and write per cpu variables.


This patch converts __get_cpu_var into either and explicit address calculation 
using this_cpu_ptr()
or into a use of this_cpu operations that use the offset. Thereby address 
calcualtions are avoided
and less registers are used when code is generated.

At the end of the patchset all uses of __get_cpu_var have been removed so the 
macro is removed too.

The patchset includes passes over all arches as well. Once these operations are 
used throughout then
specialized macros can be defined in non -x86 arches as well in order to 
optimize per cpu access by
f.e. using a global register that may be set to the per cpu base.




Transformations done to __get_cpu_var()


1. Determine the address of the percpu instance of the current processor.

DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);

Converts to

int *x = this_cpu_ptr();


2. Same as #1 but this time an array structure is involved.

DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);

Converts to

int *x = this_cpu_ptr(y);


3. Retrieve the content of the current processors instance of a per cpu 
variable.

DEFINE_PER_CPU(int, u);
int x = __get_cpu_var(y)

   Converts to

int x = __this_cpu_read(y);


4. Retrieve the content of a percpu struct

DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);

   Converts to

memcpy(this_cpu_ptr(), x, sizeof(x));


5. Assignment to a per cpu variable

DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;

   Converts to

this_cpu_write(y, x);


6. Increment/Decrement etc of a per cpu variable

DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++

   Converts to

this_cpu_inc(y)



Signed-off-by: Christoph Lameter 

Index: linux/arch/powerpc/include/asm/cputime.h
===
--- linux.orig/arch/powerpc/include/asm/cputime.h   2013-08-22 
14:56:47.939059652 -0500
+++ linux/arch/powerpc/include/asm/cputime.h2013-08-22 14:56:47.935059693 
-0500
@@ -56,10 +56,10 @@ static inline unsigned long cputime_to_j
 static inline cputime_t cputime_to_scaled(const cputime_t ct)
 {
if (cpu_has_feature(CPU_FTR_SPURR) &&
-   __get_cpu_var(cputime_last_delta))
+   __this_cpu_read(cputime_last_delta))
return (__force u64) ct *
-   __get_cpu_var(cputime_scaled_last_delta) /
-   __get_cpu_var(cputime_last_delta);
+   __this_cpu_read(cputime_scaled_last_delta) /
+   __this_cpu_read(cputime_last_delta);
return ct;
 }
 
Index: linux/arch/powerpc/include/asm/hardirq.h
===
--- linux.orig/arch/powerpc/include/asm/hardirq.h   2013-08-22 
14:56:47.939059652 -0500
+++ linux/arch/powerpc/include/asm/hardirq.h2013-08-22 14:56:47.935059693 
-0500
@@ -19,7 +19,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpust
 
 #define __ARCH_IRQ_STAT
 
-#define local_softirq_pending()
__get_cpu_var(irq_stat).__softirq_pending
+#define local_softirq_pending()
__this_cpu_read(irq_stat.__softirq_pending)
 
 static inline void ack_bad_irq(unsigned int irq)
 {
Index: linux/arch/powerpc/include/asm/tlbflush.h
===
--- linux.orig/arch/powerpc/include/asm/tlbflush.h  2013-08-22 
14:56:47.939059652 -0500
+++ linux/arch/powerpc/include/asm/tlbflush.h   2013-08-22 14:56:47.935059693 
-0500
@@ -107,14 +107,14 @@ extern void __flush_tlb_pending(struct p
 
 static inline void arch_enter_lazy_mmu_mode(void)
 {
-   struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);
+   struct ppc64_tlb_batch *batch = this_cpu_ptr(_tlb_batch);
 
batch->active = 1;
 }
 
 static inline void arch_leave_lazy_mmu_mode(void)
 {
-   struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);
+   struct ppc64_tlb_batch *batch = this_cpu_ptr(_tlb_batch);
 
if (batch->index)

[guv v2 20/31] powerpc: Replace __get_cpu_var uses

2013-08-26 Thread Christoph Lameter
__get_cpu_var() is used for multiple purposes in the kernel source. One of them 
is
address calculation via the form __get_cpu_var(x). This calculates the address 
for
the instance of the percpu variable of the current processor based on an offset.

Others usage cases are for storing and retrieving data from the current 
processors percpu area.
__get_cpu_var() can be used as an lvalue when writing data or on the right side 
of an assignment.

__get_cpu_var() is defined as :


#define __get_cpu_var(var) (*this_cpu_ptr((var)))



__get_cpu_var() always only does a address determination. However, store and 
retrieve operations
could use a segment prefix (or global register on other platforms) to avoid the 
address calculation.

this_cpu_write() and this_cpu_read() can directly take an offset into a percpu 
area and use
optimized assembly code to read and write per cpu variables.


This patch converts __get_cpu_var into either and explicit address calculation 
using this_cpu_ptr()
or into a use of this_cpu operations that use the offset. Thereby address 
calcualtions are avoided
and less registers are used when code is generated.

At the end of the patchset all uses of __get_cpu_var have been removed so the 
macro is removed too.

The patchset includes passes over all arches as well. Once these operations are 
used throughout then
specialized macros can be defined in non -x86 arches as well in order to 
optimize per cpu access by
f.e. using a global register that may be set to the per cpu base.




Transformations done to __get_cpu_var()


1. Determine the address of the percpu instance of the current processor.

DEFINE_PER_CPU(int, y);
int *x = __get_cpu_var(y);

Converts to

int *x = this_cpu_ptr(y);


2. Same as #1 but this time an array structure is involved.

DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);

Converts to

int *x = this_cpu_ptr(y);


3. Retrieve the content of the current processors instance of a per cpu 
variable.

DEFINE_PER_CPU(int, u);
int x = __get_cpu_var(y)

   Converts to

int x = __this_cpu_read(y);


4. Retrieve the content of a percpu struct

DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);

   Converts to

memcpy(this_cpu_ptr(y), x, sizeof(x));


5. Assignment to a per cpu variable

DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;

   Converts to

this_cpu_write(y, x);


6. Increment/Decrement etc of a per cpu variable

DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++

   Converts to

this_cpu_inc(y)



Signed-off-by: Christoph Lameter c...@linux.com

Index: linux/arch/powerpc/include/asm/cputime.h
===
--- linux.orig/arch/powerpc/include/asm/cputime.h   2013-08-22 
14:56:47.939059652 -0500
+++ linux/arch/powerpc/include/asm/cputime.h2013-08-22 14:56:47.935059693 
-0500
@@ -56,10 +56,10 @@ static inline unsigned long cputime_to_j
 static inline cputime_t cputime_to_scaled(const cputime_t ct)
 {
if (cpu_has_feature(CPU_FTR_SPURR) 
-   __get_cpu_var(cputime_last_delta))
+   __this_cpu_read(cputime_last_delta))
return (__force u64) ct *
-   __get_cpu_var(cputime_scaled_last_delta) /
-   __get_cpu_var(cputime_last_delta);
+   __this_cpu_read(cputime_scaled_last_delta) /
+   __this_cpu_read(cputime_last_delta);
return ct;
 }
 
Index: linux/arch/powerpc/include/asm/hardirq.h
===
--- linux.orig/arch/powerpc/include/asm/hardirq.h   2013-08-22 
14:56:47.939059652 -0500
+++ linux/arch/powerpc/include/asm/hardirq.h2013-08-22 14:56:47.935059693 
-0500
@@ -19,7 +19,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpust
 
 #define __ARCH_IRQ_STAT
 
-#define local_softirq_pending()
__get_cpu_var(irq_stat).__softirq_pending
+#define local_softirq_pending()
__this_cpu_read(irq_stat.__softirq_pending)
 
 static inline void ack_bad_irq(unsigned int irq)
 {
Index: linux/arch/powerpc/include/asm/tlbflush.h
===
--- linux.orig/arch/powerpc/include/asm/tlbflush.h  2013-08-22 
14:56:47.939059652 -0500
+++ linux/arch/powerpc/include/asm/tlbflush.h   2013-08-22 14:56:47.935059693 
-0500
@@ -107,14 +107,14 @@ extern void __flush_tlb_pending(struct p
 
 static inline void arch_enter_lazy_mmu_mode(void)
 {
-   struct ppc64_tlb_batch *batch = __get_cpu_var(ppc64_tlb_batch);
+   struct ppc64_tlb_batch *batch = this_cpu_ptr(ppc64_tlb_batch);
 
batch-active = 1;
 }
 
 static inline void arch_leave_lazy_mmu_mode(void)
 {
-   struct ppc64_tlb_batch *batch = __get_cpu_var(ppc64_tlb_batch);
+   struct ppc64_tlb_batch *batch = this_cpu_ptr(ppc64_tlb_batch);
 
if (batch-index)