type-based spinlock op selection
Subsystems (4)
RFC 1/1 type-based spinlock op selection
Hi,
reading through the I-pipe patch I noticed that there are quite a few spin_lock->spin_lock_hw and similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.
The required patch for Xenomai is attached as well.
Jan
--- arch/i386/kernel/apic.c | 4 - arch/i386/kernel/i8253.c | 6 - arch/i386/kernel/i8259.c | 24 +++---- arch/i386/kernel/io_apic.c | 100 +++++++++++++++---------------- arch/i386/kernel/ipipe.c | 10 +-- arch/i386/kernel/time.c | 4 - arch/i386/mach-visws/visws_apic.c | 24 +++---- arch/i386/mach-voyager/voyager_basic.c | 8 +- drivers/ide/legacy/hd.c | 4 - drivers/input/gameport/gameport.c | 4 - drivers/input/joystick/analog.c | 4 - drivers/pci/htirq.c | 10 +-- include/asm-i386/i8253.h | 2 include/asm-i386/i8259.h | 2 include/asm-i386/mach-default/do_timer.h | 4 - include/linux/ipipe.h | 40 ------------ include/linux/spinlock.h | 88 +++++++++++++++++++++++---- include/linux/spinlock_types.h | 12 +++ kernel/ipipe/core.c | 20 +++--- kernel/ipipe/tracer.c | 14 ++-- kernel/printk.c | 10 +-- 21 files changed, 216 insertions(+), 178 deletions(-)
arch/i386/kernel/apic.c +2 -2
@@ -929,13 +929,13 @@ static unsigned int __devinit get_8254_tunsigned int count; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x00 ,PIT_MODE ); count =inb_p (PIT_CH0 ); count |=inb_p (PIT_CH0 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags);return count; }
arch/i386/kernel/i8253.c +3 -3
@@ -16,20 +16,20 @@#include "io_ports.h" -DEFINE_SPINLOCK (i8253_lock); +IPIPE_DEFINE_SPINLOCK (i8253_lock);EXPORT_SYMBOL (i8253_lock);void setup_pit_timer (void ) {unsigned long flags; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ udelay (10 );outb_p (LATCH &0xff ,PIT_CH0 );/* LSB */ udelay (10 );outb (LATCH >>8 ,PIT_CH0 );/* MSB */ -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags); }/*
arch/i386/kernel/i8259.c +12 -12
@@ -35,7 +35,7 @@*/ static int i8259A_auto_eoi; -DEFINE_SPINLOCK (i8259A_lock); +IPIPE_DEFINE_SPINLOCK (i8259A_lock);static void mask_and_ack_8259A (unsigned int );#ifdef CONFIG_IPIPE
@@ -87,14 +87,14 @@ void disable_8259A_irq(unsigned int irq)unsigned int mask =1 << irq;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);ipipe_irq_lock (irq); cached_irq_mask |= mask;if (irq &8 )outb (cached_slave_mask,PIC_SLAVE_IMR );else outb (cached_master_mask,PIC_MASTER_IMR ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); }void enable_8259A_irq (unsigned int irq)
@@ -102,7 +102,7 @@ void enable_8259A_irq(unsigned int irq)unsigned int mask = (1 << irq);unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);if (cached_irq_mask & mask) { cached_irq_mask &= ~mask;if (irq &8 )
@@ -111,7 +111,7 @@ void enable_8259A_irq(unsigned int irq)outb (cached_master_mask,PIC_MASTER_IMR );ipipe_irq_unlock (irq); } -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); }int i8259A_irq_pending (unsigned int irq)
@@ -120,12 +120,12 @@ int i8259A_irq_pending(unsigned int irq)unsigned long flags;int ret; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);if (irq <8 ) ret =inb (PIC_MASTER_CMD ) & mask;else ret =inb (PIC_SLAVE_CMD ) & (mask >>8 ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);return ret; }
@@ -173,7 +173,7 @@ static void mask_and_ack_8259A(unsignedunsigned int irqmask =1 << irq;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);/* * Lightweight spurious IRQ detection. We do not want * to overdo spurious IRQ handling - it's usually a sign
@@ -196,7 +196,7 @@ static void mask_and_ack_8259A(unsigned/* Fast timer ack -- don't mask (unless supposedly spurious) */ outb (0x20 ,PIC_MASTER_CMD ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); return; }#endif /* CONFIG_IPIPE */
@@ -213,7 +213,7 @@ handle_real_irq:outb (cached_master_mask,PIC_MASTER_IMR );outb (0x60 +irq,PIC_MASTER_CMD );/* 'Specific EOI to master */ } -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);return ; spurious_8259A_irq:
@@ -316,7 +316,7 @@ void init_8259A(int auto_eoi) i8259A_auto_eoi = auto_eoi; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);outb (0xff ,PIC_MASTER_IMR );/* mask all of 8259A-1 */ outb (0xff ,PIC_SLAVE_IMR );/* mask all of 8259A-2 */
@@ -350,7 +350,7 @@ void init_8259A(int auto_eoi)outb (cached_master_mask,PIC_MASTER_IMR );/* restore master IRQ mask */ outb (cached_slave_mask,PIC_SLAVE_IMR );/* restore slave IRQ mask */ -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); }/*
arch/i386/kernel/io_apic.c +50 -50
307 lines not on this page · raw message
arch/i386/kernel/time.c +2 -2
@@ -181,11 +181,11 @@ irqreturn_t timer_interrupt(int irq, voi* on an 82489DX-based system. */ unsigned long flags; -spin_lock_irqsave_hw_cond (&i8259A_lock,flags); +spin_lock_irqsave_cond (&i8259A_lock,flags);outb (0x0c ,PIC_MASTER_OCW3 );/* Ack the IRQ; AEOI will end it automatically. */ inb (PIC_MASTER_POLL ); - spin_unlock_irqrestore_hw_cond(&i8259A_lock,flags); + spin_unlock_irqrestore_cond(&i8259A_lock,flags); }#endif
include/asm-i386/mach-default/do_timer.h +2 -2
@@ -56,13 +56,13 @@ static inline int do_timer_overflow(intint i;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);/* * This is tricky when I/O APICs are used; * see do_timer_interrupt(). */ i =inb (0x20 ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);/* assumption about timer being IRQ0 */ if (i &0x01 ) {
include/linux/ipipe.h +0 -40
@@ -229,9 +229,6 @@ do { \ } \ } while(0) -#define spin_lock_hw (x) __raw_spin_lock(&(x)->raw_lock) -#define spin_trylock_hw (x) __raw_spin_trylock(&(x)->raw_lock) -#define spin_unlock_hw (x) __raw_spin_unlock(&(x)->raw_lock)#if defined(CONFIG_SMP ) || defined(CONFIG_DEBUG_SPINLOCK )#define write_lock_hw (x) __raw_write_lock(&(x)->raw_lock)#define write_trylock_hw (x) __raw_write_trylock(&(x)->raw_lock)
@@ -248,35 +245,9 @@ do { \#define read_unlock_hw (lock) do { (void)(lock); } while (0)#endif /* CONFIG_SMP || CONFIG_DEBUG_SPINLOCK */ -typedef spinlock_t ipipe_spinlock_t ;typedef rwlock_t ipipe_rwlock_t ; -#define IPIPE_SPIN_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED#define IPIPE_RW_LOCK_UNLOCKED RW_LOCK_UNLOCKED -#define spin_lock_irqsave_hw (x,flags) \ -do { \ - local_irq_save_hw(flags); \ - spin_lock_hw(x); \ -} while (0) - -#define spin_unlock_irqrestore_hw (x,flags) \ -do { \ - spin_unlock_hw(x); \ - local_irq_restore_hw(flags); \ -} while (0) - -#define spin_lock_irq_hw (x) \ -do { \ - local_irq_disable_hw(); \ - spin_lock_hw(x); \ -} while (0) - -#define spin_unlock_irq_hw (x) \ -do { \ - spin_unlock_hw(x); \ - local_irq_enable_hw(); \ -} while (0) -#define read_lock_irqsave_hw (lock, flags) \ do { \ local_irq_save_hw(flags); \
@@ -688,8 +659,6 @@ void fastcall *ipipe_get_ptd(int key);local_irq_disable_hw (); \ } while(0) -#define spin_lock_irqsave_hw_cond (lock,flags) spin_lock_irqsave_hw(lock,flags) -#define spin_unlock_irqrestore_hw_cond (lock,flags) spin_unlock_irqrestore_hw(lock,flags)#define smp_processor_id_hw () ipipe_processor_id()#define ipipe_irq_lock (irq) \
@@ -720,19 +689,10 @@ void fastcall *ipipe_get_ptd(int key);#define ipipe_trap_notify (t,r) 0#define ipipe_init_proc () do { } while(0) -#define spin_lock_hw (lock) spin_lock(lock) -#define spin_unlock_hw (lock) spin_unlock(lock) -#define spin_lock_irq_hw (lock) spin_lock_irq(lock) -#define spin_unlock_irq_hw (lock) spin_unlock_irq(lock) -#define spin_lock_irqsave_hw (lock,flags) spin_lock_irqsave(lock, flags) -#define spin_unlock_irqrestore_hw (lock,flags) spin_unlock_irqrestore(lock, flags) -#define local_irq_enable_hw_cond () do { } while(0)#define local_irq_disable_hw_cond () do { } while(0)#define local_irq_save_hw_cond (flags) do { (void)(flags); } while(0)#define local_irq_restore_hw_cond (flags) do { } while(0) -#define spin_lock_irqsave_hw_cond (lock,flags) do { (void)(flags); spin_lock(lock); } while(0) -#define spin_unlock_irqrestore_hw_cond (lock,flags) spin_unlock(lock)#define smp_processor_id_hw () smp_processor_id()#define ipipe_irq_lock (irq) do { } while(0)
include/linux/spinlock.h +77 -11
135 lines not on this page · raw message
include/linux/spinlock_types.h +12 -0
@@ -31,6 +31,10 @@ typedef struct {#endif } spinlock_t; +typedef struct { +raw_spinlock_t __raw_lock; +}ipipe_spinlock_t ; +#define SPINLOCK_MAGIC 0xdead4ead typedef struct {
@@ -86,9 +90,17 @@ typedef struct {#endif #define SPIN_LOCK_UNLOCKED __SPIN_LOCK_UNLOCKED(old_style_spin_init) +#define IPIPE_SPIN_LOCK_UNLOCKED \ + (ipipe_spinlock_t) { .__raw_lock = __RAW_SPIN_LOCK_UNLOCKED }#define RW_LOCK_UNLOCKED __RW_LOCK_UNLOCKED(old_style_rw_init)#define DEFINE_SPINLOCK (x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)#define DEFINE_RWLOCK (x) rwlock_t x = __RW_LOCK_UNLOCKED(x) +#ifdef CONFIG_IPIPE +#define IPIPE_DEFINE_SPINLOCK (x) ipipe_spinlock_t x = IPIPE_SPIN_LOCK_UNLOCKED +#else +#define IPIPE_DEFINE_SPINLOCK (x) DEFINE_SPINLOCK(x) +#endif +#endif /* __LINUX_SPINLOCK_TYPES_H */
arch/i386/mach-visws/visws_apic.c +12 -12
@@ -29,7 +29,7 @@#include "irq_vectors.h" -static DEFINE_SPINLOCK (cobalt_lock); +static IPIPE_DEFINE_SPINLOCK (cobalt_lock);/* * Set the given Cobalt APIC Redirection Table entry to point
@@ -94,11 +94,11 @@ static unsigned int startup_cobalt_irq(u {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);if ((irq_desc[irq].status & (IRQ_DISABLED |IRQ_INPROGRESS |IRQ_WAITING ))) irq_desc[irq].status &= ~(IRQ_DISABLED |IRQ_INPROGRESS |IRQ_WAITING );enable_cobalt_irq (irq); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags);return 0 ; }
@@ -106,20 +106,20 @@ static void ack_cobalt_irq(unsigned int {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);disable_cobalt_irq (irq);apic_write (APIC_EOI ,APIC_EIO_ACK ); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags); }static void end_cobalt_irq (unsigned int irq) {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);if (!(irq_desc[irq].status & (IRQ_DISABLED |IRQ_INPROGRESS )))enable_cobalt_irq (irq); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags); }#ifdef CONFIG_IPIPE
@@ -174,9 +174,9 @@ static void end_piix4_master_irq(unsigne {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);enable_cobalt_irq (irq); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags); }static struct irq_chip piix4_master_irq_type = {
@@ -216,7 +216,7 @@ static irqreturn_t piix4_master_intr(intirq_desc_t *desc;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);/* Find out what's interrupting in the PIIX4 master 8259 */ outb (0x0c ,0x20 );/* OCW3 Poll command */
@@ -253,7 +253,7 @@ static irqreturn_t piix4_master_intr(intoutb (0x60 + realirq,0x20 ); } -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); desc = irq_desc + realirq;
@@ -271,7 +271,7 @@ static irqreturn_t piix4_master_intr(intreturn IRQ_HANDLED ; out_unlock: -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);return IRQ_NONE ; }
arch/i386/mach-voyager/voyager_basic.c +4 -4
@@ -185,20 +185,20 @@ voyager_timer_interrupt(void)* pointy. */ __u16 val; -spin_lock_irqsave_hw (&i8253_lock); +spin_lock_irqsave (&i8253_lock);outb_p (0x00 ,0x43 ); val =inb_p (0x40 ); val |=inb (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock); +spin_unlock_irqrestore (&i8253_lock);if (val >LATCH ) {printk ("\nVOYAGER: countdown timer value too high (%d), resetting\n\n" , val); -spin_lock_irqsave_hw (&i8253_lock); +spin_lock_irqsave (&i8253_lock);outb (0x34 ,0x43 );outb_p (LATCH &0xff ,0x40 );/* LSB */ outb (LATCH >>8 ,0x40 );/* MSB */ -spin_unlock_irqrestore_hw (&i8253_lock); +spin_unlock_irqrestore (&i8253_lock); } }#ifdef CONFIG_SMP
drivers/ide/legacy/hd.c +2 -2
@@ -166,12 +166,12 @@ unsigned long read_timer(void)unsigned long t, flags;int i; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags); t = jiffies *11932 ;outb_p (0 ,0x43 ); i =inb_p (0x40 ); i |=inb (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags); return(t - i); }#endif
drivers/input/gameport/gameport.c +2 -2
@@ -71,11 +71,11 @@ static unsigned int get_time_pit(void)unsigned long flags;unsigned int count; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x00 ,0x43 ); count =inb_p (0x40 ); count |=inb_p (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags);return count; }
drivers/input/joystick/analog.c +2 -2
@@ -151,11 +151,11 @@ static unsigned int get_time_pit(void)unsigned long flags;unsigned int count; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x00 ,0x43 ); count =inb_p (0x40 ); count |=inb_p (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags);return count; }
drivers/pci/htirq.c +5 -5
@@ -21,7 +21,7 @@* With multiple simultaneous hypertransport irq devices it might pay * to make this more fine grained. But start with simple, stupid, and correct. */ -static DEFINE_SPINLOCK (ht_irq_lock); +static IPIPE_DEFINE_SPINLOCK (ht_irq_lock);struct ht_irq_cfg {struct pci_dev *dev;
@@ -37,7 +37,7 @@ void write_ht_irq_msg(unsigned int irq, {struct ht_irq_cfg *cfg =get_irq_data (irq);unsigned long flags; -spin_lock_irqsave_hw (&ht_irq_lock, flags); +spin_lock_irqsave (&ht_irq_lock, flags);if (cfg->msg.address_lo != msg->address_lo) {pci_write_config_byte (cfg->dev, cfg->pos +2 , cfg->idx);pci_write_config_dword (cfg->dev, cfg->pos +4 , msg->address_lo);
@@ -48,7 +48,7 @@ void write_ht_irq_msg(unsigned int irq, }if (cfg->update) cfg->update (cfg->dev, irq, msg); -spin_unlock_irqrestore_hw (&ht_irq_lock, flags); +spin_unlock_irqrestore (&ht_irq_lock, flags); cfg->msg = *msg; }
@@ -111,10 +111,10 @@ int __ht_create_irq(struct pci_dev *dev,return -EINVAL ;/* Verify the idx I want to use is in range */ -spin_lock_irqsave_hw (&ht_irq_lock, flags); +spin_lock_irqsave (&ht_irq_lock, flags);pci_write_config_byte (dev, pos +2 ,1 );pci_read_config_dword (dev, pos +4 , &data); -spin_unlock_irqrestore_hw (&ht_irq_lock, flags); +spin_unlock_irqrestore (&ht_irq_lock, flags); max_irq = (data >>16 ) &0xff ;if ( idx > max_irq)
include/asm-i386/i8253.h +1 -1
@@ -1,6 +1,6 @@#ifndef __ASM_I8253_H__#define __ASM_I8253_H__ -extern spinlock_t i8253_lock; +extern ipipe_spinlock_t i8253_lock;#endif /* __ASM_I8253_H__ */
include/asm-i386/i8259.h +1 -1
@@ -7,7 +7,7 @@ extern unsigned int cached_irq_mask;#define cached_master_mask (__byte(0, cached_irq_mask))#define cached_slave_mask (__byte(1, cached_irq_mask)) -extern spinlock_t i8259A_lock; +extern ipipe_spinlock_t i8259A_lock;extern void init_8259A (int auto_eoi);extern void enable_8259A_irq (unsigned int irq);
kernel/ipipe/core.c +10 -10
@@ -460,7 +460,7 @@ unsigned ipipe_alloc_virq(void)unsigned long flags, irq =0 ;int ipos; -spin_lock_irqsave_hw (&__ipipe_pipelock, flags); +spin_lock_irqsave (&__ipipe_pipelock, flags);if (__ipipe_virtual_irq_map != ~0 ) { ipos =ffz (__ipipe_virtual_irq_map);
@@ -468,7 +468,7 @@ unsigned ipipe_alloc_virq(void) irq = ipos +IPIPE_VIRQ_BASE ; } -spin_unlock_irqrestore_hw (&__ipipe_pipelock, flags); +spin_unlock_irqrestore (&__ipipe_pipelock, flags);return irq; }
@@ -496,7 +496,7 @@ int ipipe_virtualize_irq(struct ipipe_do/* Silently unwire interrupts for non-heading domains. */ modemask &= ~IPIPE_WIRED_MASK ; -spin_lock_irqsave_hw (&__ipipe_pipelock, flags); +spin_lock_irqsave (&__ipipe_pipelock, flags);if (handler !=NULL ) {
@@ -565,7 +565,7 @@ int ipipe_virtualize_irq(struct ipipe_do unlock_and_exit: -spin_unlock_irqrestore_hw (&__ipipe_pipelock, flags); +spin_unlock_irqrestore (&__ipipe_pipelock, flags);return err; }
@@ -595,7 +595,7 @@ int ipipe_control_irq(unsigned irq, unsiif ((clrmask & (IPIPE_HANDLE_MASK |IPIPE_STICKY_MASK )) !=0 )/* If one goes, both go. */ clrmask |= (IPIPE_HANDLE_MASK |IPIPE_STICKY_MASK ); -spin_lock_irqsave_hw (&__ipipe_pipelock, flags); +spin_lock_irqsave (&__ipipe_pipelock, flags); ipd->irqs[irq].control &= ~clrmask; ipd->irqs[irq].control |= setmask;
@@ -605,7 +605,7 @@ int ipipe_control_irq(unsigned irq, unsielse if ((clrmask &IPIPE_ENABLE_MASK ) !=0 )__ipipe_disable_irq (irq); -spin_unlock_irqrestore_hw (&__ipipe_pipelock, flags); +spin_unlock_irqrestore (&__ipipe_pipelock, flags);return 0 ; }
@@ -1163,7 +1163,7 @@ int ipipe_alloc_ptdkey (void)unsigned long flags;int key =-1 ; -spin_lock_irqsave_hw (&__ipipe_pipelock,flags); +spin_lock_irqsave (&__ipipe_pipelock,flags);if (__ipipe_ptd_key_count <IPIPE_ROOT_NPTDKEYS ) { key =ffz (__ipipe_ptd_key_map);
@@ -1171,7 +1171,7 @@ int ipipe_alloc_ptdkey (void) __ipipe_ptd_key_count++; } -spin_unlock_irqrestore_hw (&__ipipe_pipelock,flags); +spin_unlock_irqrestore (&__ipipe_pipelock,flags);return key; }
@@ -1183,12 +1183,12 @@ int ipipe_free_ptdkey (int key)if (key <0 || key >=IPIPE_ROOT_NPTDKEYS )return -EINVAL ; -spin_lock_irqsave_hw (&__ipipe_pipelock,flags); +spin_lock_irqsave (&__ipipe_pipelock,flags);if (test_and_clear_bit (key,&__ipipe_ptd_key_map)) __ipipe_ptd_key_count--; -spin_unlock_irqrestore_hw (&__ipipe_pipelock,flags); +spin_unlock_irqrestore (&__ipipe_pipelock,flags);return 0 ; }
kernel/ipipe/tracer.c +7 -7
@@ -124,7 +124,7 @@ static int max_path[NR_CPUS] = { [0 ... NR_CPUS-1] = IPIPE_DEFAULT_MAX };static int frozen_path[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =IPIPE_DEFAULT_FROZEN }; -static ipipe_spinlock_t global_path_lock =IPIPE_SPIN_LOCK_UNLOCKED ; +static IPIPE_DEFINE_SPINLOCK (global_path_lock);static int pre_trace =IPIPE_DEFAULT_PRE_TRACE ;static int post_trace =IPIPE_DEFAULT_POST_TRACE ;static int back_trace =IPIPE_DEFAULT_BACK_TRACE ;
@@ -210,7 +210,7 @@ __ipipe_trace_end(int cpu_id, struct ipiif (length > (trace_paths[cpu_id][max_path[cpu_id]]).length) {/* we need protection here against other cpus trying to start a proc dump */ -spin_lock_hw (&global_path_lock); +spin_lock (&global_path_lock);/* active path holds new worst case */ tp->length = length;
@@ -219,7 +219,7 @@ __ipipe_trace_end(int cpu_id, struct ipi/* find next unused trace path */ active =__ipipe_get_free_trace_path (active, cpu_id); -spin_unlock_hw (&global_path_lock); +spin_unlock (&global_path_lock); tp = &trace_paths[cpu_id][active];
@@ -242,7 +242,7 @@ __ipipe_trace_freeze(int cpu_id, struct/* we need protection here against other cpus trying * to set their frozen path or to start a proc dump */ -spin_lock_hw (&global_path_lock); +spin_lock (&global_path_lock); frozen_path[cpu_id] = active;
@@ -256,7 +256,7 @@ __ipipe_trace_freeze(int cpu_id, struct tp->end =-1 ; } -spin_unlock_hw (&global_path_lock); +spin_unlock (&global_path_lock); tp = &trace_paths[cpu_id][active];
@@ -408,7 +408,7 @@ static unsigned long __ipipe_global_pathint cpu_id;struct ipipe_trace_path *tp; -spin_lock_irqsave_hw (&global_path_lock, flags); +spin_lock_irqsave (&global_path_lock, flags); cpu_id =ipipe_processor_id (); restart:
@@ -441,7 +441,7 @@ static void __ipipe_global_path_unlock(ustruct ipipe_trace_path *tp;/* release spinlock first - it's not involved in the NMI issue */ -spin_unlock_hw (&global_path_lock); +spin_unlock (&global_path_lock); cpu_id =ipipe_processor_id (); tp = &trace_paths[cpu_id][active_path[cpu_id]];
kernel/printk.c +5 -5
@@ -506,7 +506,7 @@ void __ipipe_flush_printk (unsigned virq goto start; do { - spin_unlock_irqrestore_hw(&__ipipe_printk_lock,flags); + spin_unlock_irqrestore(&__ipipe_printk_lock, flags); start: lmax = __ipipe_printk_fill; while (out < lmax) {
@@ -515,13 +515,13 @@ void __ipipe_flush_printk (unsigned virq p += len; out += len; } -spin_lock_irqsave_hw (&__ipipe_printk_lock,flags); +spin_lock_irqsave (&__ipipe_printk_lock, flags); }while (__ipipe_printk_fill != lmax); __ipipe_printk_fill =0 ; -spin_unlock_irqrestore_hw (&__ipipe_printk_lock,flags); +spin_unlock_irqrestore (&__ipipe_printk_lock, flags); } asmlinkage int printk(const char *fmt, ...)
@@ -539,7 +539,7 @@ asmlinkage int printk(const char *fmt, . goto out; } -spin_lock_irqsave_hw (&__ipipe_printk_lock,flags); +spin_lock_irqsave (&__ipipe_printk_lock, flags); oldcount = __ipipe_printk_fill; fbytes = __LOG_BUF_LEN - oldcount;
@@ -551,7 +551,7 @@ asmlinkage int printk(const char *fmt, . }else r =0 ; -spin_unlock_irqrestore_hw (&__ipipe_printk_lock,flags); +spin_unlock_irqrestore (&__ipipe_printk_lock, flags);if (oldcount ==0 )ipipe_trigger_irq (__ipipe_printk_virq);
arch/i386/kernel/ipipe.c +5 -5
@@ -57,7 +57,7 @@ static cpumask_t __ipipe_cpu_sync_map;static cpumask_t __ipipe_cpu_lock_map; -static ipipe_spinlock_t __ipipe_cpu_barrier =IPIPE_SPIN_LOCK_UNLOCKED ; +static IPIPE_DEFINE_SPINLOCK (__ipipe_cpu_barrier);static atomic_t __ipipe_critical_count =ATOMIC_INIT (0 );
@@ -399,7 +399,7 @@ void __ipipe_do_critical_sync(unsigned i/* Now we are in sync with the lock requestor running on another CPU. Enter a spinning wait until he releases the global lock. */ -spin_lock_hw (&__ipipe_cpu_barrier); +spin_lock (&__ipipe_cpu_barrier);/* Got it. Now get out. */
@@ -407,7 +407,7 @@ void __ipipe_do_critical_sync(unsigned i/* Call the sync routine if any. */ __ipipe_cpu_sync (); -spin_unlock_hw (&__ipipe_cpu_barrier); +spin_unlock (&__ipipe_cpu_barrier);cpu_clear (cpuid, __ipipe_cpu_sync_map); }
@@ -451,7 +451,7 @@ unsigned long ipipe_critical_enter(void }while (++n < cpuid); } -spin_lock_hw (&__ipipe_cpu_barrier); +spin_lock (&__ipipe_cpu_barrier); __ipipe_cpu_sync = syncfn;
@@ -483,7 +483,7 @@ void ipipe_critical_exit(unsigned long fipipe_load_cpuid ();if (atomic_dec_and_test (&__ipipe_critical_count)) { -spin_unlock_hw (&__ipipe_cpu_barrier); +spin_unlock (&__ipipe_cpu_barrier);while (!cpus_empty (__ipipe_cpu_sync_map))cpu_relax ();
--- include/asm-generic/hal.h | 10 +++++++++- include/rtdm/rtdm_driver.h | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-)
include/asm-generic/hal.h +9 -1
@@ -135,8 +135,16 @@ typedef rwlock_t rthal_rwlock_t;#define rthal_write_unlock (lock) write_unlock_hw(lock)#define rthal_read_lock (lock) read_lock_hw(lock)#define rthal_read_unlock (lock) read_unlock_hw(lock) + +#ifdef spin_lock_hw +#define rthal_spin_lock_init (lock) spin_lock_init(lock)#define rthal_spin_lock (lock) spin_lock_hw(lock) -#define rthal_spin_unlock (lock) spin_unlock_hw(lock) +#define rthal_spin_unlock (lock) spin_unlock_hw(lock) +#else /* !spin_lock_hw */ +#define rthal_spin_lock_init (lock) *(lock) = IPIPE_SPIN_LOCK_UNLOCKED +#define rthal_spin_lock (lock) spin_lock(lock) +#define rthal_spin_unlock (lock) spin_unlock(lock) +#endif /* !spin_lock_hw */ #define rthal_root_domain ipipe_root_domain#define rthal_current_domain ipipe_current_domain
include/rtdm/rtdm_driver.h +3 -3
@@ -546,10 +546,10 @@ static inline nanosecs_abs_t rtdm_clock_/** * Static lock initialisation */ -#define RTDM_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED +#define RTDM_LOCK_UNLOCKED RTHAL_SPIN_LOCK_UNLOCKED/** Lock variable */ -typedef spinlock_t rtdm_lock_t ; +typedef rthal_spinlock_t rtdm_lock_t ;/** Variable to save the context while holding a lock */ typedef unsigned long rtdm_lockctx_t ;
@@ -569,7 +569,7 @@ typedef unsigned long rtdm* * Rescheduling: never. */ -#define rtdm_lock_init (lock) spin_lock_init(lock) +#define rtdm_lock_init (lock) rthal_spin_lock_init(lock)/** * Acquire lock from non-preemptible contexts
Quoted 11 lines · Jan Kiszka
Hi,
reading through the I-pipe patch I noticed that there are quite a few
spin_lock->spin_lock_hwand similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.
Quoted 2 lines
The required patch for Xenomai is attached as well.
I definitely like this. Queued for testing, thanks.
Signature · 1 line
Philippe.
Quoted 12 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
reading through the I-pipe patch I noticed that there are quite a few
spin_lock->spin_lock_hwand similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.
Quoted 5 lines
Quoted 2 lines
The required patch for Xenomai is attached as well.
I definitely like this. Queued for testing, thanks.
Small update of the ipipe part: typecasts were missing for the SMP||DEBUG_SPINLOCK case.
--- arch/i386/kernel/apic.c | 4 - arch/i386/kernel/i8253.c | 6 - arch/i386/kernel/i8259.c | 24 +++---- arch/i386/kernel/io_apic.c | 100 +++++++++++++++---------------- arch/i386/kernel/ipipe.c | 10 +-- arch/i386/kernel/time.c | 4 - arch/i386/mach-visws/visws_apic.c | 24 +++---- arch/i386/mach-voyager/voyager_basic.c | 8 +- drivers/ide/legacy/hd.c | 4 - drivers/input/gameport/gameport.c | 4 - drivers/input/joystick/analog.c | 4 - drivers/pci/htirq.c | 10 +-- include/asm-i386/i8253.h | 2 include/asm-i386/i8259.h | 2 include/asm-i386/mach-default/do_timer.h | 4 - include/linux/ipipe.h | 40 ------------ include/linux/spinlock.h | 88 +++++++++++++++++++++++---- include/linux/spinlock_types.h | 12 +++ kernel/ipipe/core.c | 20 +++--- kernel/ipipe/tracer.c | 14 ++-- kernel/printk.c | 10 +-- 21 files changed, 216 insertions(+), 178 deletions(-)
arch/i386/kernel/apic.c +2 -2
@@ -929,13 +929,13 @@ static unsigned int __devinit get_8254_tunsigned int count; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x00 ,PIT_MODE ); count =inb_p (PIT_CH0 ); count |=inb_p (PIT_CH0 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags);return count; }
arch/i386/kernel/i8253.c +3 -3
@@ -16,20 +16,20 @@#include "io_ports.h" -DEFINE_SPINLOCK (i8253_lock); +IPIPE_DEFINE_SPINLOCK (i8253_lock);EXPORT_SYMBOL (i8253_lock);void setup_pit_timer (void ) {unsigned long flags; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ udelay (10 );outb_p (LATCH &0xff ,PIT_CH0 );/* LSB */ udelay (10 );outb (LATCH >>8 ,PIT_CH0 );/* MSB */ -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags); }/*
arch/i386/kernel/i8259.c +12 -12
@@ -35,7 +35,7 @@*/ static int i8259A_auto_eoi; -DEFINE_SPINLOCK (i8259A_lock); +IPIPE_DEFINE_SPINLOCK (i8259A_lock);static void mask_and_ack_8259A (unsigned int );#ifdef CONFIG_IPIPE
@@ -87,14 +87,14 @@ void disable_8259A_irq(unsigned int irq)unsigned int mask =1 << irq;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);ipipe_irq_lock (irq); cached_irq_mask |= mask;if (irq &8 )outb (cached_slave_mask,PIC_SLAVE_IMR );else outb (cached_master_mask,PIC_MASTER_IMR ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); }void enable_8259A_irq (unsigned int irq)
@@ -102,7 +102,7 @@ void enable_8259A_irq(unsigned int irq)unsigned int mask = (1 << irq);unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);if (cached_irq_mask & mask) { cached_irq_mask &= ~mask;if (irq &8 )
@@ -111,7 +111,7 @@ void enable_8259A_irq(unsigned int irq)outb (cached_master_mask,PIC_MASTER_IMR );ipipe_irq_unlock (irq); } -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); }int i8259A_irq_pending (unsigned int irq)
@@ -120,12 +120,12 @@ int i8259A_irq_pending(unsigned int irq)unsigned long flags;int ret; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);if (irq <8 ) ret =inb (PIC_MASTER_CMD ) & mask;else ret =inb (PIC_SLAVE_CMD ) & (mask >>8 ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);return ret; }
@@ -173,7 +173,7 @@ static void mask_and_ack_8259A(unsignedunsigned int irqmask =1 << irq;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);/* * Lightweight spurious IRQ detection. We do not want * to overdo spurious IRQ handling - it's usually a sign
@@ -196,7 +196,7 @@ static void mask_and_ack_8259A(unsigned/* Fast timer ack -- don't mask (unless supposedly spurious) */ outb (0x20 ,PIC_MASTER_CMD ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); return; }#endif /* CONFIG_IPIPE */
@@ -213,7 +213,7 @@ handle_real_irq:outb (cached_master_mask,PIC_MASTER_IMR );outb (0x60 +irq,PIC_MASTER_CMD );/* 'Specific EOI to master */ } -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);return ; spurious_8259A_irq:
@@ -316,7 +316,7 @@ void init_8259A(int auto_eoi) i8259A_auto_eoi = auto_eoi; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);outb (0xff ,PIC_MASTER_IMR );/* mask all of 8259A-1 */ outb (0xff ,PIC_SLAVE_IMR );/* mask all of 8259A-2 */
@@ -350,7 +350,7 @@ void init_8259A(int auto_eoi)outb (cached_master_mask,PIC_MASTER_IMR );/* restore master IRQ mask */ outb (cached_slave_mask,PIC_SLAVE_IMR );/* restore slave IRQ mask */ -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); }/*
arch/i386/kernel/io_apic.c +50 -50
307 lines not on this page · raw message
arch/i386/kernel/time.c +2 -2
@@ -181,11 +181,11 @@ irqreturn_t timer_interrupt(int irq, voi* on an 82489DX-based system. */ unsigned long flags; -spin_lock_irqsave_hw_cond (&i8259A_lock,flags); +spin_lock_irqsave_cond (&i8259A_lock,flags);outb (0x0c ,PIC_MASTER_OCW3 );/* Ack the IRQ; AEOI will end it automatically. */ inb (PIC_MASTER_POLL ); - spin_unlock_irqrestore_hw_cond(&i8259A_lock,flags); + spin_unlock_irqrestore_cond(&i8259A_lock,flags); }#endif
include/asm-i386/mach-default/do_timer.h +2 -2
@@ -56,13 +56,13 @@ static inline int do_timer_overflow(intint i;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);/* * This is tricky when I/O APICs are used; * see do_timer_interrupt(). */ i =inb (0x20 ); -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);/* assumption about timer being IRQ0 */ if (i &0x01 ) {
include/linux/ipipe.h +0 -40
@@ -229,9 +229,6 @@ do { \ } \ } while(0) -#define spin_lock_hw (x) __raw_spin_lock(&(x)->raw_lock) -#define spin_trylock_hw (x) __raw_spin_trylock(&(x)->raw_lock) -#define spin_unlock_hw (x) __raw_spin_unlock(&(x)->raw_lock)#if defined(CONFIG_SMP ) || defined(CONFIG_DEBUG_SPINLOCK )#define write_lock_hw (x) __raw_write_lock(&(x)->raw_lock)#define write_trylock_hw (x) __raw_write_trylock(&(x)->raw_lock)
@@ -248,35 +245,9 @@ do { \#define read_unlock_hw (lock) do { (void)(lock); } while (0)#endif /* CONFIG_SMP || CONFIG_DEBUG_SPINLOCK */ -typedef spinlock_t ipipe_spinlock_t ;typedef rwlock_t ipipe_rwlock_t ; -#define IPIPE_SPIN_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED#define IPIPE_RW_LOCK_UNLOCKED RW_LOCK_UNLOCKED -#define spin_lock_irqsave_hw (x,flags) \ -do { \ - local_irq_save_hw(flags); \ - spin_lock_hw(x); \ -} while (0) - -#define spin_unlock_irqrestore_hw (x,flags) \ -do { \ - spin_unlock_hw(x); \ - local_irq_restore_hw(flags); \ -} while (0) - -#define spin_lock_irq_hw (x) \ -do { \ - local_irq_disable_hw(); \ - spin_lock_hw(x); \ -} while (0) - -#define spin_unlock_irq_hw (x) \ -do { \ - spin_unlock_hw(x); \ - local_irq_enable_hw(); \ -} while (0) -#define read_lock_irqsave_hw (lock, flags) \ do { \ local_irq_save_hw(flags); \
@@ -688,8 +659,6 @@ void fastcall *ipipe_get_ptd(int key);local_irq_disable_hw (); \ } while(0) -#define spin_lock_irqsave_hw_cond (lock,flags) spin_lock_irqsave_hw(lock,flags) -#define spin_unlock_irqrestore_hw_cond (lock,flags) spin_unlock_irqrestore_hw(lock,flags)#define smp_processor_id_hw () ipipe_processor_id()#define ipipe_irq_lock (irq) \
@@ -720,19 +689,10 @@ void fastcall *ipipe_get_ptd(int key);#define ipipe_trap_notify (t,r) 0#define ipipe_init_proc () do { } while(0) -#define spin_lock_hw (lock) spin_lock(lock) -#define spin_unlock_hw (lock) spin_unlock(lock) -#define spin_lock_irq_hw (lock) spin_lock_irq(lock) -#define spin_unlock_irq_hw (lock) spin_unlock_irq(lock) -#define spin_lock_irqsave_hw (lock,flags) spin_lock_irqsave(lock, flags) -#define spin_unlock_irqrestore_hw (lock,flags) spin_unlock_irqrestore(lock, flags) -#define local_irq_enable_hw_cond () do { } while(0)#define local_irq_disable_hw_cond () do { } while(0)#define local_irq_save_hw_cond (flags) do { (void)(flags); } while(0)#define local_irq_restore_hw_cond (flags) do { } while(0) -#define spin_lock_irqsave_hw_cond (lock,flags) do { (void)(flags); spin_lock(lock); } while(0) -#define spin_unlock_irqrestore_hw_cond (lock,flags) spin_unlock(lock)#define smp_processor_id_hw () smp_processor_id()#define ipipe_irq_lock (irq) do { } while(0)
include/linux/spinlock.h +77 -11
135 lines not on this page · raw message
include/linux/spinlock_types.h +12 -0
@@ -31,6 +31,10 @@ typedef struct {#endif } spinlock_t; +typedef struct { +raw_spinlock_t __raw_lock; +}ipipe_spinlock_t ; +#define SPINLOCK_MAGIC 0xdead4ead typedef struct {
@@ -86,9 +90,17 @@ typedef struct {#endif #define SPIN_LOCK_UNLOCKED __SPIN_LOCK_UNLOCKED(old_style_spin_init) +#define IPIPE_SPIN_LOCK_UNLOCKED \ + (ipipe_spinlock_t) { .__raw_lock = __RAW_SPIN_LOCK_UNLOCKED }#define RW_LOCK_UNLOCKED __RW_LOCK_UNLOCKED(old_style_rw_init)#define DEFINE_SPINLOCK (x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)#define DEFINE_RWLOCK (x) rwlock_t x = __RW_LOCK_UNLOCKED(x) +#ifdef CONFIG_IPIPE +#define IPIPE_DEFINE_SPINLOCK (x) ipipe_spinlock_t x = IPIPE_SPIN_LOCK_UNLOCKED +#else +#define IPIPE_DEFINE_SPINLOCK (x) DEFINE_SPINLOCK(x) +#endif +#endif /* __LINUX_SPINLOCK_TYPES_H */
arch/i386/mach-visws/visws_apic.c +12 -12
@@ -29,7 +29,7 @@#include "irq_vectors.h" -static DEFINE_SPINLOCK (cobalt_lock); +static IPIPE_DEFINE_SPINLOCK (cobalt_lock);/* * Set the given Cobalt APIC Redirection Table entry to point
@@ -94,11 +94,11 @@ static unsigned int startup_cobalt_irq(u {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);if ((irq_desc[irq].status & (IRQ_DISABLED |IRQ_INPROGRESS |IRQ_WAITING ))) irq_desc[irq].status &= ~(IRQ_DISABLED |IRQ_INPROGRESS |IRQ_WAITING );enable_cobalt_irq (irq); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags);return 0 ; }
@@ -106,20 +106,20 @@ static void ack_cobalt_irq(unsigned int {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);disable_cobalt_irq (irq);apic_write (APIC_EOI ,APIC_EIO_ACK ); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags); }static void end_cobalt_irq (unsigned int irq) {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);if (!(irq_desc[irq].status & (IRQ_DISABLED |IRQ_INPROGRESS )))enable_cobalt_irq (irq); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags); }#ifdef CONFIG_IPIPE
@@ -174,9 +174,9 @@ static void end_piix4_master_irq(unsigne {unsigned long flags; -spin_lock_irqsave_hw (&cobalt_lock, flags); +spin_lock_irqsave (&cobalt_lock, flags);enable_cobalt_irq (irq); -spin_unlock_irqrestore_hw (&cobalt_lock, flags); +spin_unlock_irqrestore (&cobalt_lock, flags); }static struct irq_chip piix4_master_irq_type = {
@@ -216,7 +216,7 @@ static irqreturn_t piix4_master_intr(intirq_desc_t *desc;unsigned long flags; -spin_lock_irqsave_hw (&i8259A_lock, flags); +spin_lock_irqsave (&i8259A_lock, flags);/* Find out what's interrupting in the PIIX4 master 8259 */ outb (0x0c ,0x20 );/* OCW3 Poll command */
@@ -253,7 +253,7 @@ static irqreturn_t piix4_master_intr(intoutb (0x60 + realirq,0x20 ); } -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags); desc = irq_desc + realirq;
@@ -271,7 +271,7 @@ static irqreturn_t piix4_master_intr(intreturn IRQ_HANDLED ; out_unlock: -spin_unlock_irqrestore_hw (&i8259A_lock, flags); +spin_unlock_irqrestore (&i8259A_lock, flags);return IRQ_NONE ; }
arch/i386/mach-voyager/voyager_basic.c +4 -4
@@ -185,20 +185,20 @@ voyager_timer_interrupt(void)* pointy. */ __u16 val; -spin_lock_irqsave_hw (&i8253_lock); +spin_lock_irqsave (&i8253_lock);outb_p (0x00 ,0x43 ); val =inb_p (0x40 ); val |=inb (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock); +spin_unlock_irqrestore (&i8253_lock);if (val >LATCH ) {printk ("\nVOYAGER: countdown timer value too high (%d), resetting\n\n" , val); -spin_lock_irqsave_hw (&i8253_lock); +spin_lock_irqsave (&i8253_lock);outb (0x34 ,0x43 );outb_p (LATCH &0xff ,0x40 );/* LSB */ outb (LATCH >>8 ,0x40 );/* MSB */ -spin_unlock_irqrestore_hw (&i8253_lock); +spin_unlock_irqrestore (&i8253_lock); } }#ifdef CONFIG_SMP
drivers/ide/legacy/hd.c +2 -2
@@ -166,12 +166,12 @@ unsigned long read_timer(void)unsigned long t, flags;int i; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags); t = jiffies *11932 ;outb_p (0 ,0x43 ); i =inb_p (0x40 ); i |=inb (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags); return(t - i); }#endif
drivers/input/gameport/gameport.c +2 -2
@@ -71,11 +71,11 @@ static unsigned int get_time_pit(void)unsigned long flags;unsigned int count; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x00 ,0x43 ); count =inb_p (0x40 ); count |=inb_p (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags);return count; }
drivers/input/joystick/analog.c +2 -2
@@ -151,11 +151,11 @@ static unsigned int get_time_pit(void)unsigned long flags;unsigned int count; -spin_lock_irqsave_hw (&i8253_lock, flags); +spin_lock_irqsave (&i8253_lock, flags);outb_p (0x00 ,0x43 ); count =inb_p (0x40 ); count |=inb_p (0x40 ) <<8 ; -spin_unlock_irqrestore_hw (&i8253_lock, flags); +spin_unlock_irqrestore (&i8253_lock, flags);return count; }
drivers/pci/htirq.c +5 -5
@@ -21,7 +21,7 @@* With multiple simultaneous hypertransport irq devices it might pay * to make this more fine grained. But start with simple, stupid, and correct. */ -static DEFINE_SPINLOCK (ht_irq_lock); +static IPIPE_DEFINE_SPINLOCK (ht_irq_lock);struct ht_irq_cfg {struct pci_dev *dev;
@@ -37,7 +37,7 @@ void write_ht_irq_msg(unsigned int irq, {struct ht_irq_cfg *cfg =get_irq_data (irq);unsigned long flags; -spin_lock_irqsave_hw (&ht_irq_lock, flags); +spin_lock_irqsave (&ht_irq_lock, flags);if (cfg->msg.address_lo != msg->address_lo) {pci_write_config_byte (cfg->dev, cfg->pos +2 , cfg->idx);pci_write_config_dword (cfg->dev, cfg->pos +4 , msg->address_lo);
@@ -48,7 +48,7 @@ void write_ht_irq_msg(unsigned int irq, }if (cfg->update) cfg->update (cfg->dev, irq, msg); -spin_unlock_irqrestore_hw (&ht_irq_lock, flags); +spin_unlock_irqrestore (&ht_irq_lock, flags); cfg->msg = *msg; }
@@ -111,10 +111,10 @@ int __ht_create_irq(struct pci_dev *dev,return -EINVAL ;/* Verify the idx I want to use is in range */ -spin_lock_irqsave_hw (&ht_irq_lock, flags); +spin_lock_irqsave (&ht_irq_lock, flags);pci_write_config_byte (dev, pos +2 ,1 );pci_read_config_dword (dev, pos +4 , &data); -spin_unlock_irqrestore_hw (&ht_irq_lock, flags); +spin_unlock_irqrestore (&ht_irq_lock, flags); max_irq = (data >>16 ) &0xff ;if ( idx > max_irq)
include/asm-i386/i8253.h +1 -1
@@ -1,6 +1,6 @@#ifndef __ASM_I8253_H__#define __ASM_I8253_H__ -extern spinlock_t i8253_lock; +extern ipipe_spinlock_t i8253_lock;#endif /* __ASM_I8253_H__ */
include/asm-i386/i8259.h +1 -1
@@ -7,7 +7,7 @@ extern unsigned int cached_irq_mask;#define cached_master_mask (__byte(0, cached_irq_mask))#define cached_slave_mask (__byte(1, cached_irq_mask)) -extern spinlock_t i8259A_lock; +extern ipipe_spinlock_t i8259A_lock;extern void init_8259A (int auto_eoi);extern void enable_8259A_irq (unsigned int irq);
kernel/ipipe/core.c +10 -10
@@ -460,7 +460,7 @@ unsigned ipipe_alloc_virq(void)unsigned long flags, irq =0 ;int ipos; -spin_lock_irqsave_hw (&__ipipe_pipelock, flags); +spin_lock_irqsave (&__ipipe_pipelock, flags);if (__ipipe_virtual_irq_map != ~0 ) { ipos =ffz (__ipipe_virtual_irq_map);
@@ -468,7 +468,7 @@ unsigned ipipe_alloc_virq(void) irq = ipos +IPIPE_VIRQ_BASE ; } -spin_unlock_irqrestore_hw (&__ipipe_pipelock, flags); +spin_unlock_irqrestore (&__ipipe_pipelock, flags);return irq; }
@@ -496,7 +496,7 @@ int ipipe_virtualize_irq(struct ipipe_do/* Silently unwire interrupts for non-heading domains. */ modemask &= ~IPIPE_WIRED_MASK ; -spin_lock_irqsave_hw (&__ipipe_pipelock, flags); +spin_lock_irqsave (&__ipipe_pipelock, flags);if (handler !=NULL ) {
@@ -565,7 +565,7 @@ int ipipe_virtualize_irq(struct ipipe_do unlock_and_exit: -spin_unlock_irqrestore_hw (&__ipipe_pipelock, flags); +spin_unlock_irqrestore (&__ipipe_pipelock, flags);return err; }
@@ -595,7 +595,7 @@ int ipipe_control_irq(unsigned irq, unsiif ((clrmask & (IPIPE_HANDLE_MASK |IPIPE_STICKY_MASK )) !=0 )/* If one goes, both go. */ clrmask |= (IPIPE_HANDLE_MASK |IPIPE_STICKY_MASK ); -spin_lock_irqsave_hw (&__ipipe_pipelock, flags); +spin_lock_irqsave (&__ipipe_pipelock, flags); ipd->irqs[irq].control &= ~clrmask; ipd->irqs[irq].control |= setmask;
@@ -605,7 +605,7 @@ int ipipe_control_irq(unsigned irq, unsielse if ((clrmask &IPIPE_ENABLE_MASK ) !=0 )__ipipe_disable_irq (irq); -spin_unlock_irqrestore_hw (&__ipipe_pipelock, flags); +spin_unlock_irqrestore (&__ipipe_pipelock, flags);return 0 ; }
@@ -1163,7 +1163,7 @@ int ipipe_alloc_ptdkey (void)unsigned long flags;int key =-1 ; -spin_lock_irqsave_hw (&__ipipe_pipelock,flags); +spin_lock_irqsave (&__ipipe_pipelock,flags);if (__ipipe_ptd_key_count <IPIPE_ROOT_NPTDKEYS ) { key =ffz (__ipipe_ptd_key_map);
@@ -1171,7 +1171,7 @@ int ipipe_alloc_ptdkey (void) __ipipe_ptd_key_count++; } -spin_unlock_irqrestore_hw (&__ipipe_pipelock,flags); +spin_unlock_irqrestore (&__ipipe_pipelock,flags);return key; }
@@ -1183,12 +1183,12 @@ int ipipe_free_ptdkey (int key)if (key <0 || key >=IPIPE_ROOT_NPTDKEYS )return -EINVAL ; -spin_lock_irqsave_hw (&__ipipe_pipelock,flags); +spin_lock_irqsave (&__ipipe_pipelock,flags);if (test_and_clear_bit (key,&__ipipe_ptd_key_map)) __ipipe_ptd_key_count--; -spin_unlock_irqrestore_hw (&__ipipe_pipelock,flags); +spin_unlock_irqrestore (&__ipipe_pipelock,flags);return 0 ; }
kernel/ipipe/tracer.c +7 -7
@@ -124,7 +124,7 @@ static int max_path[NR_CPUS] = { [0 ... NR_CPUS-1] = IPIPE_DEFAULT_MAX };static int frozen_path[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =IPIPE_DEFAULT_FROZEN }; -static ipipe_spinlock_t global_path_lock =IPIPE_SPIN_LOCK_UNLOCKED ; +static IPIPE_DEFINE_SPINLOCK (global_path_lock);static int pre_trace =IPIPE_DEFAULT_PRE_TRACE ;static int post_trace =IPIPE_DEFAULT_POST_TRACE ;static int back_trace =IPIPE_DEFAULT_BACK_TRACE ;
@@ -210,7 +210,7 @@ __ipipe_trace_end(int cpu_id, struct ipiif (length > (trace_paths[cpu_id][max_path[cpu_id]]).length) {/* we need protection here against other cpus trying to start a proc dump */ -spin_lock_hw (&global_path_lock); +spin_lock (&global_path_lock);/* active path holds new worst case */ tp->length = length;
@@ -219,7 +219,7 @@ __ipipe_trace_end(int cpu_id, struct ipi/* find next unused trace path */ active =__ipipe_get_free_trace_path (active, cpu_id); -spin_unlock_hw (&global_path_lock); +spin_unlock (&global_path_lock); tp = &trace_paths[cpu_id][active];
@@ -242,7 +242,7 @@ __ipipe_trace_freeze(int cpu_id, struct/* we need protection here against other cpus trying * to set their frozen path or to start a proc dump */ -spin_lock_hw (&global_path_lock); +spin_lock (&global_path_lock); frozen_path[cpu_id] = active;
@@ -256,7 +256,7 @@ __ipipe_trace_freeze(int cpu_id, struct tp->end =-1 ; } -spin_unlock_hw (&global_path_lock); +spin_unlock (&global_path_lock); tp = &trace_paths[cpu_id][active];
@@ -408,7 +408,7 @@ static unsigned long __ipipe_global_pathint cpu_id;struct ipipe_trace_path *tp; -spin_lock_irqsave_hw (&global_path_lock, flags); +spin_lock_irqsave (&global_path_lock, flags); cpu_id =ipipe_processor_id (); restart:
@@ -441,7 +441,7 @@ static void __ipipe_global_path_unlock(ustruct ipipe_trace_path *tp;/* release spinlock first - it's not involved in the NMI issue */ -spin_unlock_hw (&global_path_lock); +spin_unlock (&global_path_lock); cpu_id =ipipe_processor_id (); tp = &trace_paths[cpu_id][active_path[cpu_id]];
kernel/printk.c +5 -5
@@ -506,7 +506,7 @@ void __ipipe_flush_printk (unsigned virq goto start; do { - spin_unlock_irqrestore_hw(&__ipipe_printk_lock,flags); + spin_unlock_irqrestore(&__ipipe_printk_lock, flags); start: lmax = __ipipe_printk_fill; while (out < lmax) {
@@ -515,13 +515,13 @@ void __ipipe_flush_printk (unsigned virq p += len; out += len; } -spin_lock_irqsave_hw (&__ipipe_printk_lock,flags); +spin_lock_irqsave (&__ipipe_printk_lock, flags); }while (__ipipe_printk_fill != lmax); __ipipe_printk_fill =0 ; -spin_unlock_irqrestore_hw (&__ipipe_printk_lock,flags); +spin_unlock_irqrestore (&__ipipe_printk_lock, flags); } asmlinkage int printk(const char *fmt, ...)
@@ -539,7 +539,7 @@ asmlinkage int printk(const char *fmt, . goto out; } -spin_lock_irqsave_hw (&__ipipe_printk_lock,flags); +spin_lock_irqsave (&__ipipe_printk_lock, flags); oldcount = __ipipe_printk_fill; fbytes = __LOG_BUF_LEN - oldcount;
@@ -551,7 +551,7 @@ asmlinkage int printk(const char *fmt, . }else r =0 ; -spin_unlock_irqrestore_hw (&__ipipe_printk_lock,flags); +spin_unlock_irqrestore (&__ipipe_printk_lock, flags);if (oldcount ==0 )ipipe_trigger_irq (__ipipe_printk_virq);
arch/i386/kernel/ipipe.c +5 -5
@@ -57,7 +57,7 @@ static cpumask_t __ipipe_cpu_sync_map;static cpumask_t __ipipe_cpu_lock_map; -static ipipe_spinlock_t __ipipe_cpu_barrier =IPIPE_SPIN_LOCK_UNLOCKED ; +static IPIPE_DEFINE_SPINLOCK (__ipipe_cpu_barrier);static atomic_t __ipipe_critical_count =ATOMIC_INIT (0 );
@@ -399,7 +399,7 @@ void __ipipe_do_critical_sync(unsigned i/* Now we are in sync with the lock requestor running on another CPU. Enter a spinning wait until he releases the global lock. */ -spin_lock_hw (&__ipipe_cpu_barrier); +spin_lock (&__ipipe_cpu_barrier);/* Got it. Now get out. */
@@ -407,7 +407,7 @@ void __ipipe_do_critical_sync(unsigned i/* Call the sync routine if any. */ __ipipe_cpu_sync (); -spin_unlock_hw (&__ipipe_cpu_barrier); +spin_unlock (&__ipipe_cpu_barrier);cpu_clear (cpuid, __ipipe_cpu_sync_map); }
@@ -451,7 +451,7 @@ unsigned long ipipe_critical_enter(void }while (++n < cpuid); } -spin_lock_hw (&__ipipe_cpu_barrier); +spin_lock (&__ipipe_cpu_barrier); __ipipe_cpu_sync = syncfn;
@@ -483,7 +483,7 @@ void ipipe_critical_exit(unsigned long fipipe_load_cpuid ();if (atomic_dec_and_test (&__ipipe_critical_count)) { -spin_unlock_hw (&__ipipe_cpu_barrier); +spin_unlock (&__ipipe_cpu_barrier);while (!cpus_empty (__ipipe_cpu_sync_map))cpu_relax ();
Quoted 13 lines · Jan Kiszka
Quoted 12 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
reading through the I-pipe patch I noticed that there are quite a few
spin_lock->spin_lock_hwand similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The required patch for Xenomai is attached as well.
I definitely like this. Queued for testing, thanks.
Small update of the ipipe part: typecasts were missing for the SMP||DEBUG_SPINLOCK case.
I saw this recently, thanks. I'm currently working on 1.6-02, which includes the spinlock op selection, and yet-another-rework of the interrupt flow. Did anything changed regarding the tracer in the attached patch?
Signature · 1 line
Philippe.
Quoted 18 lines · Philippe Gerum
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
reading through the I-pipe patch I noticed that there are quite a few
spin_lock->spin_lock_hwand similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.Quoted 2 lines
The required patch for Xenomai is attached as well.
I definitely like this. Queued for testing, thanks.
Quoted 8 lines
Quoted 2 lines
Small update of the ipipe part: typecasts were missing for the SMP||DEBUG_SPINLOCK case.
I saw this recently, thanks. I'm currently working on 1.6-02, which includes the spinlock op selection, and yet-another-rework of the interrupt flow. Did anything changed regarding the tracer in the attached patch?
Nope, only the linux/spinlock.h should be different (unless I messed something up). Do you get rejects?
I'm currently preparing to post a few cleanup patches for I-pipe (and Xenomai). Not a must for -02, but maybe worth a glance. Just a minute...
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Philippe Gerum
Quoted 19 lines · Jan Kiszka
Quoted 12 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
reading through the I-pipe patch I noticed that there are quite a few
spin_lock->spin_lock_hwand similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.Quoted 4 lines
Quoted 2 lines
The required patch for Xenomai is attached as well.
I definitely like this. Queued for testing, thanks.
Small update of the ipipe part: typecasts were missing for the SMP||DEBUG_SPINLOCK case.
Quoted 8 lines
Quoted 5 lines
I saw this recently, thanks. I'm currently working on 1.6-02, which includes the spinlock op selection, and yet-another-rework of the interrupt flow. Did anything changed regarding the tracer in the attached patch?
Nope, only the
linux/spinlock.hshould be different (unless I messed something up). Do you get rejects?
No, that's ok. I was wondering whether I should pick changes aside of spinlock.h, which I have reworked.
Quoted 4 lines
I'm currently preparing to post a few cleanup patches for I-pipe (and Xenomai). Not a must for -02, but maybe worth a glance. Just a minute...
Signature · 1 line
Philippe.
Quoted 10 lines · Jan Kiszka
Hi,
reading through the I-pipe patch I noticed that there are quite a few
spin_lock->spin_lock_hwand similar conversions. Having the conversion mechanism of the -rt patch in mind, I wrote the attached I-pipe cleanup that applies a similar pattern on this issue. Gives more than 10k patch size reduction for x86 and a bit more safety against minor variations of the patched code. Still, review of the lock usages keeps on being required as the lock user could assume running IRQs off while I-pipe may not guarantee this.
Merged after refactoring in 1.6-02/x86. Thanks.
Signature · 1 line
Philippe.