2004-06-05 20:31:55

by Jake Moilanen

[permalink] [raw]
Subject: [PATCH][RFC] Spinlock-timeout

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.

It is also helpful to find locks that are held too long.

Please send comments.

Thanks,
Jake



Attachments:
spinlock-timeout-2.6-1.patch (19.45 kB)

2004-06-05 20:51:23

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <[email protected]>
wrote in message <[email protected]>:
> 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 [email protected] . +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));


Attachments:
(No filename) (2.43 kB)
signature.asc (189.00 B)
Digital signature
Download all attachments

2004-06-06 10:13:39

by Paul Mackerras

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

Jake Moilanen writes:

> 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.
[snip]
> + if (jiffies >= jiffy_timeout)
> + BUG();

Don't you need to use time_after()?

Regards,
Paul.

2004-06-06 22:25:57

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Sat, 2004-06-05 at 15:31, Jake Moilanen wrote:
> 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.
>
> It is also helpful to find locks that are held too long.
>
> Please send comments.

It would be better to use the timebase on CPUs that have one, no ? Or
you'll miss cases where either irqs are disabled or you are on a code
path issued by the timer interrupt, and thus jiffies isn't updated


2004-06-10 18:45:16

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Sat, 2004-06-05 at 15:51, Jan-Benedict Glaw wrote:
> On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <[email protected]>
> wrote in message <[email protected]>:
> > 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.
>

I think you're right that lib/Kconfig would not be the right place, but
I don't think there is a debug Kconfig. I tried keeping the Kconfig
additions w/ CONFIG_DEBUG_SPINLOCK. The other option is to make a debug
Kconfig, but every arch seems pretty different in what they have for
their debug section.

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

You're right, I'll take this out.

> > @@ -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.

I think this would give us some extra info, but ->module, ->owner, and
->oline is only used for !SMP. I could add that in for all the arch's
spinlock_t in their asm/spinlock.h. I'm not sure how well that would be
received to increase the size of everyones spinlock_t even though it
would only be when CONFIG_DEBUG_SPINLOCK is on.

Thanks,
Jake

2004-06-10 19:26:46

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Thu, 2004-06-10 13:44:52 -0500, Jake Moilanen <[email protected]>
wrote in message <[email protected]>:
> On Sat, 2004-06-05 at 15:51, Jan-Benedict Glaw wrote:
> > On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <[email protected]>
> > wrote in message <[email protected]>:
> > > 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.
>
> I think you're right that lib/Kconfig would not be the right place, but
> I don't think there is a debug Kconfig. I tried keeping the Kconfig

Not yet:) Somebody is working towards getting all the different debug
options into a central Kconfig file. This was on LKML some four weeks
ago...

> additions w/ CONFIG_DEBUG_SPINLOCK. The other option is to make a debug
> Kconfig, but every arch seems pretty different in what they have for
> their debug section.

As I said, it's been worked on:)

MfG, JBG

--
Jan-Benedict Glaw [email protected] . +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));


Attachments:
(No filename) (1.56 kB)
signature.asc (189.00 B)
Digital signature
Download all attachments

2004-06-10 21:03:05

by Randy.Dunlap

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Thu, 10 Jun 2004 21:24:30 +0200 Jan-Benedict Glaw wrote:

| On Thu, 2004-06-10 13:44:52 -0500, Jake Moilanen <[email protected]>
| wrote in message <[email protected]>:
| > On Sat, 2004-06-05 at 15:51, Jan-Benedict Glaw wrote:
| > > On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <[email protected]>
| > > wrote in message <[email protected]>:
| > > > 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.
| >
| > I think you're right that lib/Kconfig would not be the right place, but
| > I don't think there is a debug Kconfig. I tried keeping the Kconfig
|
| Not yet:) Somebody is working towards getting all the different debug
| options into a central Kconfig file. This was on LKML some four weeks
| ago...
|
| > additions w/ CONFIG_DEBUG_SPINLOCK. The other option is to make a debug
| > Kconfig, but every arch seems pretty different in what they have for
| > their debug section.
|
| As I said, it's been worked on:)

Yes, I'll make a new version soon....

--
~Randy

2004-06-11 14:05:58

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Sun, 2004-06-06 at 17:23, Benjamin Herrenschmidt wrote:
> On Sat, 2004-06-05 at 15:31, Jake Moilanen wrote:
> > 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.
> >
> > It is also helpful to find locks that are held too long.
> >
> > Please send comments.
>
> It would be better to use the timebase on CPUs that have one, no ? Or
> you'll miss cases where either irqs are disabled or you are on a code
> path issued by the timer interrupt, and thus jiffies isn't updated

Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow
archs use their timebases if they have one, and if they don't, it uses
jiffies. time_after_eq() is used to do the jiffy checking.

I also left all of the arch/*/Kconfig changes in until a debug Kconfig
is done. I pretty much added in the spinlock timeout on all archs that
have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry.

Thanks,
Jake



Attachments:
spinlock-timeout-2.6-v2.patch (22.20 kB)

2004-06-11 14:08:45

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Sun, 2004-06-06 at 17:23, Benjamin Herrenschmidt wrote:
> On Sat, 2004-06-05 at 15:31, Jake Moilanen wrote:
> > 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.
> >
> > It is also helpful to find locks that are held too long.
> >
> > Please send comments.
>
> It would be better to use the timebase on CPUs that have one, no ? Or
> you'll miss cases where either irqs are disabled or you are on a code
> path issued by the timer interrupt, and thus jiffies isn't updated

Here is the ppc64 add-on for the HAVE_ARCH_GET_TB.

Thanks,
Jake


Attachments:
spinlock-timeout-2.6-v2-ppc64.patch (2.69 kB)

2004-06-11 15:52:05

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout


> Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow
> archs use their timebases if they have one, and if they don't, it uses
> jiffies. time_after_eq() is used to do the jiffy checking.
>
> I also left all of the arch/*/Kconfig changes in until a debug Kconfig
> is done. I pretty much added in the spinlock timeout on all archs that
> have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry.

