spin_is_locked() broken for uniprocessor?

8 messages, 7 authors, 2009-08-27 · open the first message on its own page

spin_is_locked() broken for uniprocessor?

From: Kumar Gala <hidden>
Date: 2009-08-18 22:10:15

I just want to validate that what I'm seeing (for UP, non-debug  
features):

spin_is_locked() is defined as:

include/linux/spinlock.h:#define spin_is_locked(lock)    
__raw_spin_is_locked(&(lock)->raw_lock)

for UP that should get us:

include/linux/spinlock_up.h:#define __raw_spin_is_locked(lock)  ((void) 
(lock), 0)

which implies to me that spin_is_locked() will always return false.   
Is this expected behavior.

- k

Re: spin_is_locked() broken for uniprocessor?

From: Thomas Gleixner <hidden>
Date: 2009-08-18 22:24:36

On Tue, 18 Aug 2009, Kumar Gala wrote:
I just want to validate that what I'm seeing (for UP, non-debug features):

spin_is_locked() is defined as:

include/linux/spinlock.h:#define spin_is_locked(lock)
__raw_spin_is_locked(&(lock)->raw_lock)

for UP that should get us:

include/linux/spinlock_up.h:#define __raw_spin_is_locked(lock)  ((void)(lock),
0)

which implies to me that spin_is_locked() will always return false.  Is this
expected behavior.
That's wrong. spin_is_locked should always return true on UP.

Thanks,

	tglx

Re: spin_is_locked() broken for uniprocessor?

From: David Howells <dhowells@redhat.com>
Date: 2009-08-19 09:38:49

Thomas Gleixner [off-list ref] wrote:
quoted
which implies to me that spin_is_locked() will always return false.  Is this
expected behavior.
That's wrong. spin_is_locked should always return true on UP.
Surely it's not that simple?  Maybe spin_is_lock() should be undefined on UP.

David

Re: spin_is_locked() broken for uniprocessor?

From: Peter Zijlstra <peterz@infradead.org>
Date: 2009-08-19 09:41:23

On Wed, 2009-08-19 at 10:38 +0100, David Howells wrote:
Thomas Gleixner [off-list ref] wrote:
quoted
quoted
which implies to me that spin_is_locked() will always return false.  Is this
expected behavior.
That's wrong. spin_is_locked should always return true on UP.
Surely it's not that simple?  Maybe spin_is_lock() should be undefined on UP.
#define spin_is_locked(l) panic()

should sort things out quickly ;-)

Re: spin_is_locked() broken for uniprocessor?

From: Alan Cox <hidden>
Date: 2009-08-19 10:52:47

On Wed, 19 Aug 2009 10:38:06 +0100
David Howells [off-list ref] wrote:
Thomas Gleixner [off-list ref] wrote:
quoted
quoted
which implies to me that spin_is_locked() will always return false.  Is this
expected behavior.
That's wrong. spin_is_locked should always return true on UP.
Surely it's not that simple?  Maybe spin_is_lock() should be undefined on UP.
That would lead to a lot of

#ifdef CONFIG_SMP

#endif

in drivers because there is driver code that uses spin_is_locked() in
fairly sensible fashion when dealing with locking.

Re: spin_is_locked() broken for uniprocessor?

From: Leon Woestenberg <hidden>
Date: 2009-08-19 11:16:49

Hello,

On Wed, Aug 19, 2009 at 12:53 PM, Alan Cox[off-list ref] wrote:
On Wed, 19 Aug 2009 10:38:06 +0100

in drivers because there is driver code that uses spin_is_locked() in
fairly sensible fashion when dealing with locking.
One use is to measure lock contention hits on a particular spin lock.


However I wonder if there are tracing capabilities to measure lock
contention on a particular lock?

Currently I have inserted code much like this to get a feeling on the
contention:

this_cpu = get_cpu();
put_cpu();
contention = spin_is_locked(&lock);
spin_lock*(&lock);
if (contention) {
  /* spin lock was contended, prev_cpu, this_cpu */
  /* no hard guarantee, as we had a possible race inbetween
is_locked() and lock(), but works for driver/irq spin lock */
}

/* critical section */

prev_cpu = this_cpu;
spin_unlock*(&lock);

Regards,
-- 
Leon

Re: spin_is_locked() broken for uniprocessor?

From: Peter Zijlstra <peterz@infradead.org>
Date: 2009-08-19 11:23:32

On Wed, 2009-08-19 at 13:16 +0200, Leon Woestenberg wrote:
Hello,

On Wed, Aug 19, 2009 at 12:53 PM, Alan Cox[off-list ref] wrote:
quoted
On Wed, 19 Aug 2009 10:38:06 +0100

in drivers because there is driver code that uses spin_is_locked() in
fairly sensible fashion when dealing with locking.
One use is to measure lock contention hits on a particular spin lock.


However I wonder if there are tracing capabilities to measure lock
contention on a particular lock?
lock_stat no good for you?

Re: spin_is_locked() broken for uniprocessor?

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: 2009-08-27 09:33:17

On Wed, 2009-08-19 at 11:41 +0200, Peter Zijlstra wrote:
quoted
quoted
quoted
which implies to me that spin_is_locked() will always return
false.  Is this
quoted
quoted
quoted
expected behavior.
That's wrong. spin_is_locked should always return true on UP.
Surely it's not that simple?  Maybe spin_is_lock() should be
undefined on UP.

#define spin_is_locked(l) panic()

should sort things out quickly ;-)
Not defining it would sort things out even faster and avoid nasty case
of system panic'ing when a module is loaded :-)

Cheers,
Ben.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help