optimise root stalling
The first one is a real patch, introducing an optimisation of the stall/unstall-root path of I-pipe. It removes any caring for the pipeline head case of the root doamin from ipipe_root_stall (something that was lacking for test_and_stall_root anyway), and it pushes under UP the IRQ disabling into the less likely __ipipe_sync_pipeline path in ipipe_unstall_root.
Those two changes together gave me about 5% better Linux performance under RT-load on a low-end Pentium.
A further idea of mine was to inline light-weight parts of the __ipipe_*_root API on UP (no SMP at hand to judge on it as well). That's what the second patch, err, hack is for. It gives another 5% Linux speedup on x86, but it unfortunately contains some tricky dependency issues. Of course, it also slightly increases the code size again.
Looking at other linux/ipipe.h duplications, e.g. in linux/preempt.h, it might be worth considering to derive a basic header that has no further dependencies and can be included anywhere. Based on such header the proposed optimisation could be built up more cleanly.
Jan
--- kernel/ipipe/core.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
kernel/ipipe/core.c +11 -9
@@ -134,16 +134,8 @@ void __ipipe_stall_root(void)unsigned long flags;ipipe_get_cpu (flags);/* Care for migration. */ -set_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[cpuid].status); - -#ifdef CONFIG_SMP -if (!__ipipe_pipeline_head_p (ipipe_root_domain)) -ipipe_put_cpu (flags); -#else /* CONFIG_SMP */ -if (__ipipe_pipeline_head_p (ipipe_root_domain)) -local_irq_disable_hw (); -#endif /* CONFIG_SMP */ +ipipe_put_cpu (flags); }void __ipipe_cleanup_domain (struct ipipe_domain *ipd)
@@ -166,6 +158,7 @@ void __ipipe_unstall_root(void) { ipipe_declare_cpuid; +#ifdef CONFIG_SMP local_irq_disable_hw ();ipipe_load_cpuid ();
@@ -176,6 +169,15 @@ void __ipipe_unstall_root(void)__ipipe_sync_pipeline (IPIPE_IRQMASK_ANY );local_irq_enable_hw (); +#else /* !CONFIG_SMP */ +__clear_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[cpuid].status); + +if (unlikely (ipipe_root_domain->cpudata[cpuid].irq_pending_hi !=0 )) { +local_irq_disable_hw (); +__ipipe_sync_pipeline (IPIPE_IRQMASK_ANY ); +local_irq_enable_hw (); + } +#endif /* CONFIG_SMP */ }unsigned long __ipipe_test_root (void )
--- arch/i386/kernel/entry.S | 2 - include/asm-i386/system.h | 51 +++++++++++++++++++++++++++++++++++++++++++--- include/linux/ipipe.h | 34 +++++++++++++++++++++++------- kernel/ipipe/core.c | 26 +++++++++++++---------- 4 files changed, 90 insertions(+), 23 deletions(-)
include/linux/ipipe.h +26 -8
@@ -356,18 +356,12 @@ void __ipipe_remove_domain_proc(struct ivoid __ipipe_flush_printk (unsigned irq,void *cookie); -void __ipipe_stall_root (void ); - -void __ipipe_unstall_root (void ); - -unsigned long __ipipe_test_root (void ); - -unsigned long __ipipe_test_and_stall_root (void ); - void fastcall __ipipe_walk_pipeline(struct list_head *pos, int cpuid); void fastcall __ipipe_restore_root(unsigned long x); +void __ipipe_unstall_root (void ); + int fastcall __ipipe_schedule_irq(unsigned irq, struct list_head *head); int fastcall __ipipe_dispatch_event(unsigned event, void *data);
@@ -403,6 +397,30 @@ cpumask_t __ipipe_set_irq_affinity(unsig int fastcall __ipipe_send_ipi(unsigned ipi,cpumask_t cpumask); +void __ipipe_stall_root (void ); + +unsigned long __ipipe_test_root (void ); + +unsigned long __ipipe_test_and_stall_root (void ); + +#else /* !CONFIG_SMP */ + +static inline void __ipipe_stall_root (void ) +{ +set_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[0 ].status); +} + +static inline unsigned long __ipipe_test_root (void ) +{ +return test_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[0 ].status); +} + +static inline unsigned long __ipipe_test_and_stall_root (void ) +{ +return test_and_set_bit (IPIPE_STALL_FLAG , + &ipipe_root_domain->cpudata[0 ].status); +} +#endif /* CONFIG_SMP */ /* Called with hw interrupts off. */
include/asm-i386/system.h +48 -3
70 lines not on this page · raw message
arch/i386/kernel/entry.S +1 -1
@@ -77,7 +77,7 @@ NT_MASK = 0x00004000 VM_MASK = 0x00020000 #ifdef CONFIG_IPIPE -#define CLI call __ipipe_stall_root ; sti +#define CLI btsl $0,ipipe_root+0x8 #define STI call __ipipe_unstall_root #define STI_COND_HW sti #define EMULATE_ROOT_IRET(bypass) \
kernel/ipipe/core.c +15 -11
@@ -128,16 +128,6 @@ void __ipipe_init_stage(struct ipipe_dom#endif /* CONFIG_SMP */ } -void __ipipe_stall_root (void ) -{ - ipipe_declare_cpuid; -unsigned long flags; - -ipipe_get_cpu (flags);/* Care for migration. */ -set_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[cpuid].status); -ipipe_put_cpu (flags); -} -void __ipipe_cleanup_domain (struct ipipe_domain *ipd) {ipipe_unstall_pipeline_from (ipd);
@@ -180,6 +170,17 @@ void __ipipe_unstall_root(void)#endif /* CONFIG_SMP */ } +#ifdef CONFIG_SMP +void __ipipe_stall_root (void ) +{ + ipipe_declare_cpuid; +unsigned long flags; + +ipipe_get_cpu (flags);/* Care for migration. */ +set_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[cpuid].status); +ipipe_put_cpu (flags); +} +unsigned long __ipipe_test_root (void ) {unsigned long flags, x;
@@ -204,6 +205,7 @@ unsigned long __ipipe_test_and_stall_rooreturn x; } +#endif /* CONFIG_SMP */ void fastcall __ipipe_restore_root(unsigned long x) {
@@ -1047,10 +1049,12 @@ EXPORT_SYMBOL(ipipe_test_and_unstall_pipEXPORT_SYMBOL (ipipe_unstall_pipeline_head);EXPORT_SYMBOL (__ipipe_restore_pipeline_head);EXPORT_SYMBOL (__ipipe_unstall_root); -EXPORT_SYMBOL (__ipipe_stall_root);EXPORT_SYMBOL (__ipipe_restore_root); +#ifdef CONFIG_CMP +EXPORT_SYMBOL (__ipipe_stall_root);EXPORT_SYMBOL (__ipipe_test_and_stall_root);EXPORT_SYMBOL (__ipipe_test_root); +#endif /* CONFIG_SMP */ EXPORT_SYMBOL (__ipipe_dispatch_event);EXPORT_SYMBOL (__ipipe_dispatch_wired);EXPORT_SYMBOL (__ipipe_sync_stage);
Quoted 3 lines · Jan Kiszka
...
A further idea of mine was to inline light-weight parts of the __ipipe_*_root API on UP (no SMP at hand to judge on it as well).
BTW: I haven't looked at any detail yet, but would PER_CPU here and there (e.g. for ipipe_percpu_domain) buy us something on SMP (2.6)?
Jan
Quoted 8 lines · Jan Kiszka
Quoted 3 lines · Jan Kiszka
...
A further idea of mine was to inline light-weight parts of the __ipipe_*_root API on UP (no SMP at hand to judge on it as well).BTW: I haven't looked at any detail yet, but would
PER_CPUhere and there (e.g. foripipe_percpu_domain) buy us something on SMP (2.6)?
At the very least, we don't need to share any cacheline for ipipe_percpu_domain[] which is purely a per-CPU variable.
Quoted 6 lines
Jan
_______________________________________________
Adeos-main mailing list
[email protected]
https://mail.gna.org/listinfo/adeos-main
Signature · 1 line
Philippe.
On Mon, 2006-09-25 at 09:35 +0200, Jan Kiszka wrote:
This one won't work. We need to forcibly re-enable the hw IRQs upon root unstall requests, regardless of the fact that interrupts are pending in the log; some code rely on this. E.g. Adeos/ppc over 2.4 would remain stuck in the delay calibration routine, but there are other more tricky places where this would bite too.
Quoted 25 lines
kernel/ipipe/core.c +10
-0@@ -166,6 +158,7 @@ void __ipipe_unstall_root(void) { ipipe_declare_cpuid; +#ifdef CONFIG_SMP local_irq_disable_hw ();ipipe_load_cpuid ();@@ -176,6 +169,15 @@ void __ipipe_unstall_root(void)__ipipe_sync_pipeline (IPIPE_IRQMASK_ANY );local_irq_enable_hw (); +#else /* !CONFIG_SMP */ +__clear_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[cpuid].status); + +if (unlikely (ipipe_root_domain->cpudata[cpuid].irq_pending_hi !=0 )) { +local_irq_disable_hw (); +__ipipe_sync_pipeline (IPIPE_IRQMASK_ANY ); +local_irq_enable_hw (); + } +#endif /* CONFIG_SMP */ }
Signature · 1 line
Philippe.
Quoted 7 lines · Philippe Gerum
On Mon, 2006-09-25 at 09:35 +0200, Jan Kiszka wrote:
This one won't work. We need to forcibly re-enable the hw IRQs upon root unstall requests, regardless of the fact that interrupts are pending in the log; some code rely on this. E.g. Adeos/ppc over 2.4 would remain stuck in the delay calibration routine, but there are other more tricky places where this would bite too.
But this would be ok?
#else /* !CONFIG_SMP */
__clear_bit(IPIPE_STALL_FLAG,
&ipipe_root_domain->cpudata[cpuid].status);
if (unlikely(ipipe_root_domain->cpudata[cpuid].irq_pending_hi !=
0)) {
local_irq_disable_hw();
__ipipe_sync_pipeline(IPIPE_IRQMASK_ANY);
}
local_irq_enable_hw();#endif /* CONFIG_SMP */
So we can still save one disable IRQ in the fastpath.
Jan
Quoted 21 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
On Mon, 2006-09-25 at 09:35 +0200, Jan Kiszka wrote:
This one won't work. We need to forcibly re-enable the hw IRQs upon root unstall requests, regardless of the fact that interrupts are pending in the log; some code rely on this. E.g. Adeos/ppc over 2.4 would remain stuck in the delay calibration routine, but there are other more tricky places where this would bite too.
But this would be ok?
#else /* !CONFIG_SMP */ __clear_bit(IPIPE_STALL_FLAG, &ipipe_root_domain->cpudata[cpuid].status); if (unlikely(ipipe_root_domain->cpudata[cpuid].irq_pending_hi != 0)) { local_irq_disable_hw(); __ipipe_sync_pipeline(IPIPE_IRQMASK_ANY); } local_irq_enable_hw();
Quoted 4 lines
#endif /*
CONFIG_SMP*/So we can still save one disable IRQ in the fastpath.
But in such a case, you would have to use clear_bit() to keep atomicity.
Quoted 2 lines
Jan
Signature · 1 line
Philippe.
Quoted 23 lines · Philippe Gerum
Quoted 22 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
On Mon, 2006-09-25 at 09:35 +0200, Jan Kiszka wrote:
This one won't work. We need to forcibly re-enable the hw IRQs upon root unstall requests, regardless of the fact that interrupts are pending in the log; some code rely on this. E.g. Adeos/ppc over 2.4 would remain stuck in the delay calibration routine, but there are other more tricky places where this would bite too.
But this would be ok?
#else /* !CONFIG_SMP */ __clear_bit(IPIPE_STALL_FLAG, &ipipe_root_domain->cpudata[cpuid].status); if (unlikely(ipipe_root_domain->cpudata[cpuid].irq_pending_hi != 0)) { local_irq_disable_hw(); __ipipe_sync_pipeline(IPIPE_IRQMASK_ANY); } local_irq_enable_hw();#endif /*
CONFIG_SMP*/
Quoted 4 lines
Quoted 2 lines
So we can still save one disable IRQ in the fastpath.
But in such a case, you would have to use
clear_bit()to keep atomicity.
This is for UP, not SMP.
Jan
Quoted 24 lines · Jan Kiszka
Quoted 23 lines · Philippe Gerum
Quoted 22 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
On Mon, 2006-09-25 at 09:35 +0200, Jan Kiszka wrote:
This one won't work. We need to forcibly re-enable the hw IRQs upon root unstall requests, regardless of the fact that interrupts are pending in the log; some code rely on this. E.g. Adeos/ppc over 2.4 would remain stuck in the delay calibration routine, but there are other more tricky places where this would bite too.
But this would be ok?
#else /* !CONFIG_SMP */ __clear_bit(IPIPE_STALL_FLAG, &ipipe_root_domain->cpudata[cpuid].status); if (unlikely(ipipe_root_domain->cpudata[cpuid].irq_pending_hi != 0)) { local_irq_disable_hw(); __ipipe_sync_pipeline(IPIPE_IRQMASK_ANY); } local_irq_enable_hw();#endif /*
CONFIG_SMP*/
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
So we can still save one disable IRQ in the fastpath.
But in such a case, you would have to use
clear_bit()to keep atomicity.This is for UP, not SMP.
This is not a UP vs SMP issue, the stall bit is strictly CPU local anyway. The issue is that some archs do _not_ have intrinsically atomic bitops; they need to emulate them by masking interrupts around the bit setting operation. Using __clear_bit() in this context would make this code preemptible by an interrupt in the middle of the bitop. Disabling hw IRQs on entry allows us to use non-atomic bitops.
Quoted 6 lines
Jan
_______________________________________________
Adeos-main mailing list
[email protected]
https://mail.gna.org/listinfo/adeos-main
Signature · 1 line
Philippe.
Quoted 31 lines · Philippe Gerum
Quoted 24 lines · Jan Kiszka
Quoted 23 lines · Philippe Gerum
Quoted 22 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
On Mon, 2006-09-25 at 09:35 +0200, Jan Kiszka wrote:
This one won't work. We need to forcibly re-enable the hw IRQs upon root unstall requests, regardless of the fact that interrupts are pending in the log; some code rely on this. E.g. Adeos/ppc over 2.4 would remain stuck in the delay calibration routine, but there are other more tricky places where this would bite too.
But this would be ok?
#else /* !CONFIG_SMP */ __clear_bit(IPIPE_STALL_FLAG, &ipipe_root_domain->cpudata[cpuid].status); if (unlikely(ipipe_root_domain->cpudata[cpuid].irq_pending_hi != 0)) { local_irq_disable_hw(); __ipipe_sync_pipeline(IPIPE_IRQMASK_ANY); } local_irq_enable_hw();#endif /*
CONFIG_SMP*/Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
So we can still save one disable IRQ in the fastpath.
But in such a case, you would have to use
clear_bit()to keep atomicity.This is for UP, not SMP.
Quoted 6 lines
This is not a UP vs SMP issue, the stall bit is strictly CPU local anyway. The issue is that some archs do _not_ have intrinsically atomic bitops; they need to emulate them by masking interrupts around the bit setting operation. Using
__clear_bit()in this context would make this code preemptible by an interrupt in the middle of the bitop. Disabling hw IRQs on entry allows us to use non-atomic bitops.
Yeah, I meanwhile realised my x86-restricted view as well. :)
Does it still make sense then to optimise like I proposed?
Quoted 2 lines · Jan Kiszka
Does it still make sense then to optimise like I proposed?
If you did measure a 5% improvement on low-end x86 hw, then I guess so. Moving __ipipe_unstall_root to the arch-dependent section would do, so that we could use the most efficient implementation on a case by case basis.
Signature · 1 line
Philippe.
Quoted 9 lines · Philippe Gerum
Quoted 2 lines · Jan Kiszka
Does it still make sense then to optimise like I proposed?
If you did measure a 5% improvement on low-end x86 hw, then I guess so. Moving
__ipipe_unstall_rootto the arch-dependent section would do, so that we could use the most efficient implementation on a case by case basis.
I'm not seeing 5% alone due to this change, it's a piece in the puzzle. I just benchmarked the fixed version below against the unmodified one. There is an improvement of the average hackbench runtime, though it's minimal. The wrong variant I posted first doesn't show noticeable benefit compared to the correct one. I guess the "critical" part is switching IRQs off when they were on, and not just enabling them when they weren't disabled.
So I think the one below could be applied for now, but per-arch optimisations may remain on the to-do list for the future if we discover archs that could do better with hand-optimised code here. The x86 assembly looks quite good already.
kernel/ipipe/core.c +9 -0
@@ -166,6 +158,7 @@ void __ipipe_unstall_root(void) { ipipe_declare_cpuid; +#ifdef CONFIG_SMP local_irq_disable_hw ();ipipe_load_cpuid ();
@@ -174,6 +167,14 @@ void __ipipe_unstall_root(void)if (ipipe_root_domain->cpudata[cpuid].irq_pending_hi !=0 )__ipipe_sync_pipeline (IPIPE_IRQMASK_ANY ); +#else /* !CONFIG_SMP */ +clear_bit (IPIPE_STALL_FLAG , &ipipe_root_domain->cpudata[cpuid].status); + +if (unlikely (ipipe_root_domain->cpudata[cpuid].irq_pending_hi !=0 )) { +local_irq_disable_hw (); +__ipipe_sync_pipeline (IPIPE_IRQMASK_ANY ); + } +#endif /* CONFIG_SMP */ local_irq_enable_hw (); }