Re: [RFC Patch v1 32/55] ARC: [optim] Cache "current" in Register r25

2012-11-15 Thread Vineet Gupta
On Monday 12 November 2012 07:20 PM, Arnd Bergmann wrote:
> On Monday 12 November 2012, vineet.gup...@synopsys.com wrote:
>>  endmenu # "Platform Board Configuration"
>>  
>> +config ARC_CURR_IN_REG
>> +   bool "Dedicate Register r25 for current_task pointer"
>> +   default y
>> +   help
>> + This reserved Register R25 to point to Current Task in
>> + kernel mode. This saves memory access for each such access
>> +
> This looks like a useful feature if you have 32 GPRs, but why make it
> optional? Are there cases where you would disable it?

Since it touched the low level guts of port, it made sense to start with
a config option in initial implementation. But I've kept it that way
since it annotates the code nicely and implicitly documents how to do
this for any other register + data structure.

> Another alternative to caching "current" would be to cache the per-cpu
> offset, and calculate current from that one.

Good tip - I'll add this to my TODO list -

>   Arnd

--
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: [RFC Patch v1 32/55] ARC: [optim] Cache current in Register r25

2012-11-15 Thread Vineet Gupta
On Monday 12 November 2012 07:20 PM, Arnd Bergmann wrote:
 On Monday 12 November 2012, vineet.gup...@synopsys.com wrote:
  endmenu # Platform Board Configuration
  
 +config ARC_CURR_IN_REG
 +   bool Dedicate Register r25 for current_task pointer
 +   default y
 +   help
 + This reserved Register R25 to point to Current Task in
 + kernel mode. This saves memory access for each such access
 +
 This looks like a useful feature if you have 32 GPRs, but why make it
 optional? Are there cases where you would disable it?

Since it touched the low level guts of port, it made sense to start with
a config option in initial implementation. But I've kept it that way
since it annotates the code nicely and implicitly documents how to do
this for any other register + data structure.

 Another alternative to caching current would be to cache the per-cpu
 offset, and calculate current from that one.

Good tip - I'll add this to my TODO list -

   Arnd

--
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: [RFC Patch v1 32/55] ARC: [optim] Cache "current" in Register r25

2012-11-12 Thread Arnd Bergmann
On Monday 12 November 2012, vineet.gup...@synopsys.com wrote:
> 
>  endmenu # "Platform Board Configuration"
>  
> +config ARC_CURR_IN_REG
> +   bool "Dedicate Register r25 for current_task pointer"
> +   default y
> +   help
> + This reserved Register R25 to point to Current Task in
> + kernel mode. This saves memory access for each such access
> +

This looks like a useful feature if you have 32 GPRs, but why make it
optional? Are there cases where you would disable it?

Another alternative to caching "current" would be to cache the per-cpu
offset, and calculate current from that one.

Arnd
--
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/


[RFC Patch v1 32/55] ARC: [optim] Cache "current" in Register r25

2012-11-12 Thread Vineet.Gupta1
From: Vineet Gupta 

Signed-off-by: Vineet Gupta 
---
 arch/arc/Kconfig |7 ++
 arch/arc/Makefile|9 +++
 arch/arc/include/asm/Kbuild  |1 -
 arch/arc/include/asm/current.h   |   32 +++
 arch/arc/include/asm/entry.h |   45 ++
 arch/arc/include/asm/processor.h |3 ++
 arch/arc/kernel/asm-offsets.c|3 ++
 arch/arc/kernel/ctx_sw.c |7 ++
 arch/arc/kernel/entry.S  |   14 +++
 9 files changed, 120 insertions(+), 1 deletions(-)
 create mode 100644 arch/arc/include/asm/current.h

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index f3aacfc..71e55c0 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -277,6 +277,13 @@ config ARC_PLAT_SDRAM_SIZE
 
 endmenu # "Platform Board Configuration"
 
+config ARC_CURR_IN_REG
+   bool "Dedicate Register r25 for current_task pointer"
+   default y
+   help
+ This reserved Register R25 to point to Current Task in
+ kernel mode. This saves memory access for each such access
+
 config ARC_STACK_NONEXEC
bool "Make stack non-executable"
default n
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index 4d52a3b..eeb64dd 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -20,6 +20,15 @@ export PLATFORM
 cflags-y   += -Iarch/arc/plat-$(PLATFORM)/include
 cflags-y   += -mA7 -fno-common -pipe -fno-builtin -D__linux__
 
+ifdef CONFIG_ARC_CURR_IN_REG
+# For a global register defintion, make sure it gets passed to every file
+# We had a customer reported bug where some code built in kernel was NOT using
+# any kernel headers, and missing the r25 global register
+# Can't do unconditionally (like above) because of recursive include issues
+# due to 
+LINUXINCLUDE   +=  -include ${src}/arch/arc/include/asm/current.h
+endif
+
 atleast_gcc44 :=  $(call cc-ifversion, -gt, 0402, y)
 cflags-$(atleast_gcc44)+= -fsection-anchors
 
