Re: [patch 13/37] Immediate Values - Architecture Independent Code

Previous thread: [patch 12/37] Add all cpus option to stop machine run by Mathieu Desnoyers on Thursday, April 24, 2008 - 8:03 am. (1 message)

Next thread: [patch 15/37] Immediate Values - x86 Optimization by Mathieu Desnoyers on Thursday, April 24, 2008 - 8:03 am. (1 message)
From: Mathieu Desnoyers
Date: Thursday, April 24, 2008 - 8:03 am

Immediate values are used as read mostly variables that are rarely updated. They
use code patching to modify the values inscribed in the instruction stream. It
provides a way to save precious cache lines that would otherwise have to be used
by these variables.

There is a generic _imv_read() version, which uses standard global
variables, and optimized per architecture imv_read() implementations,
which use a load immediate to remove a data cache hit. When the immediate values
functionnality is disabled in the kernel, it falls back to global variables.

It adds a new rodata section "__imv" to place the pointers to the enable
value. Immediate values activation functions sits in kernel/immediate.c.

Immediate values refer to the memory address of a previously declared integer.
This integer holds the information about the state of the immediate values
associated, and must be accessed through the API found in linux/immediate.h.

At module load time, each immediate value is checked to see if it must be
enabled. It would be the case if the variable they refer to is exported from
another module and already enabled.

In the early stages of start_kernel(), the immediate values are updated to
reflect the state of the variable they refer to.

* Why should this be merged *

It improves performances on heavy memory I/O workloads.

An interesting result shows the potential this infrastructure has by
showing the slowdown a simple system call such as getppid() suffers when it is
used under heavy user-space cache trashing:

Random walk L1 and L2 trashing surrounding a getppid() call:
(note: in this test, do_syscal_trace was taken at each system call, see
Documentation/immediate.txt in these patches for details)
- No memory pressure :   getppid() takes  1573 cycles
- With memory pressure : getppid() takes 15589 cycles

We therefore have a slowdown of 10 times just to get the kernel variables from
memory. Another test on the same architecture (Intel P4) measured the memory
latency to be 559 ...
From: Ingo Molnar
Date: Friday, April 25, 2008 - 7:55 am

randconfig testing in sched-devel caught a build bug - fixed by the 
patch below.

	Ingo

-------------->
Subject: markers: build fix
From: Ingo Molnar <mingo@elte.hu>
Date: Fri Apr 25 16:36:15 CEST 2008

fix:

 include/linux/module.h:587: error: redefinition of 'module_imv_update'
 include/linux/immediate.h:74: error: previous definition of 'module_imv_update' was here

the prototype was unnecessary.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/linux/immediate.h |    1 -
 1 file changed, 1 deletion(-)

Index: linux/include/linux/immediate.h
===================================================================
--- linux.orig/include/linux/immediate.h
+++ linux/include/linux/immediate.h
@@ -71,7 +71,6 @@ extern void imv_unref(struct __imv *begi
 #define imv_set(name, i)		(name##__imv = (i))
 
 static inline void core_imv_update(void) { }
-static inline void module_imv_update(void) { }
 static inline void imv_unref_core_init(void) { }
 
 #endif
--

From: Ingo Molnar
Date: Saturday, April 26, 2008 - 2:36 am

found another build failure - the better fix is the one below.

	Ingo

------------------------->
Subject: markers: fix2
From: Ingo Molnar <mingo@elte.hu>
Date: Sat Apr 26 11:19:00 CEST 2008

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/linux/module.h |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Index: linux/include/linux/module.h
===================================================================
--- linux.orig/include/linux/module.h
+++ linux/include/linux/module.h
@@ -472,9 +472,6 @@ extern void print_modules(void);
 
 extern void module_update_markers(void);
 
-extern void _module_imv_update(void);
-extern void module_imv_update(void);
-
 #else /* !CONFIG_MODULES... */
 #define EXPORT_SYMBOL(sym)
 #define EXPORT_SYMBOL_GPL(sym)
@@ -579,15 +576,19 @@ static inline void module_update_markers
 {
 }
 
+#endif /* CONFIG_MODULES */
+
+#if defined(MODULES) && defined(CONFIG_IMMEDIATE)
+extern void _module_imv_update(void);
+extern void module_imv_update(void);
+#else
 static inline void _module_imv_update(void)
 {
 }
-
 static inline void module_imv_update(void)
 {
 }
-
-#endif /* CONFIG_MODULES */
+#endif
 
 struct device_driver;
 #ifdef CONFIG_SYSFS
--

From: Ingo Molnar
Date: Saturday, April 26, 2008 - 4:09 am

or rather the one below ...

------------>
Subject: markers: fix2
From: Ingo Molnar <mingo@elte.hu>
Date: Sat Apr 26 11:19:00 CEST 2008

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/linux/module.h |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Index: linux/include/linux/module.h
===================================================================
--- linux.orig/include/linux/module.h
+++ linux/include/linux/module.h
@@ -472,9 +472,6 @@ extern void print_modules(void);
 
 extern void module_update_markers(void);
 
-extern void _module_imv_update(void);
-extern void module_imv_update(void);
-
 #else /* !CONFIG_MODULES... */
 #define EXPORT_SYMBOL(sym)
 #define EXPORT_SYMBOL_GPL(sym)
@@ -579,15 +576,19 @@ static inline void module_update_markers
 {
 }
 
+#endif /* CONFIG_MODULES */
+
+#if defined(CONFIG_MODULES) && defined(CONFIG_IMMEDIATE)
+extern void _module_imv_update(void);
+extern void module_imv_update(void);
+#else
 static inline void _module_imv_update(void)
 {
 }
-
 static inline void module_imv_update(void)
 {
 }
-
-#endif /* CONFIG_MODULES */
+#endif
 
 struct device_driver;
 #ifdef CONFIG_SYSFS
--

From: Mathieu Desnoyers
Date: Saturday, April 26, 2008 - 7:17 am

Good catch, thanks!


-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
--

Previous thread: [patch 12/37] Add all cpus option to stop machine run by Mathieu Desnoyers on Thursday, April 24, 2008 - 8:03 am. (1 message)

Next thread: [patch 15/37] Immediate Values - x86 Optimization by Mathieu Desnoyers on Thursday, April 24, 2008 - 8:03 am. (1 message)