Nah, that's not how the abstraction should be done. Much simpler in
fact. Just do something like this in the generic code:

#ifndef ARCH_HAS_SPINLOCK_TIMEOUT
#define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
#define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
#endif

That's all. Then, any arch who has it's own implementation of these 2
function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the
way it wants. We shouldn't let anything like get_tb() slip into a common
file, it's totally PPC specific. Other archs may have different counters
they can use to impement the same thing. That part should be entirely
self contained in asm-xxx

Ben.


2004-06-11 21:20:48

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

> > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow
> > archs use their timebases if they have one, and if they don't, it uses
> > jiffies. time_after_eq() is used to do the jiffy checking.
> >
> > I also left all of the arch/*/Kconfig changes in until a debug Kconfig
> > is done. I pretty much added in the spinlock timeout on all archs that
> > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry.
>
> Nah, that's not how the abstraction should be done. Much simpler in
> fact. Just do something like this in the generic code:
>
> #ifndef ARCH_HAS_SPINLOCK_TIMEOUT
> #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
> #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
> #endif
>
> That's all. Then, any arch who has it's own implementation of these 2
> function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the
> way it wants. We shouldn't let anything like get_tb() slip into a common
> file, it's totally PPC specific. Other archs may have different counters
> they can use to impement the same thing. That part should be entirely
> self contained in asm-xxx

That's much better. Here's hopefully a version that could be merged.

Thanks,
Jake

===== arch/alpha/Kconfig 1.37 vs edited =====
*** /tmp/Kconfig-1.37-23470 Tue May 18 10:22:12 2004
--- arch/alpha/Kconfig Fri Jun 11 10:56:36 2004
*************** config DEBUG_SPINLOCK
*** 664,669 ****
--- 664,683 ----
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_RWLOCK
bool "Read-write spinlock debugging"
depends on DEBUG_KERNEL
===== arch/alpha/defconfig 1.25 vs edited =====
*** /tmp/defconfig-1.25-23470 Tue Mar 23 12:24:34 2004
--- arch/alpha/defconfig Fri Jun 11 10:56:36 2004
*************** CONFIG_MATHEMU=y
*** 868,873 ****
--- 868,874 ----
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_DEBUG_RWLOCK is not set
# CONFIG_DEBUG_SEMAPHORE is not set
CONFIG_DEBUG_INFO=y
===== arch/arm/Kconfig 1.62 vs edited =====
*** /tmp/Kconfig-1.62-23470 Mon May 24 06:14:29 2004
--- arch/arm/Kconfig Fri Jun 11 10:56:37 2004
*************** config DEBUG_SPINLOCK
*** 728,733 ****
--- 728,747 ----
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_WAITQ
bool "Wait queue debugging"
depends on DEBUG_KERNEL
===== arch/arm/defconfig 1.5 vs edited =====
*** /tmp/defconfig-1.5-23470 Sat Aug 2 14:59:32 2003
--- arch/arm/defconfig Fri Jun 11 10:56:37 2004
*************** CONFIG_FRAME_POINTER=y
*** 507,511 ****
--- 507,512 ----
CONFIG_DEBUG_ERRORS=y
CONFIG_DEBUG_USER=y
# CONFIG_DEBUG_INFO is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_MAGIC_SYSRQ=y
CONFIG_DEBUG_LL=y
===== arch/arm26/Kconfig 1.12 vs edited =====
*** /tmp/Kconfig-1.12-23470 Sat Mar 13 05:47:59 2004
--- arch/arm26/Kconfig Fri Jun 11 10:56:37 2004
*************** config DEBUG_SPINLOCK
*** 284,289 ****
--- 284,303 ----
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_WAITQ
bool "Wait queue debugging"
depends on DEBUG_KERNEL
===== arch/arm26/defconfig 1.3 vs edited =====
*** /tmp/defconfig-1.3-23470 Thu Mar 25 11:57:00 2004
--- arch/arm26/defconfig Fri Jun 11 10:56:37 2004
*************** CONFIG_DEBUG_KERNEL=y
*** 344,349 ****
--- 344,350 ----
CONFIG_DEBUG_SLAB=y
CONFIG_MAGIC_SYSRQ=y
CONFIG_DEBUG_SPINLOCK=y
+ # CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_DEBUG_WAITQ=y
CONFIG_DEBUG_BUGVERBOSE=y
CONFIG_DEBUG_ERRORS=y
===== arch/i386/Kconfig 1.122 vs edited =====
*** /tmp/Kconfig-1.122-23470 Thu Jun 3 03:46:43 2004
--- arch/i386/Kconfig Fri Jun 11 10:56:38 2004
*************** config DEBUG_SPINLOCK
*** 1247,1252 ****
--- 1247,1266 ----
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_PAGEALLOC
bool "Page alloc debugging"
depends on DEBUG_KERNEL
===== arch/i386/defconfig 1.112 vs edited =====
*** /tmp/defconfig-1.112-23470 Mon Jun 7 08:29:17 2004
--- arch/i386/defconfig Fri Jun 11 10:56:38 2004
*************** CONFIG_OPROFILE=y
*** 1220,1225 ****
--- 1220,1226 ----
# CONFIG_DEBUG_KERNEL is not set
CONFIG_EARLY_PRINTK=y
CONFIG_DEBUG_SPINLOCK_SLEEP=y
+ # CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_FRAME_POINTER is not set
CONFIG_4KSTACKS=y
CONFIG_X86_FIND_SMP_CONFIG=y
===== arch/ia64/Kconfig 1.74 vs edited =====
*** /tmp/Kconfig-1.74-23470 Mon May 24 18:05:32 2004
--- arch/ia64/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK_SLEEP
*** 468,473 ****
--- 468,487 ----
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config IA64_DEBUG_CMPXCHG
bool "Turn on compare-and-exchange bug checking (slow!)"
depends on DEBUG_KERNEL
===== arch/ia64/defconfig 1.30 vs edited =====
*** /tmp/defconfig-1.30-23470 Fri May 21 16:03:19 2004
--- arch/ia64/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_MAGIC_SYSRQ=y
*** 1089,1094 ****
--- 1089,1095 ----
# CONFIG_DEBUG_SLAB is not set
# CONFIG_DEBUG_SPINLOCK is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_IA64_DEBUG_CMPXCHG is not set
# CONFIG_IA64_DEBUG_IRQ is not set
CONFIG_DEBUG_INFO=y
===== arch/mips/Kconfig 1.26 vs edited =====
*** /tmp/Kconfig-1.26-23470 Mon May 10 06:25:30 2004
--- arch/mips/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK_SLEEP
*** 1360,1365 ****
--- 1360,1379 ----
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config RTC_DS1742
bool "DS1742 BRAM/RTC support"
depends on TOSHIBA_JMR3927 || TOSHIBA_RBTX4927
===== arch/mips/defconfig 1.11 vs edited =====
*** /tmp/defconfig-1.11-23470 Mon May 10 06:25:30 2004
--- arch/mips/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_CPU_HAS_LLDSCD=y
*** 125,130 ****
--- 125,131 ----
CONFIG_CPU_HAS_SYNC=y
# CONFIG_PREEMPT is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set

#
# Bus options (PCI, PCMCIA, EISA, ISA, TC)
===== arch/ppc/Kconfig 1.64 vs edited =====
*** /tmp/Kconfig-1.64-23470 Mon May 31 07:28:12 2004
--- arch/ppc/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK_SLEEP
*** 1199,1204 ****
--- 1199,1218 ----
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config KGDB
bool "Include kgdb kernel debugger"
depends on DEBUG_KERNEL
===== arch/ppc/defconfig 1.28 vs edited =====
*** /tmp/defconfig-1.28-23470 Tue May 18 09:48:09 2004
--- arch/ppc/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_ZLIB_DEFLATE=y
*** 1318,1323 ****
--- 1318,1324 ----
# Kernel hacking
#
# CONFIG_DEBUG_KERNEL is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_BOOTX_TEXT=y

#
===== arch/ppc64/Kconfig 1.56 vs edited =====
*** /tmp/Kconfig-1.56-23470 Tue May 25 02:31:51 2004
--- arch/ppc64/Kconfig Fri Jun 11 10:56:39 2004
*************** config MAGIC_SYSRQ
*** 387,392 ****
--- 387,406 ----
keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
unless you really know what this hack does.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUGGER
bool "Enable debugger hooks"
depends on DEBUG_KERNEL
===== arch/ppc64/defconfig 1.37 vs edited =====
*** /tmp/defconfig-1.37-23470 Wed Mar 31 16:27:07 2004
--- arch/ppc64/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_DEBUG_STACKOVERFLOW=y
*** 1054,1059 ****
--- 1054,1060 ----
CONFIG_DEBUG_STACK_USAGE=y
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
+ # CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_DEBUGGER=y
CONFIG_XMON=y
CONFIG_XMON_DEFAULT=y
===== arch/s390/Kconfig 1.27 vs edited =====
*** /tmp/Kconfig-1.27-23470 Thu Apr 29 04:41:09 2004
--- arch/s390/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK_SLEEP
*** 423,428 ****
--- 423,442 ----
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
endmenu

source "security/Kconfig"
===== arch/s390/defconfig 1.45 vs edited =====
*** /tmp/defconfig-1.45-23470 Thu Jun 3 03:46:41 2004
--- arch/s390/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_MAGIC_SYSRQ=y
*** 474,479 ****
--- 474,480 ----
# CONFIG_DEBUG_SLAB is not set
# CONFIG_DEBUG_INFO is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set

#
# Security options
===== arch/sh/Kconfig 1.29 vs edited =====
*** /tmp/Kconfig-1.29-23470 Tue Mar 23 04:05:27 2004
--- arch/sh/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK
*** 675,680 ****
--- 675,694 ----
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config SH_STANDARD_BIOS
bool "Use LinuxSH standard BIOS"
help
===== arch/sh/defconfig 1.9 vs edited =====
*** /tmp/defconfig-1.9-23470 Tue Mar 23 12:18:46 2004
--- arch/sh/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_MSDOS_PARTITION=y
*** 351,356 ****
--- 351,357 ----
#
# CONFIG_MAGIC_SYSRQ is not set
# CONFIG_DEBUG_SPINLOCK is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_SH_STANDARD_BIOS=y
CONFIG_SH_EARLY_PRINTK=y
# CONFIG_KGDB is not set
===== arch/sparc/Kconfig 1.28 vs edited =====
*** /tmp/Kconfig-1.28-23470 Fri Mar 19 00:04:54 2004
--- arch/sparc/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK_SLEEP
*** 440,445 ****
--- 440,459 ----
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_BUGVERBOSE
bool "Verbose BUG() reporting (adds 70K)"
depends on DEBUG_KERNEL
===== arch/sparc/defconfig 1.19 vs edited =====
*** /tmp/defconfig-1.19-23470 Wed Mar 31 00:40:57 2004
--- arch/sparc/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_DEBUG_KERNEL=y
*** 611,616 ****
--- 611,617 ----
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_DEBUG_HIGHMEM is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
# CONFIG_DEBUG_BUGVERBOSE is not set
===== arch/sparc64/Kconfig 1.52 vs edited =====
*** /tmp/Kconfig-1.52-23470 Mon May 24 12:09:14 2004
--- arch/sparc64/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK_SLEEP
*** 658,663 ****
--- 658,677 ----
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_BUGVERBOSE
bool "Verbose BUG() reporting (adds 70K)"
depends on DEBUG_KERNEL
===== arch/sparc64/defconfig 1.128 vs edited =====
*** /tmp/defconfig-1.128-23470 Thu Jun 3 16:54:05 2004
--- arch/sparc64/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_DEBUG_KERNEL=y
*** 1727,1732 ****
--- 1727,1733 ----
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_DEBUG_BUGVERBOSE is not set
# CONFIG_DEBUG_DCFLUSH is not set
# CONFIG_DEBUG_INFO is not set
===== arch/um/Kconfig 1.14 vs edited =====
*** /tmp/Kconfig-1.14-23470 Mon Apr 12 12:53:57 2004
--- arch/um/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SLAB
*** 222,227 ****
--- 222,241 ----
config DEBUG_SPINLOCK
bool "Debug spinlocks usage"

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_INFO
bool "Enable kernel debugging symbols"
help
===== arch/um/defconfig 1.8 vs edited =====
*** /tmp/defconfig-1.8-23470 Fri Jun 20 15:19:15 2003
--- arch/um/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_MTD_BLKMTD=m
*** 399,404 ****
--- 399,405 ----
#
# CONFIG_DEBUG_SLAB is not set
# CONFIG_DEBUG_SPINLOCK is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_DEBUG_INFO=y
CONFIG_FRAME_POINTER=y
CONFIG_PT_PROXY=y
===== arch/x86_64/Kconfig 1.51 vs edited =====
*** /tmp/Kconfig-1.51-23470 Sat May 15 08:32:23 2004
--- arch/x86_64/Kconfig Fri Jun 11 10:56:39 2004
*************** config DEBUG_SPINLOCK
*** 436,441 ****
--- 436,455 ----
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+ config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+ config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
# !SMP for now because the context switch early causes GPF in segment reloading
# and the GS base checking does the wrong thing then, causing a hang.
config CHECKING
===== arch/x86_64/defconfig 1.39 vs edited =====
*** /tmp/defconfig-1.39-23470 Sat Jun 5 02:25:22 2004
--- arch/x86_64/defconfig Fri Jun 11 10:56:39 2004
*************** CONFIG_DEBUG_KERNEL=y
*** 910,915 ****
--- 910,916 ----
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
+ # CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_INIT_DEBUG is not set
# CONFIG_DEBUG_INFO is not set
# CONFIG_FRAME_POINTER is not set
===== include/linux/jiffies.h 1.9 vs edited =====
*** /tmp/jiffies.h-1.9-23470 Mon Dec 29 15:38:06 2003
--- include/linux/jiffies.h Fri Jun 11 10:56:40 2004
***************
*** 3,10 ****

#include <linux/kernel.h>
#include <linux/types.h>
- #include <linux/spinlock.h>
- #include <linux/seqlock.h>
#include <asm/system.h>
#include <asm/param.h> /* for HZ */