diff --git a/arch/arc/include/asm/Kbuild b/arch/arc/include/asm/Kbuild
index 148dfcf..a246390 100644
--- a/arch/arc/include/asm/Kbuild
+++ b/arch/arc/include/asm/Kbuild
@@ -11,7 +11,6 @@ generic-y += bugs.h
 generic-y += bitsperlong.h
 generic-y += clkdev.h
 generic-y += cputime.h
-generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
 generic-y += emergency-restart.h
diff --git a/arch/arc/include/asm/current.h b/arch/arc/include/asm/current.h
new file mode 100644
index 000..87b9185
--- /dev/null
+++ b/arch/arc/include/asm/current.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Vineetg: May 16th, 2008
+ *  - Current macro is now implemented as "global register" r25
+ */
+
+#ifndef _ASM_ARC_CURRENT_H
+#define _ASM_ARC_CURRENT_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+#ifdef CONFIG_ARC_CURR_IN_REG
+
+register struct task_struct *curr_arc asm("r25");
+#define current (curr_arc)
+
+#else
+#include 
+#endif /* ! CONFIG_ARC_CURR_IN_REG */
+
+#endif /* ! __ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_ARC_CURRENT_H */
diff --git a/arch/arc/include/asm/entry.h b/arch/arc/include/asm/entry.h
index 3e0a9f4..6113e1a 100644
--- a/arch/arc/include/asm/entry.h
+++ b/arch/arc/include/asm/entry.h
@@ -13,6 +13,8 @@
  *   was being "CLEARED" rather then "SET". Actually "SET" clears ZOL context
  *
  * Vineetg: May 5th 2008
+ *  -Modified CALLEE_REG save/restore macros to handle the fact that
+ *  r25 contains the kernel current task ptr
  *  - Defined Stack Switching Macro to be reused in all intr/excp hdlrs
  *  - Shaved off 11 instructions from RESTORE_ALL_INT1 by using the
  *  address Write back load ld.ab instead of seperate ld/add instn
@@ -28,6 +30,7 @@
 #include 
 #include 
 #include 
+#include  /* For VMALLOC_START */
 #include/* For THREAD_SIZE */
 
 /* Note on the LD/ST addr modes with addr reg wback
@@ -106,7 +109,14 @@
st.ar22, [sp, -4]
st.ar23, [sp, -4]
st.ar24, [sp, -4]
+
+#ifdef CONFIG_ARC_CURR_IN_REG
+   ; Retrieve orig r25 and save it on stack
+   ld  r12, [r25, TASK_THREAD + THREAD_USER_R25]
+   st.ar12, [sp, -4]
+#else
st.ar25, [sp, -4]
+#endif
 
/* move up by 1 word to "create" callee_regs->"stack_place_holder" */
sub sp, sp, 4
@@ -131,8 +141,12 @@
st.ar22, [sp, -4]
st.ar23, [sp, -4]
st.ar24, [sp, -4]
+#ifdef CONFIG_ARC_CURR_IN_REG
+   sub sp, sp, 8
+#else
st.ar25, [sp, -4]
sub sp, sp, 4
+#endif
 .endm
 
 /*--
@@ -148,8 +162,14 @@
  *-*/
 .macro 

[RFC Patch v1 32/55] ARC: [optim] Cache current in Register r25

2012-11-12 Thread Vineet.Gupta1
From: Vineet Gupta vgu...@synopsys.com

Signed-off-by: Vineet Gupta vgu...@synopsys.com
---
 arch/arc/Kconfig |7 ++
 arch/arc/Makefile|9 +++
 arch/arc/include/asm/Kbuild  |1 -
 arch/arc/include/asm/current.h   |   32 +++
 arch/arc/include/asm/entry.h |   45 ++
 arch/arc/include/asm/processor.h |3 ++
 arch/arc/kernel/asm-offsets.c|3 ++
 arch/arc/kernel/ctx_sw.c |7 ++
 arch/arc/kernel/entry.S  |   14 +++
 9 files changed, 120 insertions(+), 1 deletions(-)
 create mode 100644 arch/arc/include/asm/current.h

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index f3aacfc..71e55c0 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -277,6 +277,13 @@ config ARC_PLAT_SDRAM_SIZE
 
 endmenu # Platform Board Configuration
 
+config ARC_CURR_IN_REG
+   bool Dedicate Register r25 for current_task pointer
+   default y
+   help
+ This reserved Register R25 to point to Current Task in
+ kernel mode. This saves memory access for each such access
+
 config ARC_STACK_NONEXEC
