* [patch 8/8] Scheduler profiling - Use immediate values
2007-06-15 20:23 [patch 0/8] Immediate values for fast branches Mathieu Desnoyers
@ 2007-06-15 20:23 ` Mathieu Desnoyers
0 siblings, 0 replies; 15+ messages in thread
From: Mathieu Desnoyers @ 2007-06-15 20:23 UTC (permalink / raw)
To: akpm, linux-kernel; +Cc: Mathieu Desnoyers
[-- Attachment #1: profiling-use-immediate-values.patch --]
[-- Type: text/plain, Size: 6560 bytes --]
Use immediate values with lower d-cache hit in optimized version as a
condition for scheduler profiling call.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
drivers/kvm/svm.c | 2 +-
drivers/kvm/vmx.c | 2 +-
include/linux/profile.h | 9 +++------
kernel/profile.c | 37 +++++++++++++++++++++++++------------
kernel/sched.c | 3 ++-
5 files changed, 32 insertions(+), 21 deletions(-)
Index: linux-2.6-lttng/kernel/profile.c
===================================================================
--- linux-2.6-lttng.orig/kernel/profile.c 2007-06-15 16:13:50.000000000 -0400
+++ linux-2.6-lttng/kernel/profile.c 2007-06-15 16:14:07.000000000 -0400
@@ -23,6 +23,7 @@
#include <linux/profile.h>
#include <linux/highmem.h>
#include <linux/mutex.h>
+#include <linux/immediate.h>
#include <asm/sections.h>
#include <asm/semaphore.h>
#include <asm/irq_regs.h>
@@ -42,9 +43,6 @@
static atomic_t *prof_buffer;
static unsigned long prof_len, prof_shift;
-int prof_on __read_mostly;
-EXPORT_SYMBOL_GPL(prof_on);
-
static cpumask_t prof_cpu_mask = CPU_MASK_ALL;
#ifdef CONFIG_SMP
static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
@@ -52,6 +50,12 @@
static DEFINE_MUTEX(profile_flip_mutex);
#endif /* CONFIG_SMP */
+/* Immediate values */
+immediate_t __read_mostly sleep_profiling, sched_profiling, kvm_profiling,
+ cpu_profiling;
+EXPORT_SYMBOL_GPL(kvm_profiling);
+EXPORT_SYMBOL_GPL(cpu_profiling);
+
static int __init profile_setup(char * str)
{
static char __initdata schedstr[] = "schedule";
@@ -60,7 +64,7 @@
int par;
if (!strncmp(str, sleepstr, strlen(sleepstr))) {
- prof_on = SLEEP_PROFILING;
+ immediate_arm(&sleep_profiling);
if (str[strlen(sleepstr)] == ',')
str += strlen(sleepstr) + 1;
if (get_option(&str, &par))
@@ -69,7 +73,7 @@
"kernel sleep profiling enabled (shift: %ld)\n",
prof_shift);
} else if (!strncmp(str, schedstr, strlen(schedstr))) {
- prof_on = SCHED_PROFILING;
+ immediate_arm(&sched_profiling);
if (str[strlen(schedstr)] == ',')
str += strlen(schedstr) + 1;
if (get_option(&str, &par))
@@ -78,7 +82,7 @@
"kernel schedule profiling enabled (shift: %ld)\n",
prof_shift);
} else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
- prof_on = KVM_PROFILING;
+ immediate_arm(&kvm_profiling);
if (str[strlen(kvmstr)] == ',')
str += strlen(kvmstr) + 1;
if (get_option(&str, &par))
@@ -88,7 +92,7 @@
prof_shift);
} else if (get_option(&str, &par)) {
prof_shift = par;
- prof_on = CPU_PROFILING;
+ immediate_arm(&cpu_profiling);
printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
prof_shift);
}
@@ -99,7 +103,10 @@
void __init profile_init(void)
{
- if (!prof_on)
+ if (!immediate_query(&sleep_profiling) &&
+ !immediate_query(&sched_profiling) &&
+ !immediate_query(&kvm_profiling) &&
+ !immediate_query(&cpu_profiling))
return;
/* only text is profiled */
@@ -288,7 +295,7 @@
int i, j, cpu;
struct profile_hit *hits;
- if (prof_on != type || !prof_buffer)
+ if (!prof_buffer)
return;
pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
@@ -398,7 +405,7 @@
{
unsigned long pc;
- if (prof_on != type || !prof_buffer)
+ if (!prof_buffer)
return;
pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
@@ -555,7 +562,10 @@
}
return 0;
out_cleanup:
- prof_on = 0;
+ immediate_disarm(&sleep_profiling);
+ immediate_disarm(&sched_profiling);
+ immediate_disarm(&kvm_profiling);
+ immediate_disarm(&cpu_profiling);
smp_mb();
on_each_cpu(profile_nop, NULL, 0, 1);
for_each_online_cpu(cpu) {
@@ -582,7 +592,10 @@
{
struct proc_dir_entry *entry;
- if (!prof_on)
+ if (!immediate_query(&sleep_profiling) &&
+ !immediate_query(&sched_profiling) &&
+ !immediate_query(&kvm_profiling) &&
+ !immediate_query(&cpu_profiling))
return 0;
if (create_hash_tables())
return -1;
Index: linux-2.6-lttng/include/linux/profile.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/profile.h 2007-06-15 16:13:50.000000000 -0400
+++ linux-2.6-lttng/include/linux/profile.h 2007-06-15 16:14:07.000000000 -0400
@@ -10,7 +10,8 @@
#include <asm/errno.h>
-extern int prof_on __read_mostly;
+extern immediate_t __read_mostly sleep_profiling, sched_profiling, kvm_profiling,
+ cpu_profiling;
#define CPU_PROFILING 1
#define SCHED_PROFILING 2
@@ -35,11 +36,7 @@
*/
static inline void profile_hit(int type, void *ip)
{
- /*
- * Speedup for the common (no profiling enabled) case:
- */
- if (unlikely(prof_on == type))
- profile_hits(type, ip, 1);
+ profile_hits(type, ip, 1);
}
#ifdef CONFIG_PROC_FS
Index: linux-2.6-lttng/kernel/sched.c
===================================================================
--- linux-2.6-lttng.orig/kernel/sched.c 2007-06-15 16:13:50.000000000 -0400
+++ linux-2.6-lttng/kernel/sched.c 2007-06-15 16:14:07.000000000 -0400
@@ -2998,7 +2998,8 @@
print_irqtrace_events(prev);
dump_stack();
}
- profile_hit(SCHED_PROFILING, __builtin_return_address(0));
+ if (unlikely(immediate(sched_profiling)))
+ profile_hit(SCHED_PROFILING, __builtin_return_address(0));
/*
* The idle thread is not allowed to schedule!
Index: linux-2.6-lttng/drivers/kvm/svm.c
===================================================================
--- linux-2.6-lttng.orig/drivers/kvm/svm.c 2007-06-15 16:13:50.000000000 -0400
+++ linux-2.6-lttng/drivers/kvm/svm.c 2007-06-15 16:14:07.000000000 -0400
@@ -1647,7 +1647,7 @@
/*
* Profile KVM exit RIPs:
*/
- if (unlikely(prof_on == KVM_PROFILING))
+ if (unlikely(immediate(kvm_profiling)))
profile_hit(KVM_PROFILING,
(void *)(unsigned long)vcpu->svm->vmcb->save.rip);
Index: linux-2.6-lttng/drivers/kvm/vmx.c
===================================================================
--- linux-2.6-lttng.orig/drivers/kvm/vmx.c 2007-06-15 16:13:50.000000000 -0400
+++ linux-2.6-lttng/drivers/kvm/vmx.c 2007-06-15 16:14:07.000000000 -0400
@@ -2131,7 +2131,7 @@
/*
* Profile KVM exit RIPs:
*/
- if (unlikely(prof_on == KVM_PROFILING))
+ if (unlikely(immediate(kvm_profiling)))
profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
vcpu->launched = 1;
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
^ permalink raw reply [flat|nested] 15+ messages in thread
* [patch 8/8] Scheduler Profiling - Use Immediate Values
2007-08-12 15:07 [patch 0/8] " Mathieu Desnoyers
@ 2007-08-12 15:07 ` Mathieu Desnoyers
0 siblings, 0 replies; 15+ messages in thread
From: Mathieu Desnoyers @ 2007-08-12 15:07 UTC (permalink / raw)
To: akpm, linux-kernel; +Cc: Mathieu Desnoyers
[-- Attachment #1: profiling-use-immediate-values.patch --]
[-- Type: text/plain, Size: 6569 bytes --]
Use immediate values with lower d-cache hit in optimized version as a
condition for scheduler profiling call.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
drivers/kvm/svm.c | 2 +-
drivers/kvm/vmx.c | 2 +-
include/linux/profile.h | 10 ++++------
kernel/profile.c | 38 ++++++++++++++++++++++++++------------
kernel/sched.c | 3 ++-
5 files changed, 34 insertions(+), 21 deletions(-)
Index: linux-2.6-lttng/kernel/profile.c
===================================================================
--- linux-2.6-lttng.orig/kernel/profile.c 2007-07-13 19:30:58.000000000 -0400
+++ linux-2.6-lttng/kernel/profile.c 2007-07-13 19:32:49.000000000 -0400
@@ -42,9 +42,6 @@
static atomic_t *prof_buffer;
static unsigned long prof_len, prof_shift;
-int prof_on __read_mostly;
-EXPORT_SYMBOL_GPL(prof_on);
-
static cpumask_t prof_cpu_mask = CPU_MASK_ALL;
#ifdef CONFIG_SMP
static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
@@ -52,6 +49,14 @@
static DEFINE_MUTEX(profile_flip_mutex);
#endif /* CONFIG_SMP */
+/* Immediate values */
+immediate_char_t sleep_profiling __read_mostly,
+ sched_profiling __read_mostly,
+ kvm_profiling __read_mostly,
+ cpu_profiling __read_mostly;
+EXPORT_SYMBOL_GPL(kvm_profiling);
+EXPORT_SYMBOL_GPL(cpu_profiling);
+
static int __init profile_setup(char * str)
{
static char __initdata schedstr[] = "schedule";
@@ -60,7 +65,7 @@
int par;
if (!strncmp(str, sleepstr, strlen(sleepstr))) {
- prof_on = SLEEP_PROFILING;
+ immediate_set_early(&sleep_profiling, 1);
if (str[strlen(sleepstr)] == ',')
str += strlen(sleepstr) + 1;
if (get_option(&str, &par))
@@ -69,7 +74,7 @@
"kernel sleep profiling enabled (shift: %ld)\n",
prof_shift);
} else if (!strncmp(str, schedstr, strlen(schedstr))) {
- prof_on = SCHED_PROFILING;
+ immediate_set_early(&sched_profiling, 1);
if (str[strlen(schedstr)] == ',')
str += strlen(schedstr) + 1;
if (get_option(&str, &par))
@@ -78,7 +83,7 @@
"kernel schedule profiling enabled (shift: %ld)\n",
prof_shift);
} else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
- prof_on = KVM_PROFILING;
+ immediate_set_early(&kvm_profiling, 1);
if (str[strlen(kvmstr)] == ',')
str += strlen(kvmstr) + 1;
if (get_option(&str, &par))
@@ -88,7 +93,7 @@
prof_shift);
} else if (get_option(&str, &par)) {
prof_shift = par;
- prof_on = CPU_PROFILING;
+ immediate_set_early(&cpu_profiling, 1);
printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
prof_shift);
}
@@ -99,7 +104,10 @@
void __init profile_init(void)
{
- if (!prof_on)
+ if (!_immediate_read(&sleep_profiling) &&
+ !_immediate_read(&sched_profiling) &&
+ !_immediate_read(&kvm_profiling) &&
+ !_immediate_read(&cpu_profiling))
return;
/* only text is profiled */
@@ -288,7 +296,7 @@
int i, j, cpu;
struct profile_hit *hits;
- if (prof_on != type || !prof_buffer)
+ if (!prof_buffer)
return;
pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
@@ -398,7 +406,7 @@
{
unsigned long pc;
- if (prof_on != type || !prof_buffer)
+ if (!prof_buffer)
return;
pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
@@ -555,7 +563,10 @@
}
return 0;
out_cleanup:
- prof_on = 0;
+ immediate_set_early(&sleep_profiling, 0);
+ immediate_set_early(&sched_profiling, 0);
+ immediate_set_early(&kvm_profiling, 0);
+ immediate_set_early(&cpu_profiling, 0);
smp_mb();
on_each_cpu(profile_nop, NULL, 0, 1);
for_each_online_cpu(cpu) {
@@ -582,7 +593,10 @@
{
struct proc_dir_entry *entry;
- if (!prof_on)
+ if (!_immediate_read(&sleep_profiling) &&
+ !_immediate_read(&sched_profiling) &&
+ !_immediate_read(&kvm_profiling) &&
+ !_immediate_read(&cpu_profiling))
return 0;
if (create_hash_tables())
return -1;
Index: linux-2.6-lttng/include/linux/profile.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/profile.h 2007-07-13 19:30:58.000000000 -0400
+++ linux-2.6-lttng/include/linux/profile.h 2007-07-13 19:32:00.000000000 -0400
@@ -7,10 +7,12 @@
#include <linux/init.h>
#include <linux/cpumask.h>
#include <linux/cache.h>
+#include <linux/immediate.h>
#include <asm/errno.h>
-extern int prof_on __read_mostly;
+extern immediate_char_t sleep_profiling, sched_profiling, kvm_profiling,
+ cpu_profiling;
#define CPU_PROFILING 1
#define SCHED_PROFILING 2
@@ -35,11 +37,7 @@
*/
static inline void profile_hit(int type, void *ip)
{
- /*
- * Speedup for the common (no profiling enabled) case:
- */
- if (unlikely(prof_on == type))
- profile_hits(type, ip, 1);
+ profile_hits(type, ip, 1);
}
#ifdef CONFIG_PROC_FS
Index: linux-2.6-lttng/kernel/sched.c
===================================================================
--- linux-2.6-lttng.orig/kernel/sched.c 2007-07-13 19:30:58.000000000 -0400
+++ linux-2.6-lttng/kernel/sched.c 2007-07-13 19:32:00.000000000 -0400
@@ -3241,7 +3241,8 @@
if (unlikely(in_atomic_preempt_off()) && unlikely(!prev->exit_state))
__schedule_bug(prev);
- profile_hit(SCHED_PROFILING, __builtin_return_address(0));
+ immediate_if (&sched_profiling)
+ profile_hit(SCHED_PROFILING, __builtin_return_address(0));
schedstat_inc(this_rq(), sched_cnt);
}
Index: linux-2.6-lttng/drivers/kvm/svm.c
===================================================================
--- linux-2.6-lttng.orig/drivers/kvm/svm.c 2007-07-13 19:30:58.000000000 -0400
+++ linux-2.6-lttng/drivers/kvm/svm.c 2007-07-13 19:32:00.000000000 -0400
@@ -1654,7 +1654,7 @@
/*
* Profile KVM exit RIPs:
*/
- if (unlikely(prof_on == KVM_PROFILING))
+ immediate_if (&kvm_profiling)
profile_hit(KVM_PROFILING,
(void *)(unsigned long)vcpu->svm->vmcb->save.rip);
Index: linux-2.6-lttng/drivers/kvm/vmx.c
===================================================================
--- linux-2.6-lttng.orig/drivers/kvm/vmx.c 2007-07-13 19:30:58.000000000 -0400
+++ linux-2.6-lttng/drivers/kvm/vmx.c 2007-07-13 19:32:00.000000000 -0400
@@ -2156,7 +2156,7 @@
/*
* Profile KVM exit RIPs:
*/
- if (unlikely(prof_on == KVM_PROFILING))
+ immediate_if (&kvm_profiling)
profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
vcpu->launched = 1;
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
^ permalink raw reply [flat|nested] 15+ messages in thread
* [patch 0/8] Immediate Values
@ 2007-08-20 20:23 Mathieu Desnoyers
2007-08-20 20:23 ` [patch 1/8] Immediate Values - Global Modules List and Module Mutex Mathieu Desnoyers
` (7 more replies)
0 siblings, 8 replies; 15+ messages in thread
From: Mathieu Desnoyers @ 2007-08-20 20:23 UTC (permalink / raw)
To: akpm, linux-kernel
Hi Andrew,
Changelog since the last post:
- Adapt to the new text edit lock.
- Add more test results to Documentation/immediate.txt
Applies to 2.6.23-rc2-mm2, depends on the Text Edit Lock patchset.
Patch order:
immediate-values-global-modules-list-and-mutex.patch
immediate-values-architecture-independent-code.patch
immediate-values-kconfig-embedded.patch
immediate-values-move-kprobes-i386-restore-interrupt-to-kdebug-h.patch
immediate-values-i386-optimization.patch
immediate-values-powerpc-optimization.patch
immediate-values-documentation.patch
profiling-use-immediate-values.patch
Mathieu
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
^ permalink raw reply [flat|nested] 15+ messages in thread
* [patch 1/8] Immediate Values - Global Modules List and Module Mutex
2007-08-20 20:23 [patch 0/8] Immediate Values Mathieu Desnoyers
@ 2007-08-20 20:23 ` Mathieu Desnoyers
2007-08-20 20:23 ` [patch 2/8] Immediate Values - Architecture Independent Code Mathieu Desnoyers
` (6 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Mathieu Desnoyers @ 2007-08-20 20:23 UTC (permalink / raw)
To: akpm, linux-kernel; +Cc: Mathieu Desnoyers
[-- Attachment #1: immediate-values-global-modules-list-and-mutex.patch --]
[-- Type: text/plain, Size: 2184 bytes --]
Remove "static" from module_mutex and the modules list so it can be used by
other builtin objects in the kernel. Otherwise, every code depending on the
module list would have to be put in kernel/module.c. Since the immediate values
depends on the module list but can be considered as logically different, it
makes sense to implement them in their own file.
The alternative to this would be to disable preemption in code path that need
such synchronization, so they can be protected against module unload by
stop_machine(), but not being able to sleep within while needing such
synchronization is limiting.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
include/linux/module.h | 4 ++++
kernel/module.c | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
Index: linux-2.6-lttng/kernel/module.c
===================================================================
--- linux-2.6-lttng.orig/kernel/module.c 2007-08-07 11:03:56.000000000 -0400
+++ linux-2.6-lttng/kernel/module.c 2007-08-07 11:40:22.000000000 -0400
@@ -64,8 +64,8 @@ extern int module_sysfs_initialized;
/* List of modules, protected by module_mutex or preempt_disable
* (add/delete uses stop_machine). */
-static DEFINE_MUTEX(module_mutex);
-static LIST_HEAD(modules);
+DEFINE_MUTEX(module_mutex);
+LIST_HEAD(modules);
static DECLARE_MUTEX(notify_mutex);
static BLOCKING_NOTIFIER_HEAD(module_notify_list);
Index: linux-2.6-lttng/include/linux/module.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/module.h 2007-08-07 11:03:48.000000000 -0400
+++ linux-2.6-lttng/include/linux/module.h 2007-08-07 11:39:55.000000000 -0400
@@ -60,6 +60,10 @@ struct module_kobject
struct kobject *drivers_dir;
};
+/* Protects the list of modules. */
+extern struct mutex module_mutex;
+extern struct list_head modules;
+
/* These are either module local, or the kernel's dummy ones. */
extern int init_module(void);
extern void cleanup_module(void);
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
^ permalink raw reply [flat|nested] 15+ messages in thread
* [patch 2/8] Immediate Values - Architecture Independent Code
2007-08-20 20:23 [patch 0/8] Immediate Values Mathieu Desnoyers
2007-08-20 20:23 ` [patch 1/8] Immediate Values - Global Modules List and Module Mutex Mathieu Desnoyers
@ 2007-08-20 20:23 ` Mathieu Desnoyers
2007-08-20 20:23 ` [patch 3/8] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
` (5 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Mathieu Desnoyers @ 2007-08-20 20:23 UTC (permalink / raw)
To: akpm, linux-kernel; +Cc: Mathieu Desnoyers
[-- Attachment #1: immediate-values-architecture-independent-code.patch --]
[-- Type: text/plain, Size: 15624 bytes --]
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 _immediate_read() version, which uses standard global
variables, and optimized per architecture immediate_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 "__immediate" 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 cycles. Therefore, each cache line removed from the hot path
would improve the syscall time of 3.5% in these conditions.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
include/asm-generic/vmlinux.lds.h | 7 ++
include/linux/immediate.h | 119 +++++++++++++++++++++++++++++++++++
include/linux/module.h | 6 +
init/main.c | 2
kernel/Makefile | 1
kernel/immediate.c | 128 ++++++++++++++++++++++++++++++++++++++
kernel/module.c | 16 ++++
7 files changed, 279 insertions(+)
Index: linux-2.6-lttng/include/linux/immediate.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng/include/linux/immediate.h 2007-08-07 13:30:21.000000000 -0400
@@ -0,0 +1,119 @@
+#ifndef _LINUX_IMMEDIATE_H
+#define _LINUX_IMMEDIATE_H
+
+/*
+ * Immediate values, can be updated at runtime and save cache lines.
+ *
+ * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
+#ifdef CONFIG_IMMEDIATE
+#include <asm/immediate.h>
+#else
+/*
+ * Generic immediate values: a simple, standard, memory load.
+ */
+
+struct module;
+
+/**
+ * immediate_read - read immediate variable
+ * @var: pointer of type immediate_*_t
+ *
+ * Reads the value of @var.
+ */
+#define immediate_read(var) _immediate_read(var)
+
+/**
+ * immediate_set - set immediate variable (with locking)
+ * @var: pointer of type immediate_*_t
+ * @i: required value
+ *
+ * Sets the value of @var, taking the module_mutex if required by
+ * the architecture.
+ */
+#define immediate_set(var, i) ((var)->value = (i))
+
+/**
+ * _immediate_set - set immediate variable (without locking)
+ * @var: pointer of type immediate_*_t
+ * @i: required value
+ *
+ * Sets the value of @var. Must be called with module_mutex held.
+ */
+#define _immediate_set(var, i) immediate_set(var, i)
+
+/**
+ * immediate_set_early - set immediate variable at early boot
+ * @var: pointer of type immediate_*_t
+ * @i: required value
+ *
+ * Sets the value of @var. Should be used for early boot updates.
+ */
+#define immediate_set_early(var, i) immediate_set(var, i)
+
+/**
+ * immediate_if - if () statement depending on an immediate value
+ * @var: pointer of type immediate_*_t
+ *
+ * Use as an if () statement depending on an immediate value.
+ */
+#define immediate_if(var) if (immediate_read(var))
+
+/*
+ * Internal update functions.
+ */
+static inline void module_immediate_setup(struct module *mod) { }
+static inline void immediate_update_early(void) { }
+#endif
+
+/**
+ * DEFINE_IMMEDIATE_TYPE - Define an immediate type
+ * @type: type that the immediate should hold
+ * @name: name of the immediate type
+ *
+ * Define new immediate types. Naming scheme is immediate_*_t.
+ * Always access these types with the provided functions.
+ */
+#define DEFINE_IMMEDIATE_TYPE(type, name) \
+ typedef struct { type value; } name
+
+/*
+ * Standard pre-defined immediate types.
+ */
+DEFINE_IMMEDIATE_TYPE(char, immediate_char_t);
+DEFINE_IMMEDIATE_TYPE(short, immediate_short_t);
+DEFINE_IMMEDIATE_TYPE(int, immediate_int_t);
+DEFINE_IMMEDIATE_TYPE(long, immediate_long_t);
+DEFINE_IMMEDIATE_TYPE(void*, immediate_void_ptr_t);
+
+/**
+ * IMMEDIATE_INIT - Static initialization of an immediate variable
+ * @i: required value
+ *
+ * Use this macro to initialize an immediate value to an initial static
+ * value.
+ */
+#define IMMEDIATE_INIT(i) { (i) }
+
+/**
+ * _immediate_read - Read immediate value with standard memory load.
+ * @var: pointer of type immediate_*_t
+ *
+ * Force a data read of the immediate value instead of the immediate value
+ * based mechanism. Useful for __init and __exit section data read.
+ */
+#define _immediate_read(var) (var)->value
+
+/*
+ * _immediate_if - if () statement depending on immediate value (memory load)
+ * @var: pointer of type immediate_*_t
+ *
+ * Force the use of a normal if () statement depending on an immediate value.
+ */
+#define _immediate_if(var) if (_immediate_read(var))
+
+#endif
Index: linux-2.6-lttng/include/asm-generic/vmlinux.lds.h
===================================================================
--- linux-2.6-lttng.orig/include/asm-generic/vmlinux.lds.h 2007-08-07 13:28:12.000000000 -0400
+++ linux-2.6-lttng/include/asm-generic/vmlinux.lds.h 2007-08-07 13:29:55.000000000 -0400
@@ -122,6 +122,13 @@
VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
} \
\
+ /* Immediate values: pointers */ \
+ __immediate : AT(ADDR(__immediate) - LOAD_OFFSET) { \
+ VMLINUX_SYMBOL(__start___immediate) = .; \
+ *(__immediate) \
+ VMLINUX_SYMBOL(__stop___immediate) = .; \
+ } \
+ \
/* Kernel symbol table: strings */ \
__ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
*(__ksymtab_strings) \
Index: linux-2.6-lttng/include/linux/module.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/module.h 2007-08-07 13:29:52.000000000 -0400
+++ linux-2.6-lttng/include/linux/module.h 2007-08-07 13:29:55.000000000 -0400
@@ -15,6 +15,7 @@
#include <linux/stringify.h>
#include <linux/kobject.h>
#include <linux/moduleparam.h>
+#include <linux/immediate.h>
#include <asm/local.h>
#include <asm/module.h>
@@ -374,6 +375,11 @@ struct module
/* The command line arguments (may be mangled). People like
keeping pointers to this stuff */
char *args;
+
+#ifdef CONFIG_IMMEDIATE
+ const struct __immediate *immediate;
+ unsigned int num_immediate;
+#endif
};
#ifndef MODULE_ARCH_INIT
#define MODULE_ARCH_INIT {}
Index: linux-2.6-lttng/kernel/module.c
===================================================================
--- linux-2.6-lttng.orig/kernel/module.c 2007-08-07 13:29:52.000000000 -0400
+++ linux-2.6-lttng/kernel/module.c 2007-08-07 13:29:55.000000000 -0400
@@ -33,6 +33,7 @@
#include <linux/cpu.h>
#include <linux/moduleparam.h>
#include <linux/errno.h>
+#include <linux/immediate.h>
#include <linux/err.h>
#include <linux/vermagic.h>
#include <linux/notifier.h>
@@ -1719,6 +1720,7 @@ static struct module *load_module(void _
unsigned int unusedcrcindex;
unsigned int unusedgplindex;
unsigned int unusedgplcrcindex;
+ unsigned int immediateindex = 0;
struct module *mod;
long err = 0;
void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
@@ -1815,6 +1817,9 @@ static struct module *load_module(void _
#ifdef ARCH_UNWIND_SECTION_NAME
unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME);
#endif
+#ifdef CONFIG_IMMEDIATE
+ immediateindex = find_sec(hdr, sechdrs, secstrings, "__immediate");
+#endif
/* Don't keep modinfo section */
sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
@@ -1825,6 +1830,8 @@ static struct module *load_module(void _
#endif
if (unwindex)
sechdrs[unwindex].sh_flags |= SHF_ALLOC;
+ if (immediateindex)
+ sechdrs[immediateindex].sh_flags |= SHF_ALLOC;
/* Check module struct version now, before we try to use module. */
if (!check_modstruct_version(sechdrs, versindex, mod)) {
@@ -1965,6 +1972,13 @@ static struct module *load_module(void _
mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
if (gplfuturecrcindex)
mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
+#ifdef CONFIG_IMMEDIATE
+ if (immediateindex) {
+ mod->immediate = (void *)sechdrs[immediateindex].sh_addr;
+ mod->num_immediate =
+ sechdrs[immediateindex].sh_size / sizeof(*mod->immediate);
+ }
+#endif
mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr;
if (unusedcrcindex)
@@ -2031,6 +2045,8 @@ static struct module *load_module(void _
}
#endif
+ module_immediate_setup(mod);
+
err = module_finalize(hdr, sechdrs, mod);
if (err < 0)
goto cleanup;
Index: linux-2.6-lttng/kernel/Makefile
===================================================================
--- linux-2.6-lttng.orig/kernel/Makefile 2007-08-07 13:28:12.000000000 -0400
+++ linux-2.6-lttng/kernel/Makefile 2007-08-07 13:29:55.000000000 -0400
@@ -57,6 +57,7 @@ obj-$(CONFIG_RELAY) += relay.o
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
obj-$(CONFIG_TASKSTAT