introduce PICK_FUNCTION
Subsystems (6)
PATCH 1/8 introduce PICK_FUNCTION
PICK_FUNCTION() is similar to the other PICK_OP style macros, and was created to replace them all. I used variable argument macros to handle PICK_FUNC_2ARG/PICK_FUNC_1ARG. Otherwise the marcos are similar to the original macros used for semaphores. The entire system is used to do a compile time switch between two different locking APIs. For example, real spinlocks (raw_spinlock_t) and mutexes (or sleeping spinlocks).
This new macro replaces all the duplication from lock type to lock type. The result of this patch, and the next two, is a fairly nice simplification, and consolidation. Although the seqlock changes are larger than the originals I think over all the patchset is worth while.
Incorporated peterz's suggestion to not require TYPE_EQUAL() to only use pointers.
--- include/linux/pickop.h | 36 +++++++++++++ include/linux/rt_lock.h | 129 +++++++++++++++--------------------------------- 2 files changed, 77 insertions(+), 88 deletions(-)
include/linux/pickop.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef _LINUX_PICKOP_H +#define _LINUX_PICKOP_H + +#undef TYPE_EQUAL +#define TYPE_EQUAL (var, type) \ + __builtin_types_compatible_p(typeof(var), type *) + +#undef PICK_TYPE_EQUAL +#define PICK_TYPE_EQUAL (var, type) \ + __builtin_types_compatible_p(typeof(var), type) + +extern int __bad_func_type (void ); + +#define PICK_FUNCTION (type1, type2, func1, func2, arg0, ...) \ +do { \ + if (PICK_TYPE_EQUAL((arg0), type1)) \ + func1((type1)(arg0), ##__VA_ARGS__); \ + else if (PICK_TYPE_EQUAL((arg0), type2)) \ + func2((type2)(arg0), ##__VA_ARGS__); \ + else __bad_func_type(); \ +} while (0) + +#define PICK_FUNCTION_RET (type1, type2, func1, func2, arg0, ...) \ +({ \ + unsigned long __ret; \ + \ + if (PICK_TYPE_EQUAL((arg0), type1)) \ + __ret = func1((type1)(arg0), ##__VA_ARGS__); \ + else if (PICK_TYPE_EQUAL((arg0), type2)) \ + __ret = func2((type2)(arg0), ##__VA_ARGS__); \ + else __ret = __bad_func_type(); \ + \ + __ret; \ +}) + +#endif /* _LINUX_PICKOP_H */
include/linux/rt_lock.h +41 -88
175 lines not on this page · raw message
PATCH 2/8 spinlocks/rwlocks: use PICK_FUNCTION()
Reaplace old PICK_OP style macros with the new PICK_FUNCTION macro.
--- include/linux/sched.h | 13 - include/linux/spinlock.h | 345 ++++++++++++++--------------------------------- kernel/rtmutex.c | 2 lib/dec_and_lock.c | 2 4 files changed, 111 insertions(+), 251 deletions(-)
include/linux/sched.h +2 -11
@@ -2022,17 +2022,8 @@ extern int __cond_resched_raw_spinlock(rextern int __cond_resched_spinlock (spinlock_t *spinlock);#define cond_resched_lock (lock) \ -({ \ - int __ret; \ - \ - if (TYPE_EQUAL((lock), raw_spinlock_t)) \ - __ret = __cond_resched_raw_spinlock((raw_spinlock_t *)lock);\ - else if (TYPE_EQUAL(lock, spinlock_t)) \ - __ret = __cond_resched_spinlock((spinlock_t *)lock); \ - else __ret = __bad_spinlock_type(); \ - \ - __ret; \ -}) + PICK_SPIN_OP_RET(__cond_resched_raw_spinlock, __cond_resched_spinlock,\ + lock)extern int cond_resched_softirq (void );extern int cond_resched_softirq_context (void );
include/linux/spinlock.h +107 -238
470 lines not on this page · raw message
kernel/rtmutex.c +1 -1
@@ -857,7 +857,7 @@ int __lockfunc rt_spin_trylock_irqsave(s }EXPORT_SYMBOL (rt_spin_trylock_irqsave); -int _atomic_dec_and_spin_lock (atomic_t *atomic,spinlock_t *lock) +int _atomic_dec_and_spin_lock (spinlock_t *lock,atomic_t *atomic) {/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ if (atomic_add_unless (atomic,-1 ,1 ))
lib/dec_and_lock.c +1 -1
@@ -17,7 +17,7 @@* because the spin-lock and the decrement must be * "atomic". */ -int __atomic_dec_and_spin_lock (atomic_t *atomic,raw_spinlock_t *lock) +int __atomic_dec_and_spin_lock (raw_spinlock_t *lock,atomic_t *atomic) {#ifdef CONFIG_SMP /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
PATCH 3/8 seqlocks: use PICK_FUNCTION
In reply to Daniel WalkerReplace the old PICK_OP style macros with PICK_FUNCTION. Although, seqlocks has some alien code, which I also replaced as can be seen from the line count below.
--- include/linux/pickop.h | 4 include/linux/seqlock.h | 235 +++++++++++++++++++++++++++--------------------- 2 files changed, 135 insertions(+), 104 deletions(-)
include/linux/pickop.h +0 -4
@@ -1,10 +1,6 @@#ifndef _LINUX_PICKOP_H#define _LINUX_PICKOP_H -#undef TYPE_EQUAL -#define TYPE_EQUAL (var, type) \ - __builtin_types_compatible_p(typeof(var), type *) -#undef PICK_TYPE_EQUAL#define PICK_TYPE_EQUAL (var, type) \ __builtin_types_compatible_p(typeof(var), type)
include/linux/seqlock.h +135 -100
272 lines not on this page · raw message
PATCH 4/8 fork: desched_thread comment rework.
In reply to Daniel WalkerLines are too long..
--- kernel/fork.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/fork.c +4 -2
@@ -1787,8 +1787,10 @@ static int desched_thread(void * __bind_continue ;schedule (); -/* This must be called from time to time on ia64, and is a no-op on other archs. -* Used to be in cpu_idle(), but with the new -rt semantics it can't stay there. +/* +* This must be called from time to time on ia64, and is a +* no-op on other archs. Used to be in cpu_idle(), but with +* the new -rt semantics it can't stay there. */ check_pgt_cache ();
PATCH 5/8 latency tracing: use now() consistently
In reply to Daniel WalkerJust get_monotonic_cycles() switched to now() ..
--- kernel/latency_trace.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
kernel/latency_trace.c +9 -9
@@ -1751,7 +1751,7 @@ check_critical_timing(int cpu, struct cp* as long as possible: */ T0 = tr->preempt_timestamp; -T1 =get_monotonic_cycles (); +T1 =now (); delta =T1 -T0 ;local_save_flags (flags);
@@ -1765,7 +1765,7 @@ check_critical_timing(int cpu, struct cp* might change it (it can only get larger so the latency * is fair to be reported): */ -T2 =get_monotonic_cycles (); +T2 =now (); delta =T2 -T0 ;
@@ -1815,7 +1815,7 @@ check_critical_timing(int cpu, struct cpprintk (" => ended at timestamp %lu: " , t1);print_symbol ("<%s>\n" , tr->critical_end);dump_stack (); - t1 =cycles_to_usecs (get_monotonic_cycles ()); + t1 =cycles_to_usecs (now ());printk (" => dump-end timestamp %lu\n\n" , t1);#endif
@@ -1825,7 +1825,7 @@ check_critical_timing(int cpu, struct cp out: tr->critical_sequence = max_sequence; - tr->preempt_timestamp =get_monotonic_cycles (); + tr->preempt_timestamp =now (); tr->early_warning =0 ;reset_trace_idx (cpu, tr);_trace_cmdline (cpu, tr);
@@ -1874,7 +1874,7 @@ __start_critical_timing(unsigned long eiatomic_inc (&tr->disabled); tr->critical_sequence = max_sequence; - tr->preempt_timestamp =get_monotonic_cycles (); + tr->preempt_timestamp =now (); tr->critical_start = eip;reset_trace_idx (cpu, tr); tr->latency_type = latency_type;
@@ -2196,7 +2196,7 @@ check_wakeup_timing(struct cpu_trace *tr goto out;T0 = tr->preempt_timestamp; -T1 =get_monotonic_cycles (); +T1 =now ();/* * Any wraparound or time warp and we are out: */
@@ -2314,7 +2314,7 @@ void __trace_start_sched_wakeup(struct t// if (!atomic_read(&tr->disabled)) { atomic_inc (&tr->disabled); tr->critical_sequence = max_sequence; - tr->preempt_timestamp =get_monotonic_cycles (); + tr->preempt_timestamp =now (); tr->latency_type =WAKEUP_LATENCY ; tr->critical_start =CALLER_ADDR0 ;_trace_cmdline (raw_smp_processor_id (), tr);
@@ -2426,7 +2426,7 @@ long user_trace_start(void)atomic_inc (&tr->disabled); tr->critical_sequence = max_sequence; - tr->preempt_timestamp =get_monotonic_cycles (); + tr->preempt_timestamp =now (); tr->critical_start =CALLER_ADDR0 ;_trace_cmdline (cpu, tr);atomic_dec (&tr->disabled);
@@ -2486,7 +2486,7 @@ long user_trace_stop(void)unsigned long long tmp0;T0 = tr->preempt_timestamp; -T1 =get_monotonic_cycles (); +T1 =now (); tmp0 = preempt_max_latency;if (T1 <T0 )T0 =T1 ;
PATCH 6/8 preempt_max_latency in all modes
In reply to Daniel WalkerThis enables the /proc/preempt_max_latency facility for timing modes, even if event tracing is disabled. Wakeup latency was the only one that had this feature in the past.
--- kernel/sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sysctl.c +1 -1
@@ -392,7 +392,7 @@ static ctl_table kern_table[] = { .proc_handler = &proc_dointvec, },#endif -#if defined(CONFIG_WAKEUP_TIMING ) || defined(CONFIG_EVENT_TRACE ) +#if defined(CONFIG_CRITICAL_TIMING ) { .ctl_name = CTL_UNNUMBERED, .procname = "preempt_max_latency",
PATCH 7/8 latency hist: add resetting for all timing options
In reply to Daniel WalkerI dropped parts of the prior reset method, and added a file called "reset" into the /proc/latency_hist/ timing directories. It allows any of the timing options to get their histograms reset.
I also fixed a couple of oddities in the code. Instead of creating a file for all NR_CPUS , I just used num_possible_cpus() . I also drop a string which only hold "CPU" and just inserted it where it was used.
--- include/linux/latency_hist.h | 1 kernel/latency_hist.c | 119 ++++++++++++++++++++++++++++--------------- kernel/latency_trace.c | 13 ---- 3 files changed, 80 insertions(+), 53 deletions(-)
include/linux/latency_hist.h +0 -1
@@ -23,7 +23,6 @@ enum {#ifdef CONFIG_LATENCY_HIST extern void latency_hist (int latency_type,int cpu,unsigned long latency); -extern void latency_hist_reset (void );# define latency_hist_flag 1#else # define latency_hist (a,b,c) do { (void)(cpu); } while (0)
kernel/latency_hist.c +80 -39
180 lines not on this page · raw message
kernel/latency_trace.c +0 -13
@@ -2207,19 +2207,6 @@ check_wakeup_timing(struct cpu_trace *trif (!report_latency (delta)) goto out; -#ifdef CONFIG_WAKEUP_LATENCY_HIST -/* -* Was preempt_max_latency reset? -* If so, we reinitialize the latency histograms to keep them in sync. -* -* FIXME: Remove the poll and write our own procfs handler, so -* we can trigger on the write to preempt_max_latency -*/ -if (last_preempt_max_latency >0 && preempt_max_latency ==0 ) -latency_hist_reset (); - last_preempt_max_latency = preempt_max_latency; -#endif -____trace (smp_processor_id (),TRACE_FN , tr,CALLER_ADDR0 , parent_eip,0 ,0 ,0 , *flags);
PATCH 8/8 stop critical timing in idle.
In reply to Daniel Walkerwithout this the idle routine still gets traced.. This is done already for ACPI idle , but it should also be done for other idle routines.
--- arch/i386/kernel/process.c | 9 +++++++++ arch/x86_64/kernel/process.c | 10 ++++++++++ 2 files changed, 19 insertions(+)
arch/i386/kernel/process.c +9 -0
@@ -197,8 +197,17 @@ void cpu_idle(void)if (cpu_is_offline (cpu))play_dead (); +/* +* We have irqs disabled here, so stop latency tracing +* at this point and restart it after we return: +*/ +stop_critical_timing (); +__get_cpu_var (irq_stat).idle_timestamp = jiffies;idle (); + +touch_critical_timing (); + }local_irq_disable ();trace_preempt_exit_idle ();
arch/x86_64/kernel/process.c +10 -0
@@ -223,8 +223,18 @@ void cpu_idle (void)* Otherwise, idle callbacks can misfire. */ local_irq_disable (); + +/* +* We have irqs disabled here, so stop latency tracing +* at this point and restart it after we return: +*/ +stop_critical_timing (); +enter_idle ();idle (); + +touch_critical_timing (); +/* In many cases the interrupt that ended idle has already called exit_idle. But some idle loops can be woken up without interrupt. */
Quoted 7 lines · Daniel Walker
PICK_FUNCTION()is similar to the otherPICK_OPstyle macros, and was created to replace them all. I used variable argument macros to handle PICK_FUNC_2ARG/PICK_FUNC_1ARG. Otherwise the marcos are similar to the original macros used for semaphores. The entire system is used to do a compile time switch between two different locking APIs. For example, real spinlocks (raw_spinlock_t) and mutexes (or sleeping spinlocks).
Quoted 7 lines
This new macro replaces all the duplication from lock type to lock type. The result of this patch, and the next two, is a fairly nice simplification, and consolidation. Although the seqlock changes are larger than the originals I think over all the patchset is worth while.
Incorporated peterz's suggestion to not require
TYPE_EQUAL()to only use pointers.
How come this is cc'ed to lkml? Is it something that is relevant to the mainline kernel... or?
Signature · 1 line
SUSE Labs, Novell Inc.
Quoted 13 lines · Nick Piggin
Quoted 12 lines · Daniel Walker
PICK_FUNCTION()is similar to the otherPICK_OPstyle macros, and was created to replace them all. I used variable argument macros to handle PICK_FUNC_2ARG/PICK_FUNC_1ARG. Otherwise the marcos are similar to the original macros used for semaphores. The entire system is used to do a compile time switch between two different locking APIs. For example, real spinlocks (raw_spinlock_t) and mutexes (or sleeping spinlocks).This new macro replaces all the duplication from lock type to lock type. The result of this patch, and the next two, is a fairly nice simplification, and consolidation. Although the seqlock changes are larger than the originals I think over all the patchset is worth while.
Quoted 5 lines
Quoted 2 lines
Incorporated peterz's suggestion to not require
TYPE_EQUAL()to only use pointers.How come this is cc'ed to lkml? Is it something that is relevant to the mainline kernel... or?
The real time changes are usually developed on lkml , that's how it's been in the past. I personally like CC'ing lkml since real time can sometimes touch lots of different subsystems .. So it good to have a diverse set of people reviewing ..
Daniel