bool Make stack non-executable
default n
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index 4d52a3b..eeb64dd 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -20,6 +20,15 @@ export PLATFORM
 cflags-y   += -Iarch/arc/plat-$(PLATFORM)/include
 cflags-y   += -mA7 -fno-common -pipe -fno-builtin -D__linux__
 
+ifdef CONFIG_ARC_CURR_IN_REG
+# For a global register defintion, make sure it gets passed to every file
+# We had a customer reported bug where some code built in kernel was NOT using
+# any kernel headers, and missing the r25 global register
+# Can't do unconditionally (like above) because of recursive include issues
+# due to linux/thread_info.h
+LINUXINCLUDE   +=  -include ${src}/arch/arc/include/asm/current.h
+endif
+
 atleast_gcc44 :=  $(call cc-ifversion, -gt, 0402, y)
 cflags-$(atleast_gcc44)+= -fsection-anchors
 
diff --git a/arch/arc/include/asm/Kbuild b/arch/arc/include/asm/Kbuild
index 148dfcf..a246390 100644
--- a/arch/arc/include/asm/Kbuild
+++ b/arch/arc/include/asm/Kbuild
@@ -11,7 +11,6 @@ generic-y += bugs.h
 generic-y += bitsperlong.h
 generic-y += clkdev.h
 generic-y += cputime.h
-generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
 generic-y += emergency-restart.h
diff --git a/arch/arc/include/asm/current.h b/arch/arc/include/asm/current.h
new file mode 100644
index 000..87b9185
--- /dev/null
+++ b/arch/arc/include/asm/current.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Vineetg: May 16th, 2008
+ *  - Current macro is now implemented as global register r25
+ */
+
+#ifndef _ASM_ARC_CURRENT_H
+#define _ASM_ARC_CURRENT_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+#ifdef CONFIG_ARC_CURR_IN_REG
+
+register struct task_struct *curr_arc asm(r25);
+#define current (curr_arc)
+
+#else
+#include asm-generic/current.h
+#endif /* ! CONFIG_ARC_CURR_IN_REG */
+
+#endif /* ! __ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_ARC_CURRENT_H */
diff --git a/arch/arc/include/asm/entry.h b/arch/arc/include/asm/entry.h
index 3e0a9f4..6113e1a 100644
--- a/arch/arc/include/asm/entry.h
+++ b/arch/arc/include/asm/entry.h
@@ -13,6 +13,8 @@
  *   was being CLEARED rather then SET. Actually SET clears ZOL context
  *
  * Vineetg: May 5th 2008
+ *  -Modified CALLEE_REG save/restore macros to handle the fact that
+ *  r25 contains the kernel current task ptr
  *  - Defined Stack Switching Macro to be reused in all intr/excp hdlrs
  *  - Shaved off 11 instructions from RESTORE_ALL_INT1 by using the
  *  address Write back load ld.ab instead of seperate ld/add instn
@@ -28,6 +30,7 @@
 #include asm/asm-offsets.h
 #include asm/arcregs.h
 #include asm/ptrace.h
+#include asm/processor.h /* For VMALLOC_START */
 #include asm/thread_info.h   /* For THREAD_SIZE */
 
 /* Note on the LD/ST addr modes with addr reg wback
@@ -106,7 +109,14 @@
st.ar22, [sp, -4]
st.ar23, [sp, -4]
st.ar24, [sp, -4]
+
+#ifdef CONFIG_ARC_CURR_IN_REG
+   ; Retrieve orig r25 and save it on stack
+   ld  r12, [r25, TASK_THREAD + THREAD_USER_R25]
+   st.ar12, [sp, -4]
+#else
st.ar25, [sp, -4]
+#endif
 
/* move up by 1 word to create callee_regs-stack_place_holder */
sub sp, sp, 4
@@ -131,8 +141,12 @@
st.ar22, [sp, -4]
st.ar23, [sp, -4]
st.ar24, [sp, -4]
+#ifdef CONFIG_ARC_CURR_IN_REG
+   sub sp, sp, 8
+#else
st.ar25, [sp, -4]
sub sp, sp, 4
+#endif
 .endm
 
 

Re: [RFC Patch v1 32/55] ARC: [optim] Cache current in Register r25

2012-11-12 Thread Arnd Bergmann
On Monday 12 November 2012, vineet.gup...@synopsys.com wrote:
 
  endmenu # Platform Board Configuration
  
 +config ARC_CURR_IN_REG
 +   bool Dedicate Register r25 for current_task pointer
 +   default y
 +   help
 + This reserved Register R25 to point to Current Task in
 + kernel mode. This saves memory access for each such access
 +

This looks like a useful feature if you have 32 GPRs, but why make it
optional? Are there cases where you would disable it?

Another alternative to caching current would be to cache the per-cpu
offset, and calculate current from that one.

Arnd
--
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/