2004-01-16 13:42:35

by Prashanth T

[permalink] [raw]
Subject: [PATCH] rwlock_is_locked undefined for UP systems

diff -urN linux-2.6.1/include/linux/spinlock.h linux-2.6.1-rwlock-patch/include/linux/spinlock.h
--- linux-2.6.1/include/linux/spinlock.h 2004-01-09 12:29:33.000000000 +0530
+++ linux-2.6.1-rwlock-patch/include/linux/spinlock.h 2004-01-16 18:15:10.000000000 +0530
@@ -176,6 +176,7 @@
#endif

#define rwlock_init(lock) do { (void)(lock); } while(0)
+#define rwlock_is_locked(lock) ((void)(lock), 0)
#define _raw_read_lock(lock) do { (void)(lock); } while(0)
#define _raw_read_unlock(lock) do { (void)(lock); } while(0)
#define _raw_write_lock(lock) do { (void)(lock); } while(0)


Attachments:
rwlock-check-UP.patch (585.00 B)

2004-01-16 13:56:19

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] rwlock_is_locked undefined for UP systems

On Fri, 2004-01-16 at 14:45, Prashanth T wrote:
> Hi,
> I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
> this routine to be undefined for UP. I have attached the patch for 2.6.1
> below to return 0 for rwlock_is_locked( ) on UP systems.
> Please let me know.

I consider any user of this on UP to be broken, just like UP use of
spin_is_locked() is always a bug..... better a compiletime bug than a
runtime bug I guess...


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2004-01-16 14:09:42

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] rwlock_is_locked undefined for UP systems

On Fri, Jan 16, 2004 at 07:15:11PM +0530, Prashanth T wrote:
> Hi,
> I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
> this routine to be undefined for UP. I have attached the patch for 2.6.1
> below to return 0 for rwlock_is_locked( ) on UP systems.
> Please let me know.

we don't implement spin_is_locked on UP either because there's no really
usefull return value. The lock will never be taken on !SMP && !PREEMPT,
but OTOH it's also not needed, so any assert on will give false results.
And the assert is probably the only thing that the _is_locked routines
could used for sanely.

2004-01-16 14:53:12

by Joe Thornber

[permalink] [raw]
Subject: Re: [PATCH] rwlock_is_locked undefined for UP systems

On Fri, Jan 16, 2004 at 02:55:50PM +0100, Arjan van de Ven wrote:
> On Fri, 2004-01-16 at 14:45, Prashanth T wrote:
> > Hi,
> > I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
> > this routine to be undefined for UP. I have attached the patch for 2.6.1
> > below to return 0 for rwlock_is_locked( ) on UP systems.
> > Please let me know.
>
> I consider any user of this on UP to be broken, just like UP use of
> spin_is_locked() is always a bug..... better a compiletime bug than a
> runtime bug I guess...

Then maybe a #error explaining this is in order ?

- Joe


2004-01-16 15:14:17

by Nikita Danilov

[permalink] [raw]
Subject: Re: [PATCH] rwlock_is_locked undefined for UP systems

Joe Thornber writes:
> On Fri, Jan 16, 2004 at 02:55:50PM +0100, Arjan van de Ven wrote:
> > On Fri, 2004-01-16 at 14:45, Prashanth T wrote:
> > > Hi,
> > > I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
> > > this routine to be undefined for UP. I have attached the patch for 2.6.1
> > > below to return 0 for rwlock_is_locked( ) on UP systems.
> > > Please let me know.
> >
> > I consider any user of this on UP to be broken, just like UP use of
> > spin_is_locked() is always a bug..... better a compiletime bug than a
> > runtime bug I guess...
>
> Then maybe a #error explaining this is in order ?

So, if there is a function

void foo_locked(struct bar *obj)
{
/* check that we are called with obj's lock held */
BUG_ON(!rwlock_is_locked(&obj->lock));
/* proceed with obj. */
}

it should now be changed to the

void foo_locked(struct bar *obj)
{
#ifdef CONFIG_SMP
BUG_ON(!rwlock_is_locked(&obj->lock));
#endif
/* proceed with obj. */
}

?

>
> - Joe
>

Nikita.

>

2004-01-16 18:11:50

by Mike Fedyk

[permalink] [raw]
Subject: Re: [PATCH] rwlock_is_locked undefined for UP systems

On Fri, Jan 16, 2004 at 06:14:06PM +0300, Nikita Danilov wrote:
> it should now be changed to the
>
> void foo_locked(struct bar *obj)
> {
> #ifdef CONFIG_SMP
> BUG_ON(!rwlock_is_locked(&obj->lock));
> #endif
> /* proceed with obj. */
> }

You forgot preempt... ;)

2004-01-19 06:10:20

by Prashanth T

[permalink] [raw]
Subject: Re: [PATCH] rwlock_is_locked undefined for UP systems

ok....I understand that rwlock_is_locked( ) is to be protected by
CONFIG_SMP. But I was tempted when I saw spin_is_locked( )
to be returning zero for !SMP in include/linux/spinlock.h .
Am I seeing something wrong here?

Christoph Hellwig wrote:

>On Fri, Jan 16, 2004 at 07:15:11PM +0530, Prashanth T wrote:
>
>
>>Hi,
>> I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
>>this routine to be undefined for UP. I have attached the patch for 2.6.1
>>below to return 0 for rwlock_is_locked( ) on UP systems.
>>Please let me know.
>>
>>
>
>we don't implement spin_is_locked on UP either because there's no really
>usefull return value. The lock will never be taken on !SMP && !PREEMPT,
>but OTOH it's also not needed, so any assert on will give false results.
>And the assert is probably the only thing that the _is_locked routines
>could used for sanely.
>
>
>
>