Re: [PATCH][RFC] Spinlock-timeout

From: Jan-Benedict Glaw (jbglaw_at_lug-owl.de)
Date: 06/05/04

  • Next message: Arjan van de Ven: "Re: clone() <-> getpid() bug in 2.6?"
    Date:	Sat, 5 Jun 2004 22:51:17 +0200
    To: linux-kernel@vger.kernel.org
    
    
    

    On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <moilanen@austin.ibm.com>
    wrote in message <1086467486.20906.59.camel@dhcp-client215.upt.austin.ibm.com>:
    > Here's a patch that will BUG() when a spinlock is held for longer then X
    > seconds. It is useful for catching deadlocks since not all archs have a
    > NMI watchdog.

    I like the idea. However, I don't like touching all arch's Kconfig
    files. I think it's better to either put this into ./lib/Kconfig (well,
    doesn't really fit there), ot (even better:) put it into the Debug
    Kconfig file.

    > diff -Nru a/include/linux/spinlock.h b/include/linux/spinlock.h
    > --- a/include/linux/spinlock.h Sat Jun 5 14:25:51 2004
    > +++ b/include/linux/spinlock.h Sat Jun 5 14:25:51 2004
    > @@ -38,6 +38,16 @@
    > #ifdef CONFIG_SMP
    > #include <asm/spinlock.h>
    >
    > +#if defined(CONFIG_SPINLOCK_TIMEOUT)
    > +
    > +#include <asm/param.h>
    > +
    > +#define SPINLOCK_TIMEOUT CONFIG_SPINLOCK_TIMEOUT_TIME
    > +extern unsigned long volatile jiffies;
    > +
    > +#endif /* CONFIG_SPINLOCK_TIMEOUT */
    > +
    > +
    > #else
    >
    > #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)

    I'd say just include <linux/jiffies.h> and drop the whole #ifdef/#endif
    block.

    > @@ -218,11 +228,27 @@
    > } while (0)
    >
    > #else
    > +#if defined(CONFIG_SPINLOCK_TIMEOUT)
    > +
    > +static inline void spin_lock(spinlock_t * lock) {
    > + unsigned long jiffy_timeout = jiffies + (SPINLOCK_TIMEOUT * HZ);
    > +
    > + preempt_disable();
    > + do {
    > + if (jiffies >= jiffy_timeout)
    > + BUG();
    > + } while (!_raw_spin_trylock(lock));
    > +}
    > +
    > +#else /* CONFIG_SPINLOCK_TIMEOUT */
    > +
    > #define spin_lock(lock) \
    > do { \
    > preempt_disable(); \
    > _raw_spin_lock(lock); \
    > } while(0)
    > +
    > +#endif /* CONFIG_SPINLOCK_TIMEOUT */
    >
    > #define write_lock(lock) \
    > do { \

    Also, printing out ->module, ->owner and ->oline might help additionally
    to just BUG()ing. So you see the (former) owner of the lock.

    > @@ -3967,6 +3971,10 @@
    > while (spin_is_locked(lock))
    > cpu_relax();
    > preempt_disable();
    > +#if defined(CONFIG_SPINLOCK_TIMEOUT)
    > + if (jiffies > = jiffy_timeout)
    > + BUG();
    > +#endif
    > } while (!_raw_spin_trylock(lock));
    > }
    >

    Dito.

    MfG, JBG

    -- 
       Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
       "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
        fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
       ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
    
    

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/



  • Next message: Arjan van de Ven: "Re: clone() <-> getpid() bug in 2.6?"

    Relevant Pages

    • Re: Linux 2.4 future
      ... we want to have a somewhat stable interface for libc (-> ... "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Problems with my parport (and printer)
      ... all kernel debug output (as seen in ... "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Stop the Linux kernel madness
      ... We don't have the man power, hardware, nor the support ... "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Unbloating the kernel, action list
      ... >> of switching userspace around to verify it. ... "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: kernel.bkbits.net off the air
      ... > at all as long as the raw changesets were rsyncable...then the community ... "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)