--- 3,8 ----
===== include/linux/spinlock.h 1.28 vs edited =====
*** /tmp/spinlock.h-1.28-23470 Mon May 10 06:25:44 2004
--- include/linux/spinlock.h Fri Jun 11 11:02:53 2004
***************
*** 38,43 ****
--- 38,62 ----
#ifdef CONFIG_SMP
#include <asm/spinlock.h>

+ #if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+ #include <linux/jiffies.h>
+
+ #define SPINLOCK_TIMEOUT CONFIG_SPINLOCK_TIMEOUT_TIME
+
+ /*
+ * There are paths where jiffies won't be updated and
+ * SPINLOCK_TIMEOUT will not work. To ensure they work, it is best
+ * to have every arch implement their own SPINLOCK_TIMEOUT routines
+ * that use hardware timers.
+ */
+ #ifndef ARCH_HAS_SPINLOCK_TIMEOUT
+ #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
+ #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
+ #endif /* !ARCH_HASH_SPINLOCK_TIMEOUT */
+
+ #endif /* CONFIG_SPINLOCK_TIMEOUT */
+
#else

#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
*************** do { \
*** 218,228 ****
--- 237,263 ----
} while (0)

#else
+ #if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+ static inline void spin_lock(spinlock_t * lock) {
+ unsigned long timeout = get_spinlock_timeout();
+
+ preempt_disable();
+ do {
+ if (check_spinlock_timeout(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 { \
===== kernel/sched.c 1.309 vs edited =====
*** /tmp/sched.c-1.309-23470 Sat Jun 5 19:00:00 2004
--- kernel/sched.c Fri Jun 11 10:56:40 2004
*************** EXPORT_SYMBOL(__might_sleep);
*** 3998,4011 ****
*/
void __sched __preempt_spin_lock(spinlock_t *lock)
{
if (preempt_count() > 1) {
_raw_spin_lock(lock);
return;
}
do {
preempt_enable();
! while (spin_is_locked(lock))
cpu_relax();
preempt_disable();
} while (!_raw_spin_trylock(lock));
}
--- 3998,4020 ----
*/
void __sched __preempt_spin_lock(spinlock_t *lock)
{
+ #if defined(CONFIG_SPINLOCK_TIMEOUT)
+ unsigned long timeout = get_spinlock_timeout();
+ #endif
+
if (preempt_count() > 1) {
_raw_spin_lock(lock);
return;
}
do {
preempt_enable();
! while (spin_is_locked(lock)) {
! #if defined(CONFIG_SPINLOCK_TIMEOUT)
! if (check_spinlock_timeout(timeout))
! BUG();
! #endif
cpu_relax();
+ }
preempt_disable();
} while (!_raw_spin_trylock(lock));
}

2004-06-11 21:23:22

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

> > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow
> > archs use their timebases if they have one, and if they don't, it uses
> > jiffies. time_after_eq() is used to do the jiffy checking.
> >
> > I also left all of the arch/*/Kconfig changes in until a debug Kconfig
> > is done. I pretty much added in the spinlock timeout on all archs that
> > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry.
>
> Nah, that's not how the abstraction should be done. Much simpler in
> fact. Just do something like this in the generic code:
>
> #ifndef ARCH_HAS_SPINLOCK_TIMEOUT
> #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
> #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
> #endif
>
> That's all. Then, any arch who has it's own implementation of these 2
> function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the
> way it wants. We shouldn't let anything like get_tb() slip into a common
> file, it's totally PPC specific. Other archs may have different counters
> they can use to impement the same thing. That part should be entirely
> self contained in asm-xxx

Here's the ppc64 add-on for using timebase register for the spinlock
timeout. If no one has any issues w/ the base spin-lock timeout patch, or
this one, please apply.

Thanks,
Jake

===== arch/ppc64/kernel/chrp_setup.c 1.47 vs edited =====
*** /tmp/chrp_setup.c-1.47-18066 Tue Apr 27 00:07:31 2004
--- arch/ppc64/kernel/chrp_setup.c Fri Jun 11 11:58:11 2004
*************** chrp_progress(char *s, unsigned short he
*** 405,414 ****

extern void setup_default_decr(void);

- /* Some sane defaults: 125 MHz timebase, 1GHz processor */
- #define DEFAULT_TB_FREQ 125000000UL
- #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
-
void __init pSeries_calibrate_decr(void)
{
struct device_node *cpu;
--- 405,410 ----
===== arch/ppc64/kernel/time.c 1.30 vs edited =====
*** /tmp/time.c-1.30-18066 Mon May 31 12:41:03 2004
--- arch/ppc64/kernel/time.c Fri Jun 11 14:19:48 2004
*************** static unsigned long first_settimeofday
*** 81,87 ****

#define XSEC_PER_SEC (1024*1024)

! unsigned long tb_ticks_per_jiffy;
unsigned long tb_ticks_per_usec;
unsigned long tb_ticks_per_sec;
unsigned long next_xtime_sync_tb;
--- 81,87 ----

#define XSEC_PER_SEC (1024*1024)

! unsigned long tb_ticks_per_jiffy = DEFAULT_TB_FREQ / HZ;
unsigned long tb_ticks_per_usec;
unsigned long tb_ticks_per_sec;
unsigned long next_xtime_sync_tb;
===== include/asm-ppc64/processor.h 1.45 vs edited =====
*** /tmp/processor.h-1.45-18066 Tue Jun 1 04:27:47 2004
--- include/asm-ppc64/processor.h Fri Jun 11 11:58:44 2004
*************** GLUE(.,name):
*** 440,445 ****
--- 440,448 ----

#endif /* __ASSEMBLY__ */

+ /* Some sane defaults: 125 MHz timebase, 1GHz processor */
+ #define DEFAULT_TB_FREQ 125000000UL
+ #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)

/* Macros for setting and retrieving special purpose registers */

===== include/asm-ppc64/spinlock.h 1.10 vs edited =====
*** /tmp/spinlock.h-1.10-18066 Tue May 25 04:53:02 2004
--- include/asm-ppc64/spinlock.h Fri Jun 11 14:30:57 2004
*************** static __inline__ void _raw_write_lock(r
*** 278,282 ****
--- 278,293 ----
}
#endif /* CONFIG_SPINLINE */

+ #ifdef CONFIG_SPINLOCK_TIMEOUT
+
+ #define ARCH_HAS_SPINLOCK_TIMEOUT
+
+ extern unsigned long tb_ticks_per_jiffy;
+
+ #define get_spinlock_timeout() (mftb() + (tb_ticks_per_jiffy * SPINLOCK_TIMEOUT * HZ))
+ #define check_spinlock_timeout(timeout) (mftb() >= timeout ? 1 : 0)
+
+ #endif /* CONFIG_SPINLOCK_TIMEOUT */
+
#endif /* __KERNEL__ */
#endif /* __ASM_SPINLOCK_H */

2004-06-11 22:12:24

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout


> Here's the ppc64 add-on for using timebase register for the spinlock
> timeout. If no one has any issues w/ the base spin-lock timeout patch, or
> this one, please apply.

Same comment, make sure you produce a unified diff.

Ben.


2004-06-11 22:12:22

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

On Fri, 2004-06-11 at 16:19, [email protected] wrote:
> > > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow
> > > archs use their timebases if they have one, and if they don't, it uses
> > > jiffies. time_after_eq() is used to do the jiffy checking.
> > >
> > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig
> > > is done. I pretty much added in the spinlock timeout on all archs that
> > > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry.
> >
> > Nah, that's not how the abstraction should be done. Much simpler in
> > fact. Just do something like this in the generic code:
> >
> > #ifndef ARCH_HAS_SPINLOCK_TIMEOUT
> > #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
> > #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
> > #endif
> >
> > That's all. Then, any arch who has it's own implementation of these 2
> > function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the
> > way it wants. We shouldn't let anything like get_tb() slip into a common
> > file, it's totally PPC specific. Other archs may have different counters
> > they can use to impement the same thing. That part should be entirely
> > self contained in asm-xxx
>
> That's much better. Here's hopefully a version that could be merged.

Hehe, almost ;) There's a bit of non-unified diff at the end ...

Ben.


2004-06-14 13:13:37

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

> On Fri, 2004-06-11 at 16:19, [email protected] wrote:
> > > > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow
> > > > archs use their timebases if they have one, and if they don't, it uses
> > > > jiffies. time_after_eq() is used to do the jiffy checking.
> > > >
> > > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig
> > > > is done. I pretty much added in the spinlock timeout on all archs that
> > > > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry.
> > >
> > > Nah, that's not how the abstraction should be done. Much simpler in
> > > fact. Just do something like this in the generic code:
> > >
> > > #ifndef ARCH_HAS_SPINLOCK_TIMEOUT
> > > #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
> > > #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
> > > #endif
> > >
> > > That's all. Then, any arch who has it's own implementation of these 2
> > > function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the
> > > way it wants. We shouldn't let anything like get_tb() slip into a common
> > > file, it's totally PPC specific. Other archs may have different counters
> > > they can use to impement the same thing. That part should be entirely
> > > self contained in asm-xxx
> >
> > That's much better. Here's hopefully a version that could be merged.
>
> Hehe, almost ;) There's a bit of non-unified diff at the end ...

Hmm...not sure how that extra -p option got in there. I did it twice!
Here's the unified version.

diff -Nru a/arch/alpha/Kconfig b/arch/alpha/Kconfig
--- a/arch/alpha/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/alpha/Kconfig Mon Jun 14 08:05:25 2004
@@ -664,6 +664,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_RWLOCK
bool "Read-write spinlock debugging"
depends on DEBUG_KERNEL
diff -Nru a/arch/alpha/defconfig b/arch/alpha/defconfig
--- a/arch/alpha/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/alpha/defconfig Mon Jun 14 08:05:25 2004
@@ -868,6 +868,7 @@
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_DEBUG_RWLOCK is not set
# CONFIG_DEBUG_SEMAPHORE is not set
CONFIG_DEBUG_INFO=y
diff -Nru a/arch/arm/Kconfig b/arch/arm/Kconfig
--- a/arch/arm/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/arm/Kconfig Mon Jun 14 08:05:25 2004
@@ -728,6 +728,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_WAITQ
bool "Wait queue debugging"
depends on DEBUG_KERNEL
diff -Nru a/arch/arm/defconfig b/arch/arm/defconfig
--- a/arch/arm/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/arm/defconfig Mon Jun 14 08:05:25 2004
@@ -507,5 +507,6 @@
CONFIG_DEBUG_ERRORS=y
CONFIG_DEBUG_USER=y
# CONFIG_DEBUG_INFO is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_MAGIC_SYSRQ=y
CONFIG_DEBUG_LL=y
diff -Nru a/arch/arm26/Kconfig b/arch/arm26/Kconfig
--- a/arch/arm26/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/arm26/Kconfig Mon Jun 14 08:05:25 2004
@@ -284,6 +284,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_WAITQ
bool "Wait queue debugging"
depends on DEBUG_KERNEL
diff -Nru a/arch/arm26/defconfig b/arch/arm26/defconfig
--- a/arch/arm26/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/arm26/defconfig Mon Jun 14 08:05:25 2004
@@ -344,6 +344,7 @@
CONFIG_DEBUG_SLAB=y
CONFIG_MAGIC_SYSRQ=y
CONFIG_DEBUG_SPINLOCK=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_DEBUG_WAITQ=y
CONFIG_DEBUG_BUGVERBOSE=y
CONFIG_DEBUG_ERRORS=y
diff -Nru a/arch/i386/Kconfig b/arch/i386/Kconfig
--- a/arch/i386/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/i386/Kconfig Mon Jun 14 08:05:25 2004
@@ -1247,6 +1247,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_PAGEALLOC
bool "Page alloc debugging"
depends on DEBUG_KERNEL
diff -Nru a/arch/i386/defconfig b/arch/i386/defconfig
--- a/arch/i386/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/i386/defconfig Mon Jun 14 08:05:25 2004
@@ -1220,6 +1220,7 @@
# CONFIG_DEBUG_KERNEL is not set
CONFIG_EARLY_PRINTK=y
CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_FRAME_POINTER is not set
CONFIG_4KSTACKS=y
CONFIG_X86_FIND_SMP_CONFIG=y
diff -Nru a/arch/ia64/Kconfig b/arch/ia64/Kconfig
--- a/arch/ia64/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/ia64/Kconfig Mon Jun 14 08:05:25 2004
@@ -468,6 +468,20 @@
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config IA64_DEBUG_CMPXCHG
bool "Turn on compare-and-exchange bug checking (slow!)"
depends on DEBUG_KERNEL
diff -Nru a/arch/ia64/defconfig b/arch/ia64/defconfig
--- a/arch/ia64/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/ia64/defconfig Mon Jun 14 08:05:25 2004
@@ -1089,6 +1089,7 @@
# CONFIG_DEBUG_SLAB is not set
# CONFIG_DEBUG_SPINLOCK is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_IA64_DEBUG_CMPXCHG is not set
# CONFIG_IA64_DEBUG_IRQ is not set
CONFIG_DEBUG_INFO=y
diff -Nru a/arch/mips/Kconfig b/arch/mips/Kconfig
--- a/arch/mips/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/mips/Kconfig Mon Jun 14 08:05:25 2004
@@ -1360,6 +1360,20 @@
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config RTC_DS1742
bool "DS1742 BRAM/RTC support"
depends on TOSHIBA_JMR3927 || TOSHIBA_RBTX4927
diff -Nru a/arch/mips/defconfig b/arch/mips/defconfig
--- a/arch/mips/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/mips/defconfig Mon Jun 14 08:05:25 2004
@@ -125,6 +125,7 @@
CONFIG_CPU_HAS_SYNC=y
# CONFIG_PREEMPT is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set

#
# Bus options (PCI, PCMCIA, EISA, ISA, TC)
diff -Nru a/arch/ppc/Kconfig b/arch/ppc/Kconfig
--- a/arch/ppc/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/ppc/Kconfig Mon Jun 14 08:05:25 2004
@@ -1199,6 +1199,20 @@
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config KGDB
bool "Include kgdb kernel debugger"
depends on DEBUG_KERNEL
diff -Nru a/arch/ppc/defconfig b/arch/ppc/defconfig
--- a/arch/ppc/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/ppc/defconfig Mon Jun 14 08:05:25 2004
@@ -1318,6 +1318,7 @@
# Kernel hacking
#
# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_BOOTX_TEXT=y

#
diff -Nru a/arch/ppc64/Kconfig b/arch/ppc64/Kconfig
--- a/arch/ppc64/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/ppc64/Kconfig Mon Jun 14 08:05:25 2004
@@ -387,6 +387,20 @@
keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
unless you really know what this hack does.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUGGER
bool "Enable debugger hooks"
depends on DEBUG_KERNEL
diff -Nru a/arch/ppc64/defconfig b/arch/ppc64/defconfig
--- a/arch/ppc64/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/ppc64/defconfig Mon Jun 14 08:05:25 2004
@@ -1054,6 +1054,7 @@
CONFIG_DEBUG_STACK_USAGE=y
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_DEBUGGER=y
CONFIG_XMON=y
CONFIG_XMON_DEFAULT=y
diff -Nru a/arch/s390/Kconfig b/arch/s390/Kconfig
--- a/arch/s390/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/s390/Kconfig Mon Jun 14 08:05:25 2004
@@ -423,6 +423,20 @@
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
endmenu

source "security/Kconfig"
diff -Nru a/arch/s390/defconfig b/arch/s390/defconfig
--- a/arch/s390/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/s390/defconfig Mon Jun 14 08:05:25 2004
@@ -474,6 +474,7 @@
# CONFIG_DEBUG_SLAB is not set
# CONFIG_DEBUG_INFO is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set

#
# Security options
diff -Nru a/arch/sh/Kconfig b/arch/sh/Kconfig
--- a/arch/sh/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/sh/Kconfig Mon Jun 14 08:05:25 2004
@@ -675,6 +675,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config SH_STANDARD_BIOS
bool "Use LinuxSH standard BIOS"
help
diff -Nru a/arch/sh/defconfig b/arch/sh/defconfig
--- a/arch/sh/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/sh/defconfig Mon Jun 14 08:05:25 2004
@@ -351,6 +351,7 @@
#
# CONFIG_MAGIC_SYSRQ is not set
# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_SH_STANDARD_BIOS=y
CONFIG_SH_EARLY_PRINTK=y
# CONFIG_KGDB is not set
diff -Nru a/arch/sparc/Kconfig b/arch/sparc/Kconfig
--- a/arch/sparc/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/sparc/Kconfig Mon Jun 14 08:05:25 2004
@@ -440,6 +440,20 @@
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_BUGVERBOSE
bool "Verbose BUG() reporting (adds 70K)"
depends on DEBUG_KERNEL
diff -Nru a/arch/sparc/defconfig b/arch/sparc/defconfig
--- a/arch/sparc/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/sparc/defconfig Mon Jun 14 08:05:25 2004
@@ -611,6 +611,7 @@
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_DEBUG_HIGHMEM is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
# CONFIG_DEBUG_BUGVERBOSE is not set
diff -Nru a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
--- a/arch/sparc64/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/sparc64/Kconfig Mon Jun 14 08:05:25 2004
@@ -658,6 +658,20 @@
If you say Y here, various routines which may sleep will become very
noisy if they are called with a spinlock held.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_BUGVERBOSE
bool "Verbose BUG() reporting (adds 70K)"
depends on DEBUG_KERNEL
diff -Nru a/arch/sparc64/defconfig b/arch/sparc64/defconfig
--- a/arch/sparc64/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/sparc64/defconfig Mon Jun 14 08:05:25 2004
@@ -1727,6 +1727,7 @@
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_DEBUG_BUGVERBOSE is not set
# CONFIG_DEBUG_DCFLUSH is not set
# CONFIG_DEBUG_INFO is not set
diff -Nru a/arch/um/Kconfig b/arch/um/Kconfig
--- a/arch/um/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/um/Kconfig Mon Jun 14 08:05:25 2004
@@ -222,6 +222,20 @@
config DEBUG_SPINLOCK
bool "Debug spinlocks usage"

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
config DEBUG_INFO
bool "Enable kernel debugging symbols"
help
diff -Nru a/arch/um/defconfig b/arch/um/defconfig
--- a/arch/um/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/um/defconfig Mon Jun 14 08:05:25 2004
@@ -399,6 +399,7 @@
#
# CONFIG_DEBUG_SLAB is not set
# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_DEBUG_INFO=y
CONFIG_FRAME_POINTER=y
CONFIG_PT_PROXY=y
diff -Nru a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
--- a/arch/x86_64/Kconfig Mon Jun 14 08:05:25 2004
+++ b/arch/x86_64/Kconfig Mon Jun 14 08:05:25 2004
@@ -436,6 +436,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.

+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout"
+ depends on DEBUG_KERNEL && SMP
+ help
+ If you say Y here, the spinlocks will timeout after X number
+ of seconds. This is useful for catching deadlocks, and make sure
+ locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+ int "Spinlock timeout time in seconds (1-43200)"
+ range 1 43200
+ depends on SPINLOCK_TIMEOUT
+ default "10"
+
# !SMP for now because the context switch early causes GPF in segment reloading
# and the GS base checking does the wrong thing then, causing a hang.
config CHECKING
diff -Nru a/arch/x86_64/defconfig b/arch/x86_64/defconfig
--- a/arch/x86_64/defconfig Mon Jun 14 08:05:25 2004
+++ b/arch/x86_64/defconfig Mon Jun 14 08:05:25 2004
@@ -910,6 +910,7 @@
# CONFIG_DEBUG_SLAB is not set
CONFIG_MAGIC_SYSRQ=y
# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
# CONFIG_INIT_DEBUG is not set
# CONFIG_DEBUG_INFO is not set
# CONFIG_FRAME_POINTER is not set
diff -Nru a/include/linux/jiffies.h b/include/linux/jiffies.h
--- a/include/linux/jiffies.h Mon Jun 14 08:05:25 2004
+++ b/include/linux/jiffies.h Mon Jun 14 08:05:25 2004
@@ -3,8 +3,6 @@

#include <linux/kernel.h>
#include <linux/types.h>
-#include <linux/spinlock.h>
-#include <linux/seqlock.h>
#include <asm/system.h>
#include <asm/param.h> /* for HZ */

diff -Nru a/include/linux/spinlock.h b/include/linux/spinlock.h
--- a/include/linux/spinlock.h Mon Jun 14 08:05:25 2004
+++ b/include/linux/spinlock.h Mon Jun 14 08:05:25 2004
@@ -38,6 +38,25 @@
#ifdef CONFIG_SMP
#include <asm/spinlock.h>

+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+#include <linux/jiffies.h>
+
+#define SPINLOCK_TIMEOUT CONFIG_SPINLOCK_TIMEOUT_TIME
+
+/*
+ * There are paths where jiffies won't be updated and
+ * SPINLOCK_TIMEOUT will not work. To ensure they work, it is best
+ * to have every arch implement their own SPINLOCK_TIMEOUT routines
+ * that use hardware timers.
+ */
+#ifndef ARCH_HAS_SPINLOCK_TIMEOUT
+#define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
+#define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
+#endif /* !ARCH_HASH_SPINLOCK_TIMEOUT */
+
+#endif /* CONFIG_SPINLOCK_TIMEOUT */
+
#else

#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
@@ -218,11 +237,27 @@
} while (0)

#else
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+static inline void spin_lock(spinlock_t * lock) {
+ unsigned long timeout = get_spinlock_timeout();
+
+ preempt_disable();
+ do {
+ if (check_spinlock_timeout(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 { \
diff -Nru a/kernel/sched.c b/kernel/sched.c
--- a/kernel/sched.c Mon Jun 14 08:05:25 2004
+++ b/kernel/sched.c Mon Jun 14 08:05:25 2004
@@ -3998,14 +3998,23 @@
*/
void __sched __preempt_spin_lock(spinlock_t *lock)
{
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+ unsigned long timeout = get_spinlock_timeout();
+#endif
+
if (preempt_count() > 1) {
_raw_spin_lock(lock);
return;
}
do {
preempt_enable();
- while (spin_is_locked(lock))
+ while (spin_is_locked(lock)) {
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+ if (check_spinlock_timeout(timeout))
+ BUG();
+#endif
cpu_relax();
+ }
preempt_disable();
} while (!_raw_spin_trylock(lock));
}

2004-06-14 13:14:12

by Jake Moilanen

[permalink] [raw]
Subject: Re: [PATCH][RFC] Spinlock-timeout

>
> > Here's the ppc64 add-on for using timebase register for the spinlock
> > timeout. If no one has any issues w/ the base spin-lock timeout patch, or
> > this one, please apply.
>
> Same comment, make sure you produce a unified diff.

Here's the unified ver.

diff -Nru a/arch/ppc64/kernel/chrp_setup.c b/arch/ppc64/kernel/chrp_setup.c
--- a/arch/ppc64/kernel/chrp_setup.c Mon Jun 14 08:07:11 2004
+++ b/arch/ppc64/kernel/chrp_setup.c Mon Jun 14 08:07:11 2004
@@ -405,10 +405,6 @@

extern void setup_default_decr(void);

-/* Some sane defaults: 125 MHz timebase, 1GHz processor */
-#define DEFAULT_TB_FREQ 125000000UL
-#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
-
void __init pSeries_calibrate_decr(void)
{
struct device_node *cpu;
diff -Nru a/arch/ppc64/kernel/time.c b/arch/ppc64/kernel/time.c
--- a/arch/ppc64/kernel/time.c Mon Jun 14 08:07:11 2004
+++ b/arch/ppc64/kernel/time.c Mon Jun 14 08:07:11 2004
@@ -81,7 +81,7 @@

#define XSEC_PER_SEC (1024*1024)

-unsigned long tb_ticks_per_jiffy;
+unsigned long tb_ticks_per_jiffy = DEFAULT_TB_FREQ / HZ;
unsigned long tb_ticks_per_usec;
unsigned long tb_ticks_per_sec;
unsigned long next_xtime_sync_tb;
diff -Nru a/include/asm-ppc64/processor.h b/include/asm-ppc64/processor.h
--- a/include/asm-ppc64/processor.h Mon Jun 14 08:07:11 2004
+++ b/include/asm-ppc64/processor.h Mon Jun 14 08:07:11 2004
@@ -440,6 +440,9 @@

#endif /* __ASSEMBLY__ */

+/* Some sane defaults: 125 MHz timebase, 1GHz processor */
+#define DEFAULT_TB_FREQ 125000000UL
+#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)

/* Macros for setting and retrieving special purpose registers */

diff -Nru a/include/asm-ppc64/spinlock.h b/include/asm-ppc64/spinlock.h
--- a/include/asm-ppc64/spinlock.h Mon Jun 14 08:07:11 2004
+++ b/include/asm-ppc64/spinlock.h Mon Jun 14 08:07:11 2004
@@ -278,5 +278,16 @@
}
#endif /* CONFIG_SPINLINE */

+#ifdef CONFIG_SPINLOCK_TIMEOUT
+
+#define ARCH_HAS_SPINLOCK_TIMEOUT
+
+extern unsigned long tb_ticks_per_jiffy;
+
+#define get_spinlock_timeout() (mftb() + (tb_ticks_per_jiffy * SPINLOCK_TIMEOUT * HZ))
+#define check_spinlock_timeout(timeout) (mftb() >= timeout ? 1 : 0)
+
+#endif /* CONFIG_SPINLOCK_TIMEOUT */
+
#endif /* __KERNEL__ */
#endif /* __ASM_SPINLOCK_H */