2005-03-11 00:15:58

by Jody McIntyre

[permalink] [raw]
Subject: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

parisc and frv define sem_getcount() in semaphore.h, which returns the
current semaphore value. This is cleaner than doing
atomic_read(&semaphore.count), currently done in
drivers/ieee1394/nodemgr.c and fs/xfs/linux-2.6/xfs_buf.c, and will work
on all architectures if sem_getcount() is added.

This patch adds sem_getcount(). I will also send patches that convert
ieee1394 and xfs to use sem_getcount(), which fixes a warning on parisc
(and presumably frv.)

Any objections?

Jody

--

Adds sem_getcount() to architectures that were missing it. Renames
sema_count on arm for this purpose (sema_count has no current callers.)

Tested on i386, ia64, parisc.

Signed-off-by: Jody McIntyre <[email protected]>

Index: 1394-dev/include/asm-h8300/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-h8300/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-h8300/semaphore.h 2005-03-08 16:38:06.000000000 -0500
@@ -59,6 +59,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-sh64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sh64/semaphore.h 2005-02-10 12:39:41.000000000 -0500
+++ 1394-dev/include/asm-sh64/semaphore.h 2005-03-08 16:42:14.000000000 -0500
@@ -72,6 +72,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
#if 0
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
Index: 1394-dev/include/asm-m68knommu/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m68knommu/semaphore.h 2005-02-10 12:39:29.000000000 -0500
+++ 1394-dev/include/asm-m68knommu/semaphore.h 2005-03-08 16:39:18.000000000 -0500
@@ -59,6 +59,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-m32r/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m32r/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-m32r/semaphore.h 2005-03-08 16:38:26.000000000 -0500
@@ -64,6 +64,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-ia64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ia64/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-ia64/semaphore.h 2005-03-08 16:38:21.000000000 -0500
@@ -50,6 +50,11 @@ init_MUTEX_LOCKED (struct semaphore *sem
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void __down (struct semaphore * sem);
extern int __down_interruptible (struct semaphore * sem);
extern int __down_trylock (struct semaphore * sem);
Index: 1394-dev/include/asm-i386/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-i386/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-i386/semaphore.h 2005-03-08 16:13:56.000000000 -0500
@@ -87,6 +87,13 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+typedef atomic_t semcount_t;
+
+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
fastcall void __down_failed(void /* special register calling convention */);
fastcall int __down_failed_interruptible(void /* params in registers */);
fastcall int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-sparc/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sparc/semaphore.h 2005-02-10 12:39:41.000000000 -0500
+++ 1394-dev/include/asm-sparc/semaphore.h 2005-03-08 16:42:37.000000000 -0500
@@ -48,6 +48,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern int __down_trylock(struct semaphore * sem);
Index: 1394-dev/include/asm-x86_64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-x86_64/semaphore.h 2005-02-10 12:39:41.000000000 -0500
+++ 1394-dev/include/asm-x86_64/semaphore.h 2005-03-08 16:43:23.000000000 -0500
@@ -88,6 +88,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-ppc/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ppc/semaphore.h 2005-02-10 12:39:40.000000000 -0500
+++ 1394-dev/include/asm-ppc/semaphore.h 2005-03-08 16:41:22.000000000 -0500
@@ -62,6 +62,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
Index: 1394-dev/include/asm-ppc64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ppc64/semaphore.h 2005-02-10 12:39:40.000000000 -0500
+++ 1394-dev/include/asm-ppc64/semaphore.h 2005-03-08 16:41:32.000000000 -0500
@@ -56,6 +56,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
Index: 1394-dev/include/asm-arm26/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-arm26/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-arm26/semaphore.h 2005-03-08 16:36:37.000000000 -0500
@@ -51,6 +51,11 @@ static inline void init_MUTEX_LOCKED(str
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
/*
* special register calling convention
*/
Index: 1394-dev/include/asm-s390/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-s390/semaphore.h 2005-02-10 12:39:40.000000000 -0500
+++ 1394-dev/include/asm-s390/semaphore.h 2005-03-08 16:41:41.000000000 -0500
@@ -53,6 +53,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
asmlinkage void __down(struct semaphore * sem);
asmlinkage int __down_interruptible(struct semaphore * sem);
asmlinkage int __down_trylock(struct semaphore * sem);
Index: 1394-dev/include/asm-m68k/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m68k/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-m68k/semaphore.h 2005-03-08 16:39:10.000000000 -0500
@@ -60,6 +60,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-arm/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-arm/semaphore.h 2005-02-10 12:39:27.000000000 -0500
+++ 1394-dev/include/asm-arm/semaphore.h 2005-03-08 16:36:00.000000000 -0500
@@ -49,7 +49,7 @@ static inline void init_MUTEX_LOCKED(str
sema_init(sem, 0);
}

-static inline int sema_count(struct semaphore *sem)
+static inline int sem_getcount(struct semaphore *sem)
{
return atomic_read(&sem->count);
}
Index: 1394-dev/include/asm-sparc64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sparc64/semaphore.h 2005-02-10 12:39:41.000000000 -0500
+++ 1394-dev/include/asm-sparc64/semaphore.h 2005-03-08 16:42:51.000000000 -0500
@@ -47,6 +47,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void up(struct semaphore *sem);
extern void down(struct semaphore *sem);
extern int down_trylock(struct semaphore *sem);
Index: 1394-dev/include/asm-sh/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sh/semaphore.h 2005-02-10 12:39:40.000000000 -0500
+++ 1394-dev/include/asm-sh/semaphore.h 2005-03-08 16:42:04.000000000 -0500
@@ -65,6 +65,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
#if 0
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
Index: 1394-dev/include/asm-mips/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-mips/semaphore.h 2005-02-10 12:39:29.000000000 -0500
+++ 1394-dev/include/asm-mips/semaphore.h 2005-03-08 16:39:31.000000000 -0500
@@ -70,6 +70,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
Index: 1394-dev/include/asm-alpha/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-alpha/semaphore.h 2005-02-10 12:39:27.000000000 -0500
+++ 1394-dev/include/asm-alpha/semaphore.h 2005-03-08 16:13:47.000000000 -0500
@@ -57,6 +57,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem.count);
+}
+
extern void down(struct semaphore *);
extern void __down_failed(struct semaphore *);
extern int down_interruptible(struct semaphore *);
Index: 1394-dev/include/asm-cris/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-cris/semaphore.h 2005-02-10 12:39:28.000000000 -0500
+++ 1394-dev/include/asm-cris/semaphore.h 2005-03-08 16:37:12.000000000 -0500
@@ -57,6 +57,11 @@ extern inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern int __down_trylock(struct semaphore * sem);
Index: 1394-dev/include/asm-v850/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-v850/semaphore.h 2005-02-10 12:39:41.000000000 -0500
+++ 1394-dev/include/asm-v850/semaphore.h 2005-03-08 16:43:13.000000000 -0500
@@ -42,6 +42,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init (sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count);
+}
+
/*
* special register calling convention
*/
--


2005-03-11 00:15:28

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 2/3] Use sem_getcount in ieee1394


Convert 1394's node manager to use sem_getcount instead of nasty hack.
Tested on parisc (where it eliminates a warning), ia64, i386.

Signed-off-by: Jody McIntyre <[email protected]>

Index: 1394-dev/drivers/ieee1394/nodemgr.c
===================================================================
--- 1394-dev.orig/drivers/ieee1394/nodemgr.c 2005-03-08 16:50:40.000000000 -0500
+++ 1394-dev/drivers/ieee1394/nodemgr.c 2005-03-08 16:51:07.000000000 -0500
@@ -284,7 +284,7 @@ static DEVICE_ATTR(bus_options,S_IRUGO,f
static ssize_t fw_show_ne_tlabels_free(struct device *dev, char *buf)
{
struct node_entry *ne = container_of(dev, struct node_entry, device);
- return sprintf(buf, "%d\n", atomic_read(&ne->tpool->count.count) + 1);
+ return sprintf(buf, "%d\n", sem_getcount(&ne->tpool->count) + 1);
}
static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL);

2005-03-11 00:17:19

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 3/3] Use sem_getcount in xfs


Convert XFS to use sem_getcount instead of nasty hack. Should fix warning
with XFS debugging on PARISC. Untested since there is no obvious way to
turn on XFS debugging.

Signed-off-by: Jody McIntyre <[email protected]>

Index: 1394-dev/fs/xfs/linux-2.6/xfs_buf.c
===================================================================
--- 1394-dev.orig/fs/xfs/linux-2.6/xfs_buf.c 2005-03-10 18:20:13.000000000 -0500
+++ 1394-dev/fs/xfs/linux-2.6/xfs_buf.c 2005-03-10 18:20:55.000000000 -0500
@@ -976,7 +976,7 @@ int
pagebuf_lock_value(
xfs_buf_t *pb)
{
- return(atomic_read(&pb->pb_sema.count));
+ return(sem_getcount(&pb->pb_sema));
}
#endif

2005-03-11 04:55:55

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

Jody McIntyre <[email protected]> wrote:
>
> parisc and frv define sem_getcount() in semaphore.h, which returns the
> current semaphore value. This is cleaner than doing
> atomic_read(&semaphore.count), currently done in
> drivers/ieee1394/nodemgr.c and fs/xfs/linux-2.6/xfs_buf.c, and will work
> on all architectures if sem_getcount() is added.

That's a fairly bizarre thing to want to do. Would it be hard to modify
xfs and 1394 to stop wanting to read a semaphore's up() count?

(Why do they want to do this anyway?)

2005-03-11 05:10:47

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

Andrew> (Why do they want to do this anyway?)

Neither use seems really fundamental. The XFS use is explicitly
inside #ifdef DEBUG and seems to be used only for assertions.
ieee1394 is just sticking the value in a read-only sysfs attribute.

- R.

2005-03-11 05:19:21

by Nathan Scott

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

On Thu, Mar 10, 2005 at 09:10:42PM -0800, Roland Dreier wrote:
> Andrew> (Why do they want to do this anyway?)
>
> Neither use seems really fundamental. The XFS use is explicitly
> inside #ifdef DEBUG and seems to be used only for assertions.

Right, our peeking at that value is debug-only (so usually its not
even compiled in). I wouldn't go out of your way to add a more
permanent interface just for this, we can live without it.

cheers.

--
Nathan

2005-03-11 05:39:27

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

On Thu, Mar 10, 2005 at 08:55:03PM -0800, Andrew Morton wrote:
> Jody McIntyre <[email protected]> wrote:
> >
> > parisc and frv define sem_getcount() in semaphore.h, which returns the
> > current semaphore value. This is cleaner than doing
> > atomic_read(&semaphore.count), currently done in
> > drivers/ieee1394/nodemgr.c and fs/xfs/linux-2.6/xfs_buf.c, and will work
> > on all architectures if sem_getcount() is added.
>
> That's a fairly bizarre thing to want to do. Would it be hard to modify
> xfs and 1394 to stop wanting to read a semaphore's up() count?

The count is the number of free transaction labels (1394 async is
transaction-based) and is initialized to 64. When a new transaction label
is needed, the requestor does a down(), then locks the tlabel variables
and allocates a new one. When a transaction label is freed, an up()
occurs. The semaphore's up() count is therefore the number of free
tlabels, and the number of outstanding transactions is (64 - count). I
can imagine situations in which this would be a useful statistic, but
I'm not sure any of them actually exist.

I haven't investigated xfs, but modifying 1394 would be fairly easy. I
could add a second variable that tracks the up() count, or just drop the
sysfs attribute that reports the number. The first option seems a bit
wasteful, but only slightly. I thought this patch was worthwhile based
on xfs wanting to do this and 3 arches already having (unused)
implementations of sem_getcount/sema_count.

If this patch isn't accepted, we should get rid of the xfs and 1394
hacks and delete sem_getcount (parisc, frv) and sema_count (arm) as they
are unused.

Jody

>
> (Why do they want to do this anyway?)

--

2005-03-11 05:57:36

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

Jody McIntyre <[email protected]> wrote:
>
> On Thu, Mar 10, 2005 at 08:55:03PM -0800, Andrew Morton wrote:
> > Jody McIntyre <[email protected]> wrote:
> > >
> > > parisc and frv define sem_getcount() in semaphore.h, which returns the
> > > current semaphore value. This is cleaner than doing
> > > atomic_read(&semaphore.count), currently done in
> > > drivers/ieee1394/nodemgr.c and fs/xfs/linux-2.6/xfs_buf.c, and will work
> > > on all architectures if sem_getcount() is added.
> >
> > That's a fairly bizarre thing to want to do. Would it be hard to modify
> > xfs and 1394 to stop wanting to read a semaphore's up() count?
>
> The count is the number of free transaction labels (1394 async is
> transaction-based) and is initialized to 64. When a new transaction label
> is needed, the requestor does a down(), then locks the tlabel variables
> and allocates a new one. When a transaction label is freed, an up()
> occurs. The semaphore's up() count is therefore the number of free
> tlabels, and the number of outstanding transactions is (64 - count). I
> can imagine situations in which this would be a useful statistic, but
> I'm not sure any of them actually exist.

That's a nice application of semaphores. I can see that there's also a
need to be able to read the value back for reporting purposes. Dang.

But I guess it's a bit hard to justify adding more infrastructure to
support a single callsite which has a simple alternative. So if you could
please add the separate counter?

> ...
>
> If this patch isn't accepted, we should get rid of the xfs and 1394
> hacks and delete sem_getcount (parisc, frv) and sema_count (arm) as they
> are unused.

True.

2005-03-11 12:28:15

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

On Thu, Mar 10, 2005 at 09:56:52PM -0800, Andrew Morton wrote:
> That's a nice application of semaphores. I can see that there's also a
> need to be able to read the value back for reporting purposes. Dang.
>
> But I guess it's a bit hard to justify adding more infrastructure to
> support a single callsite which has a simple alternative. So if you could
> please add the separate counter?

It's pretty *small* infrastructure, and it gives me something to whine at
people about when they use atomic_read on something that isn't an atomic.

> > ...
> >
> > If this patch isn't accepted, we should get rid of the xfs and 1394
> > hacks and delete sem_getcount (parisc, frv) and sema_count (arm) as they
> > are unused.
>
> True.

If we are going to get rid of sem_getcount, could we rename the 'count'
variables, at least on i386 and ppc to make it clear that you're not
supposed to do this ... maybe to 'count_$ARCH'?

--
"Next the statesmen will invent cheap lies, putting the blame upon
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince
himself that the war is just, and will thank God for the better sleep
he enjoys after this process of grotesque self-deception." -- Mark Twain

2005-03-11 17:07:55

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 1/3] Add sem_getcount() to arches that lack it

On Fri, Mar 11, 2005 at 12:27:47PM +0000, Matthew Wilcox wrote:

> > But I guess it's a bit hard to justify adding more infrastructure to
> > support a single callsite which has a simple alternative. So if you could
> > please add the separate counter?
>
> It's pretty *small* infrastructure, and it gives me something to whine at
> people about when they use atomic_read on something that isn't an atomic.

Agreed, but I don't mind adding a separate counter. However...

> If we are going to get rid of sem_getcount, could we rename the 'count'
> variables, at least on i386 and ppc to make it clear that you're not
> supposed to do this ... maybe to 'count_$ARCH'?

I'm working on a patch to do just that. It fails when building XFS:

fs/xfs/xfs_inode_item.c: In function `xfs_inode_item_pushbuf':
fs/xfs/xfs_inode_item.c:803: error: structure has no member named `count'
fs/xfs/xfs_inode_item.c:825: error: structure has no member named `count'

fs/xfs/linux-2.6/sema.h:
#define valusema(sp) (atomic_read(&(sp)->count))

It seems getting the value of a semaphore is more common than it appears
at first glance. I don't see how this code could possibly work on
parisc. Therefore I propose:

1. Adding sem_getcount() everywhere, as in my original patch.
2. Renaming count to count_$ARCH as willy suggested.
3. Anyone who abuses semaphores will now break. Fix them to use
sem_getcount().

I'll work on that over the weekend unless anyone has any better ideas.

Jody


>
> --
> "Next the statesmen will invent cheap lies, putting the blame upon
> the nation that is attacked, and every man will be glad of those
> conscience-soothing falsities, and will diligently study them, and refuse
> to examine any refutations of them; and thus he will by and by convince
> himself that the war is just, and will thank God for the better sleep
> he enjoys after this process of grotesque self-deception." -- Mark Twain

--

2005-03-16 19:33:51

by Jody McIntyre

[permalink] [raw]
Subject: [PATCH, RFC 1/4] Rename semaphore count variable to be arch specific

On Fri, Mar 11, 2005 at 12:04:49PM -0500, Jody McIntyre wrote:

> Therefore I propose:
>
> 1. Adding sem_getcount() everywhere, as in my original patch.
> 2. Renaming count to count_$ARCH as willy suggested.
> 3. Anyone who abuses semaphores will now break. Fix them to use
> sem_getcount().

OK, here it is. Tested 3. with 'make allyesconfig' on i386 to be sure
I've caught all abuses.

--

Rename semaphore "count" members to count_$ARCH, to emphasize that this is
an opaque type and sem_getcount() should be used to retrieve the current
up() count.

Tested on i386, ia64, parisc. More testing would be good.

Signed-off-by: Jody McIntyre <[email protected]>

arch/sparc64/kernel/semaphore.c | 36 ++++++++++++++++++------------------
include/asm-alpha/semaphore.h | 22 +++++++++++-----------
include/asm-arm/semaphore.h | 17 ++++++-----------
include/asm-arm26/semaphore.h | 6 +++---
include/asm-cris/semaphore.h | 12 ++++++------
include/asm-frv/semaphore.h | 5 -----
include/asm-h8300/semaphore.h | 12 ++++++------
include/asm-i386/semaphore.h | 22 +++++++++++-----------
include/asm-ia64/semaphore.h | 12 ++++++------
include/asm-m32r/semaphore.h | 14 +++++++-------
include/asm-m68k/semaphore.h | 4 ++--
include/asm-m68knommu/semaphore.h | 12 ++++++------
include/asm-mips/semaphore.h | 14 +++++++-------
include/asm-parisc/semaphore.h | 5 -----
include/asm-ppc/semaphore.h | 14 +++++++-------
include/asm-ppc64/semaphore.h | 14 +++++++-------
include/asm-s390/semaphore.h | 12 ++++++------
include/asm-sh/semaphore.h | 14 +++++++-------
include/asm-sh64/semaphore.h | 14 +++++++-------
include/asm-sparc/semaphore.h | 14 +++++++-------
include/asm-sparc64/semaphore.h | 4 ++--
include/asm-v850/semaphore.h | 10 +++++-----
include/asm-x86_64/semaphore.h | 20 ++++++++++----------
23 files changed, 147 insertions(+), 162 deletions(-)

Index: 1394-dev/include/asm-h8300/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-h8300/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-h8300/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -23,14 +23,14 @@


struct semaphore {
- atomic_t count;
+ atomic_t count_h8300;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_h8300 = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -82,7 +82,7 @@ static inline void down(struct semaphore

might_sleep();

- count = &(sem->count);
+ count = &(sem->count_h8300);
__asm__ __volatile__(
"stc ccr,r3l\n\t"
"orc #0x80,ccr\n\t"
@@ -108,7 +108,7 @@ static inline int down_interruptible(str

might_sleep();

- count = &(sem->count);
+ count = &(sem->count_h8300);
__asm__ __volatile__(
"stc ccr,r1l\n\t"
"orc #0x80,ccr\n\t"
@@ -134,7 +134,7 @@ static inline int down_trylock(struct se
{
register atomic_t *count asm("er0");

- count = &(sem->count);
+ count = &(sem->count_h8300);
__asm__ __volatile__(
"stc ccr,r3l\n\t"
"orc #0x80,ccr\n\t"
@@ -170,7 +170,7 @@ static inline void up(struct semaphore *
{
register atomic_t *count asm("er0");

- count = &(sem->count);
+ count = &(sem->count_h8300);
__asm__ __volatile__(
"stc ccr,r3l\n\t"
"orc #0x80,ccr\n\t"
Index: 1394-dev/arch/sparc64/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/sparc64/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/sparc64/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -11,12 +11,12 @@
#include <linux/init.h>

/*
- * Atomically update sem->count.
+ * Atomically update sem->count_sparc64.
* This does the equivalent of the following:
*
- * old_count = sem->count;
+ * old_count = sem->count_sparc64;
* tmp = MAX(old_count, 0) + incr;
- * sem->count = tmp;
+ * sem->count_sparc64 = tmp;
* return old_count;
*/
static __inline__ int __sem_update_count(struct semaphore *sem, int incr)
@@ -24,7 +24,7 @@ static __inline__ int __sem_update_count
int old_count, tmp;

__asm__ __volatile__("\n"
-" ! __sem_update_count old_count(%0) tmp(%1) incr(%4) &sem->count(%3)\n"
+" ! __sem_update_count old_count(%0) tmp(%1) incr(%4) &sem->count_sparc64(%3)\n"
"1: ldsw [%3], %0\n"
" mov %0, %1\n"
" cmp %0, 0\n"
@@ -34,8 +34,8 @@ static __inline__ int __sem_update_count
" cmp %0, %1\n"
" bne,pn %%icc, 1b\n"
" membar #StoreLoad | #StoreStore\n"
- : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
- : "r" (&sem->count), "r" (incr), "m" (sem->count)
+ : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count_sparc64)
+ : "r" (&sem->count_sparc64), "r" (incr), "m" (sem->count_sparc64)
: "cc");

return old_count;
@@ -50,9 +50,9 @@ static void __up(struct semaphore *sem)
void up(struct semaphore *sem)
{
/* This atomically does:
- * old_val = sem->count;
- * new_val = sem->count + 1;
- * sem->count = new_val;
+ * old_val = sem->count_sparc64;
+ * new_val = sem->count_sparc64 + 1;
+ * sem->count_sparc64 = new_val;
* if (old_val < 0)
* __up(sem);
*
@@ -113,9 +113,9 @@ void __sched down(struct semaphore *sem)
{
might_sleep();
/* This atomically does:
- * old_val = sem->count;
- * new_val = sem->count - 1;
- * sem->count = new_val;
+ * old_val = sem->count_sparc64;
+ * new_val = sem->count_sparc64 - 1;
+ * sem->count_sparc64 = new_val;
* if (old_val < 1)
* __down(sem);
*
@@ -158,12 +158,12 @@ int down_trylock(struct semaphore *sem)
int ret;

/* This atomically does:
- * old_val = sem->count;
- * new_val = sem->count - 1;
+ * old_val = sem->count_sparc64;
+ * new_val = sem->count_sparc64 - 1;
* if (old_val < 1) {
* ret = 1;
* } else {
- * sem->count = new_val;
+ * sem->count_sparc64 = new_val;
* ret = 0;
* }
*
@@ -223,9 +223,9 @@ int __sched down_interruptible(struct se

might_sleep();
/* This atomically does:
- * old_val = sem->count;
- * new_val = sem->count - 1;
- * sem->count = new_val;
+ * old_val = sem->count_sparc64;
+ * new_val = sem->count_sparc64 - 1;
+ * sem->count_sparc64 = new_val;
* if (old_val < 1)
* ret = __down_interruptible(sem);
*
Index: 1394-dev/include/asm-sh64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sh64/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-sh64/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -28,14 +28,14 @@
#include <asm/atomic.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_sh64;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_sh64 = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -57,7 +57,7 @@ static inline void sema_init (struct sem
* i'd rather use the more flexible initialization above, but sadly
* GCC 2.7.2.3 emits a bogus warning. EGCS doesnt. Oh well.
*/
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_sh64, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
@@ -88,7 +88,7 @@ extern spinlock_t semaphore_wake_lock;

static inline void down(struct semaphore * sem)
{
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_sh64) < 0)
__down(sem);
}

@@ -96,7 +96,7 @@ static inline int down_interruptible(str
{
int ret = 0;

- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_sh64) < 0)
ret = __down_interruptible(sem);
return ret;
}
@@ -105,7 +105,7 @@ static inline int down_trylock(struct se
{
int ret = 0;

- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_sh64) < 0)
ret = __down_trylock(sem);
return ret;
}
@@ -116,7 +116,7 @@ static inline int down_trylock(struct se
*/
static inline void up(struct semaphore * sem)
{
- if (atomic_inc_return(&sem->count) <= 0)
+ if (atomic_inc_return(&sem->count_sh64) <= 0)
__up(sem);
}

Index: 1394-dev/include/asm-m68knommu/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m68knommu/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-m68knommu/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -23,16 +23,16 @@


struct semaphore {
- atomic_t count;
+ atomic_t count_m68knommu;
atomic_t waking;
wait_queue_head_t wait;
};

-#define __SEMAPHORE_INITIALIZER(name, n) \
-{ \
- .count = ATOMIC_INIT(n), \
- .waking = ATOMIC_INIT(0), \
- .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
+#define __SEMAPHORE_INITIALIZER(name, n) \
+{ \
+ .count_m68knommu = ATOMIC_INIT(n), \
+ .waking = ATOMIC_INIT(0), \
+ .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}

#define __MUTEX_INITIALIZER(name) \
Index: 1394-dev/include/asm-m32r/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m32r/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-m32r/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -20,14 +20,14 @@
#include <asm/atomic.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_m32r;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_m32r = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -49,7 +49,7 @@ static inline void sema_init (struct sem
* i'd rather use the more flexible initialization above, but sadly
* GCC 2.7.2.3 emits a bogus warning. EGCS doesnt. Oh well.
*/
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_m32r, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
@@ -92,7 +92,7 @@ static inline void down(struct semaphore
"addi %0, #-1; \n\t"
M32R_UNLOCK" %0, @%1; \n\t"
: "=&r" (count)
- : "r" (&sem->count)
+ : "r" (&sem->count_m32r)
: "memory"
#ifdef CONFIG_CHIP_M32700_TS1
, "r4"
@@ -123,7 +123,7 @@ static inline int down_interruptible(str
"addi %0, #-1; \n\t"
M32R_UNLOCK" %0, @%1; \n\t"
: "=&r" (count)
- : "r" (&sem->count)
+ : "r" (&sem->count_m32r)
: "memory"
#ifdef CONFIG_CHIP_M32700_TS1
, "r4"
@@ -155,7 +155,7 @@ static inline int down_trylock(struct se
"addi %0, #-1; \n\t"
M32R_UNLOCK" %0, @%1; \n\t"
: "=&r" (count)
- : "r" (&sem->count)
+ : "r" (&sem->count_m32r)
: "memory"
#ifdef CONFIG_CHIP_M32700_TS1
, "r4"
@@ -188,7 +188,7 @@ static inline void up(struct semaphore *
"addi %0, #1; \n\t"
M32R_UNLOCK" %0, @%1; \n\t"
: "=&r" (count)
- : "r" (&sem->count)
+ : "r" (&sem->count_m32r)
: "memory"
#ifdef CONFIG_CHIP_M32700_TS1
, "r4"
Index: 1394-dev/include/asm-ia64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ia64/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-ia64/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -12,14 +12,14 @@
#include <asm/atomic.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_ia64;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_ia64 = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -63,7 +63,7 @@ static inline void
down (struct semaphore *sem)
{
might_sleep();
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_ia64) < 0)
__down(sem);
}

@@ -77,7 +77,7 @@ down_interruptible (struct semaphore * s
int ret = 0;

might_sleep();
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_ia64) < 0)
ret = __down_interruptible(sem);
return ret;
}
@@ -87,7 +87,7 @@ down_trylock (struct semaphore *sem)
{
int ret = 0;

- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_ia64) < 0)
ret = __down_trylock(sem);
return ret;
}
@@ -95,7 +95,7 @@ down_trylock (struct semaphore *sem)
static inline void
up (struct semaphore * sem)
{
- if (atomic_inc_return(&sem->count) <= 0)
+ if (atomic_inc_return(&sem->count_ia64) <= 0)
__up(sem);
}

Index: 1394-dev/include/asm-i386/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-i386/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-i386/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -42,7 +42,7 @@
#include <linux/rwsem.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_i386;
int sleepers;
wait_queue_head_t wait;
};
@@ -50,7 +50,7 @@ struct semaphore {

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_i386 = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -72,7 +72,7 @@ static inline void sema_init (struct sem
* i'd rather use the more flexible initialization above, but sadly
* GCC 2.7.2.3 emits a bogus warning. EGCS doesn't. Oh well.
*/
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_i386, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
@@ -107,7 +107,7 @@ static inline void down(struct semaphore
might_sleep();
__asm__ __volatile__(
"# atomic down operation\n\t"
- LOCK "decl %0\n\t" /* --sem->count */
+ LOCK "decl %0\n\t" /* --sem->count_i386 */
"js 2f\n"
"1:\n"
LOCK_SECTION_START("")
@@ -115,7 +115,7 @@ static inline void down(struct semaphore
"call __down_failed\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=m" (sem->count)
+ :"=m" (sem->count_i386)
:
:"memory","ax");
}
@@ -131,7 +131,7 @@ static inline int down_interruptible(str
might_sleep();
__asm__ __volatile__(
"# atomic interruptible down operation\n\t"
- LOCK "decl %1\n\t" /* --sem->count */
+ LOCK "decl %1\n\t" /* --sem->count_i386 */
"js 2f\n\t"
"xorl %0,%0\n"
"1:\n"
@@ -140,7 +140,7 @@ static inline int down_interruptible(str
"call __down_failed_interruptible\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=a" (result), "=m" (sem->count)
+ :"=a" (result), "=m" (sem->count_i386)
:
:"memory");
return result;
@@ -156,7 +156,7 @@ static inline int down_trylock(struct se

__asm__ __volatile__(
"# atomic interruptible down operation\n\t"
- LOCK "decl %1\n\t" /* --sem->count */
+ LOCK "decl %1\n\t" /* --sem->count_i386 */
"js 2f\n\t"
"xorl %0,%0\n"
"1:\n"
@@ -165,7 +165,7 @@ static inline int down_trylock(struct se
"call __down_failed_trylock\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=a" (result), "=m" (sem->count)
+ :"=a" (result), "=m" (sem->count_i386)
:
:"memory");
return result;
@@ -181,7 +181,7 @@ static inline void up(struct semaphore *
{
__asm__ __volatile__(
"# atomic up operation\n\t"
- LOCK "incl %0\n\t" /* ++sem->count */
+ LOCK "incl %0\n\t" /* ++sem->count_i386 */
"jle 2f\n"
"1:\n"
LOCK_SECTION_START("")
@@ -190,7 +190,7 @@ static inline void up(struct semaphore *
"jmp 1b\n"
LOCK_SECTION_END
".subsection 0\n"
- :"=m" (sem->count)
+ :"=m" (sem->count_i386)
:
:"memory","ax");
}
Index: 1394-dev/include/asm-sparc/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sparc/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-sparc/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -10,14 +10,14 @@
#include <linux/rwsem.h>

struct semaphore {
- atomic24_t count;
+ atomic24_t count_sparc;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC24_INIT(n), \
+ .count_sparc = ATOMIC24_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -33,7 +33,7 @@ struct semaphore {

static inline void sema_init (struct semaphore *sem, int val)
{
- atomic24_set(&sem->count, val);
+ atomic24_set(&sem->count_sparc, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
@@ -60,7 +60,7 @@ static inline void down(struct semaphore

might_sleep();

- ptr = &(sem->count.counter);
+ ptr = &(sem->count_sparc.counter);
increment = 1;

__asm__ __volatile__(
@@ -94,7 +94,7 @@ static inline int down_interruptible(str

might_sleep();

- ptr = &(sem->count.counter);
+ ptr = &(sem->count_sparc.counter);
increment = 1;

__asm__ __volatile__(
@@ -129,7 +129,7 @@ static inline int down_trylock(struct se
register volatile int *ptr asm("g1");
register int increment asm("g2");

- ptr = &(sem->count.counter);
+ ptr = &(sem->count_sparc.counter);
increment = 1;

__asm__ __volatile__(
@@ -164,7 +164,7 @@ static inline void up(struct semaphore *
register volatile int *ptr asm("g1");
register int increment asm("g2");

- ptr = &(sem->count.counter);
+ ptr = &(sem->count_sparc.counter);
increment = 1;

__asm__ __volatile__(
Index: 1394-dev/include/asm-x86_64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-x86_64/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-x86_64/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -44,14 +44,14 @@
#include <linux/stringify.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_x86_64;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_x86_64 = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -73,7 +73,7 @@ static inline void sema_init (struct sem
* i'd rather use the more flexible initialization above, but sadly
* GCC 2.7.2.3 emits a bogus warning. EGCS doesn't. Oh well.
*/
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_x86_64, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
@@ -116,7 +116,7 @@ static inline void down(struct semaphore
"2:\tcall __down_failed\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=m" (sem->count)
+ :"=m" (sem->count_x86_64)
:"D" (sem)
:"memory");
}
@@ -133,7 +133,7 @@ static inline int down_interruptible(str

__asm__ __volatile__(
"# atomic interruptible down operation\n\t"
- LOCK "decl %1\n\t" /* --sem->count */
+ LOCK "decl %1\n\t" /* --sem->count_x86_64 */
"js 2f\n\t"
"xorl %0,%0\n"
"1:\n"
@@ -141,7 +141,7 @@ static inline int down_interruptible(str
"2:\tcall __down_failed_interruptible\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=a" (result), "=m" (sem->count)
+ :"=a" (result), "=m" (sem->count_x86_64)
:"D" (sem)
:"memory");
return result;
@@ -157,7 +157,7 @@ static inline int down_trylock(struct se

__asm__ __volatile__(
"# atomic interruptible down operation\n\t"
- LOCK "decl %1\n\t" /* --sem->count */
+ LOCK "decl %1\n\t" /* --sem->count_x86_64 */
"js 2f\n\t"
"xorl %0,%0\n"
"1:\n"
@@ -165,7 +165,7 @@ static inline int down_trylock(struct se
"2:\tcall __down_failed_trylock\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=a" (result), "=m" (sem->count)
+ :"=a" (result), "=m" (sem->count_x86_64)
:"D" (sem)
:"memory","cc");
return result;
@@ -181,14 +181,14 @@ static inline void up(struct semaphore *
{
__asm__ __volatile__(
"# atomic up operation\n\t"
- LOCK "incl %0\n\t" /* ++sem->count */
+ LOCK "incl %0\n\t" /* ++sem->count_x86_64 */
"jle 2f\n"
"1:\n"
LOCK_SECTION_START("")
"2:\tcall __up_wakeup\n\t"
"jmp 1b\n"
LOCK_SECTION_END
- :"=m" (sem->count)
+ :"=m" (sem->count_x86_64)
:"D" (sem)
:"memory");
}
Index: 1394-dev/include/asm-ppc/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ppc/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-ppc/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -27,13 +27,13 @@ struct semaphore {
* but additionally indicates that some process(es) might be
* sleeping on `wait'.
*/
- atomic_t count;
+ atomic_t count_ppc;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_ppc = ATOMIC_INIT(n), \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}

@@ -48,7 +48,7 @@ struct semaphore {

static inline void sema_init (struct semaphore *sem, int val)
{
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_ppc, val);
init_waitqueue_head(&sem->wait);
}

@@ -73,7 +73,7 @@ extern inline void down(struct semaphore
/*
* Try to get the semaphore, take the slow path if we fail.
*/
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_ppc) < 0)
__down(sem);
smp_wmb();
}
@@ -84,7 +84,7 @@ extern inline int down_interruptible(str

might_sleep();

- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_ppc) < 0)
ret = __down_interruptible(sem);
smp_wmb();
return ret;
@@ -94,7 +94,7 @@ extern inline int down_trylock(struct se
{
int ret;

- ret = atomic_dec_if_positive(&sem->count) < 0;
+ ret = atomic_dec_if_positive(&sem->count_ppc) < 0;
smp_wmb();
return ret;
}
@@ -102,7 +102,7 @@ extern inline int down_trylock(struct se
extern inline void up(struct semaphore * sem)
{
smp_wmb();
- if (atomic_inc_return(&sem->count) <= 0)
+ if (atomic_inc_return(&sem->count_ppc) <= 0)
__up(sem);
}

Index: 1394-dev/include/asm-ppc64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ppc64/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-ppc64/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -21,13 +21,13 @@ struct semaphore {
* but additionally indicates that some process(es) might be
* sleeping on `wait'.
*/
- atomic_t count;
+ atomic_t count_ppc64;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_ppc64 = ATOMIC_INIT(n), \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}

@@ -42,7 +42,7 @@ struct semaphore {

static inline void sema_init (struct semaphore *sem, int val)
{
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_ppc64, val);
init_waitqueue_head(&sem->wait);
}

@@ -67,7 +67,7 @@ static inline void down(struct semaphore
/*
* Try to get the semaphore, take the slow path if we fail.
*/
- if (unlikely(atomic_dec_return(&sem->count) < 0))
+ if (unlikely(atomic_dec_return(&sem->count_ppc64) < 0))
__down(sem);
}

@@ -77,19 +77,19 @@ static inline int down_interruptible(str

might_sleep();

- if (unlikely(atomic_dec_return(&sem->count) < 0))
+ if (unlikely(atomic_dec_return(&sem->count_ppc64) < 0))
ret = __down_interruptible(sem);
return ret;
}

static inline int down_trylock(struct semaphore * sem)
{
- return atomic_dec_if_positive(&sem->count) < 0;
+ return atomic_dec_if_positive(&sem->count_ppc64) < 0;
}

static inline void up(struct semaphore * sem)
{
- if (unlikely(atomic_inc_return(&sem->count) <= 0))
+ if (unlikely(atomic_inc_return(&sem->count_ppc64) <= 0))
__up(sem);
}

Index: 1394-dev/include/asm-arm26/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-arm26/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-arm26/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -13,14 +13,14 @@
#include <asm/locks.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_arm;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INIT(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_arm = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
}
@@ -36,7 +36,7 @@ struct semaphore {

static inline void sema_init(struct semaphore *sem, int val)
{
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_arm, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
Index: 1394-dev/include/asm-s390/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-s390/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-s390/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -22,7 +22,7 @@ struct semaphore {
* but additionally indicates that some process(es) might be
* sleeping on `wait'.
*/
- atomic_t count;
+ atomic_t count_s390;
wait_queue_head_t wait;
};

@@ -61,7 +61,7 @@ asmlinkage void __up(struct semaphore *
static inline void down(struct semaphore * sem)
{
might_sleep();
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_s390) < 0)
__down(sem);
}

@@ -70,7 +70,7 @@ static inline int down_interruptible(str
int ret = 0;

might_sleep();
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_s390) < 0)
ret = __down_interruptible(sem);
return ret;
}
@@ -95,15 +95,15 @@ static inline int down_trylock(struct se
" cs %0,%1,0(%3)\n"
" jl 0b\n"
"1:"
- : "=&d" (old_val), "=&d" (new_val), "=m" (sem->count.counter)
- : "a" (&sem->count.counter), "m" (sem->count.counter)
+ : "=&d" (old_val), "=&d" (new_val), "=m" (sem->count_s390.counter)
+ : "a" (&sem->count_s390.counter), "m" (sem->count_s390.counter)
: "cc", "memory" );
return old_val <= 0;
}

static inline void up(struct semaphore * sem)
{
- if (atomic_inc_return(&sem->count) <= 0)
+ if (atomic_inc_return(&sem->count_s390) <= 0)
__up(sem);
}

Index: 1394-dev/include/asm-m68k/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m68k/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-m68k/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -24,14 +24,14 @@


struct semaphore {
- atomic_t count;
+ atomic_t count_m68k;
atomic_t waking;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_m68k = ATOMIC_INIT(n), \
.waking = ATOMIC_INIT(0), \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
Index: 1394-dev/include/asm-arm/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-arm/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-arm/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -13,15 +13,15 @@
#include <asm/locks.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_arm;
int sleepers;
wait_queue_head_t wait;
};

-#define __SEMAPHORE_INIT(name, cnt) \
-{ \
- .count = ATOMIC_INIT(cnt), \
- .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
+#define __SEMAPHORE_INIT(name, cnt) \
+{ \
+ .count_arm = ATOMIC_INIT(cnt), \
+ .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
}

#define __MUTEX_INITIALIZER(name) __SEMAPHORE_INIT(name,1)
@@ -34,7 +34,7 @@ struct semaphore {

static inline void sema_init(struct semaphore *sem, int val)
{
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_arm, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
Index: 1394-dev/include/asm-sparc64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sparc64/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-sparc64/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -14,7 +14,7 @@
#include <linux/rwsem.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_sparc64;
wait_queue_head_t wait;
};

@@ -33,7 +33,7 @@ struct semaphore {

static inline void sema_init (struct semaphore *sem, int val)
{
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_sparc64, val);
init_waitqueue_head(&sem->wait);
}

Index: 1394-dev/include/asm-sh/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sh/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-sh/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -21,14 +21,14 @@
#include <asm/atomic.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_sh;
int sleepers;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_sh = ATOMIC_INIT(n), \
.sleepers = 0, \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -50,7 +50,7 @@ static inline void sema_init (struct sem
* i'd rather use the more flexible initialization above, but sadly
* GCC 2.7.2.3 emits a bogus warning. EGCS doesn't. Oh well.
*/
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_sh, val);
sem->sleepers = 0;
init_waitqueue_head(&sem->wait);
}
@@ -82,7 +82,7 @@ extern spinlock_t semaphore_wake_lock;
static inline void down(struct semaphore * sem)
{
might_sleep();
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_sh) < 0)
__down(sem);
}

@@ -91,7 +91,7 @@ static inline int down_interruptible(str
int ret = 0;

might_sleep();
- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_sh) < 0)
ret = __down_interruptible(sem);
return ret;
}
@@ -100,7 +100,7 @@ static inline int down_trylock(struct se
{
int ret = 0;

- if (atomic_dec_return(&sem->count) < 0)
+ if (atomic_dec_return(&sem->count_sh) < 0)
ret = __down_trylock(sem);
return ret;
}
@@ -111,7 +111,7 @@ static inline int down_trylock(struct se
*/
static inline void up(struct semaphore * sem)
{
- if (atomic_inc_return(&sem->count) <= 0)
+ if (atomic_inc_return(&sem->count_sh) <= 0)
__up(sem);
}

Index: 1394-dev/include/asm-mips/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-mips/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-mips/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -35,13 +35,13 @@ struct semaphore {
* but additionally indicates that some process(es) might be
* sleeping on `wait'.
*/
- atomic_t count;
+ atomic_t count_mips;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_mips = ATOMIC_INIT(n), \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}

@@ -56,7 +56,7 @@ struct semaphore {

static inline void sema_init (struct semaphore *sem, int val)
{
- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_mips, val);
init_waitqueue_head(&sem->wait);
}

@@ -81,7 +81,7 @@ static inline void down(struct semaphore
/*
* Try to get the semaphore, take the slow path if we fail.
*/
- if (unlikely(atomic_dec_return(&sem->count) < 0))
+ if (unlikely(atomic_dec_return(&sem->count_mips) < 0))
__down(sem);
}

@@ -91,19 +91,19 @@ static inline int down_interruptible(str

might_sleep();

- if (unlikely(atomic_dec_return(&sem->count) < 0))
+ if (unlikely(atomic_dec_return(&sem->count_mips) < 0))
ret = __down_interruptible(sem);
return ret;
}

static inline int down_trylock(struct semaphore * sem)
{
- return atomic_dec_if_positive(&sem->count) < 0;
+ return atomic_dec_if_positive(&sem->count_mips) < 0;
}

static inline void up(struct semaphore * sem)
{
- if (unlikely(atomic_inc_return(&sem->count) <= 0))
+ if (unlikely(atomic_inc_return(&sem->count_mips) <= 0))
__up(sem);
}

Index: 1394-dev/include/asm-alpha/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-alpha/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-alpha/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -16,14 +16,14 @@
#include <linux/rwsem.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_alpha;
wait_queue_head_t wait;
};

-#define __SEMAPHORE_INITIALIZER(name, n) \
-{ \
- .count = ATOMIC_INIT(n), \
- .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
+#define __SEMAPHORE_INITIALIZER(name, n) \
+{ \
+ .count_alpha = ATOMIC_INIT(n), \
+ .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
}

#define __MUTEX_INITIALIZER(name) \
@@ -43,7 +43,7 @@ static inline void sema_init(struct sema
* except that gcc produces better initializing by parts yet.
*/

- atomic_set(&sem->count, val);
+ atomic_set(&sem->count_alpha, val);
init_waitqueue_head(&sem->wait);
}

@@ -75,7 +75,7 @@ static inline void __down(struct semapho
{
long count;
might_sleep();
- count = atomic_dec_return(&sem->count);
+ count = atomic_dec_return(&sem->count_alpha);
if (unlikely(count < 0))
__down_failed(sem);
}
@@ -84,7 +84,7 @@ static inline int __down_interruptible(s
{
long count;
might_sleep();
- count = atomic_dec_return(&sem->count);
+ count = atomic_dec_return(&sem->count_alpha);
if (unlikely(count < 0))
return __down_failed_interruptible(sem);
return 0;
@@ -119,15 +119,15 @@ static inline int __down_trylock(struct
".subsection 2\n"
"3: br 1b\n"
".previous"
- : "=&r" (ret), "=m" (sem->count)
- : "m" (sem->count));
+ : "=&r" (ret), "=m" (sem->count_alpha)
+ : "m" (sem->count_alpha));

return ret < 0;
}

static inline void __up(struct semaphore *sem)
{
- if (unlikely(atomic_inc_return(&sem->count) <= 0))
+ if (unlikely(atomic_inc_return(&sem->count_alpha) <= 0))
__up_wakeup(sem);
}

Index: 1394-dev/include/asm-frv/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-frv/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-frv/semaphore.h 2005-03-15 17:26:42.000000000 -0500
@@ -71,6 +71,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return sem->count_frv;
+}
+
extern void __down(struct semaphore *sem, unsigned long flags);
extern int __down_interruptible(struct semaphore *sem, unsigned long flags);
extern void __up(struct semaphore *sem);
@@ -151,11 +156,6 @@ static inline void up(struct semaphore *
spin_unlock_irqrestore(&sem->wait_lock, flags);
}

-static inline int sem_getcount(struct semaphore *sem)
-{
- return sem->counter;
-}
-
#endif /* __ASSEMBLY__ */

#endif
Index: 1394-dev/include/asm-cris/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-cris/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-cris/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -21,14 +21,14 @@
int printk(const char *fmt, ...);

struct semaphore {
- atomic_t count;
+ atomic_t count_cris;
atomic_t waking;
wait_queue_head_t wait;
};

#define __SEMAPHORE_INITIALIZER(name, n) \
{ \
- .count = ATOMIC_INIT(n), \
+ .count_cris = ATOMIC_INIT(n), \
.waking = ATOMIC_INIT(0), \
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
}
@@ -74,7 +74,7 @@ extern inline void down(struct semaphore
/* atomically decrement the semaphores count, and if its negative, we wait */
local_save_flags(flags);
local_irq_disable();
- failed = --(sem->count.counter) < 0;
+ failed = --(sem->count_cris.counter) < 0;
local_irq_restore(flags);
if(failed) {
__down(sem);
@@ -97,7 +97,7 @@ extern inline int down_interruptible(str
/* atomically decrement the semaphores count, and if its negative, we wait */
local_save_flags(flags);
local_irq_disable();
- failed = --(sem->count.counter) < 0;
+ failed = --(sem->count_cris.counter) < 0;
local_irq_restore(flags);
if(failed)
failed = __down_interruptible(sem);
@@ -111,7 +111,7 @@ extern inline int down_trylock(struct se

local_save_flags(flags);
local_irq_disable();
- failed = --(sem->count.counter) < 0;
+ failed = --(sem->count_cris.counter) < 0;
local_irq_restore(flags);
if(failed)
failed = __down_trylock(sem);
@@ -132,7 +132,7 @@ extern inline void up(struct semaphore *
/* atomically increment the semaphores count, and if it was negative, we wake people */
local_save_flags(flags);
local_irq_disable();
- wakeup = ++(sem->count.counter) <= 0;
+ wakeup = ++(sem->count_cris.counter) <= 0;
local_irq_restore(flags);
if(wakeup) {
__up(sem);
Index: 1394-dev/include/asm-v850/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-v850/semaphore.h 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/include/asm-v850/semaphore.h 2005-03-15 17:29:24.000000000 -0500
@@ -9,7 +9,7 @@
#include <asm/atomic.h>

struct semaphore {
- atomic_t count;
+ atomic_t count_v850;
int sleepers;
wait_queue_head_t wait;
};
@@ -58,7 +58,7 @@ extern void __up (struct semaphore * sem
extern inline void down (struct semaphore * sem)
{
might_sleep();
- if (atomic_dec_return (&sem->count) < 0)
+ if (atomic_dec_return (&sem->count_v850) < 0)
__down (sem);
}

@@ -66,7 +66,7 @@ extern inline int down_interruptible (st
{
int ret = 0;
might_sleep();
- if (atomic_dec_return (&sem->count) < 0)
+ if (atomic_dec_return (&sem->count_v850) < 0)
ret = __down_interruptible (sem);
return ret;
}
@@ -74,14 +74,14 @@ extern inline int down_interruptible (st
extern inline int down_trylock (struct semaphore *sem)
{
int ret = 0;
- if (atomic_dec_return (&sem->count) < 0)
+ if (atomic_dec_return (&sem->count_v850) < 0)
ret = __down_trylock (sem);
return ret;
}

extern inline void up (struct semaphore * sem)
{
- if (atomic_inc_return (&sem->count) <= 0)
+ if (atomic_inc_return (&sem->count_v850) <= 0)
__up (sem);
}

Index: 1394-dev/arch/i386/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/i386/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/i386/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -73,7 +73,7 @@ fastcall void __sched __down(struct sema
* playing, because we own the spinlock in
* the wait_queue_head.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_i386)) {
sem->sleepers = 0;
break;
}
@@ -116,7 +116,7 @@ fastcall int __sched __down_interruptibl
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_i386);
break;
}

@@ -126,7 +126,7 @@ fastcall int __sched __down_interruptibl
* wait_queue_head. The "-1" is because we're
* still hoping to get the semaphore.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_i386)) {
sem->sleepers = 0;
break;
}
@@ -168,7 +168,7 @@ fastcall int __down_trylock(struct semap
* playing, because we own the spinlock in the
* wait_queue_head.
*/
- if (!atomic_add_negative(sleepers, &sem->count)) {
+ if (!atomic_add_negative(sleepers, &sem->count_i386)) {
wake_up_locked(&sem->wait);
}

Index: 1394-dev/arch/mips/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/mips/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/mips/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -24,16 +24,16 @@
#include <asm/semaphore.h>
#include <asm/war.h>
/*
- * Atomically update sem->count.
+ * Atomically update sem->count_mips.
* This does the equivalent of the following:
*
- * old_count = sem->count;
+ * old_count = sem->count_mips;
* tmp = MAX(old_count, 0) + incr;
- * sem->count = tmp;
+ * sem->count_mips = tmp;
* return old_count;
*
* On machines without lld/scd we need a spinlock to make the manipulation of
- * sem->count and sem->waking atomic. Scalability isn't an issue because
+ * sem->count_mips and sem->waking atomic. Scalability isn't an issue because
* this lock is used on UP only so it's just an empty variable.
*/
static inline int __sem_update_count(struct semaphore *sem, int incr)
@@ -49,8 +49,8 @@ static inline int __sem_update_count(str
" add %1, %1, %3 \n"
" sc %1, %2 \n"
" beqzl %1, 1b \n"
- : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
- : "r" (incr), "m" (sem->count));
+ : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count_mips)
+ : "r" (incr), "m" (sem->count_mips));
} else if (cpu_has_llsc) {
__asm__ __volatile__(
"1: ll %0, %2 \n"
@@ -60,16 +60,16 @@ static inline int __sem_update_count(str
" add %1, %1, %3 \n"
" sc %1, %2 \n"
" beqz %1, 1b \n"
- : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
- : "r" (incr), "m" (sem->count));
+ : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count_mips)
+ : "r" (incr), "m" (sem->count_mips));
} else {
static DEFINE_SPINLOCK(semaphore_lock);
unsigned long flags;

spin_lock_irqsave(&semaphore_lock, flags);
- old_count = atomic_read(&sem->count);
+ old_count = atomic_read(&sem->count_mips);
tmp = max_t(int, old_count, 0) + incr;
- atomic_set(&sem->count, tmp);
+ atomic_set(&sem->count_mips, tmp);
spin_unlock_irqrestore(&semaphore_lock, flags);
}

@@ -144,7 +144,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
/*
* A signal is pending - give up trying.
- * Set sem->count to 0 if it is negative,
+ * Set sem->count_mips to 0 if it is negative,
* since we are no longer sleeping.
*/
__sem_update_count(sem, 0);
Index: 1394-dev/arch/arm/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/arm/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/arm/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -72,7 +72,7 @@ void __sched __down(struct semaphore * s
* Add "everybody else" into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_arm)) {
sem->sleepers = 0;
break;
}
@@ -112,7 +112,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_arm);
break;
}

@@ -122,7 +122,7 @@ int __sched __down_interruptible(struct
* "-1" is because we're still hoping to get
* the lock.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_arm)) {
sem->sleepers = 0;
break;
}
@@ -161,7 +161,7 @@ int __down_trylock(struct semaphore * se
* Add "everybody else" and us into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic_add_negative(sleepers, &sem->count))
+ if (!atomic_add_negative(sleepers, &sem->count_arm))
wake_up(&sem->wait);

spin_unlock_irqrestore(&semaphore_lock, flags);
Index: 1394-dev/arch/m68knommu/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/m68knommu/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/m68knommu/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -75,8 +75,8 @@ void __up(struct semaphore *sem)
add_wait_queue(&sem->wait, &wait); \
\
/* \
- * Ok, we're set up. sem->count is known to be less than zero \
- * so we must wait. \
+ * Ok, we're set up. sem->count_m68knommu is known to be less \
+ * than zero so we must wait. \
* \
* We can let go the lock for purposes of waiting. \
* We re-acquire it after awaking so as to protect \
Index: 1394-dev/arch/alpha/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/alpha/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/alpha/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -16,12 +16,12 @@
*/

/*
- * Atomically update sem->count.
+ * Atomically update sem->count_alpha.
* This does the equivalent of the following:
*
- * old_count = sem->count;
+ * old_count = sem->count_alpha;
* tmp = MAX(old_count, 0) + incr;
- * sem->count = tmp;
+ * sem->count_alpha = tmp;
* return old_count;
*/
static inline int __sem_update_count(struct semaphore *sem, int incr)
@@ -38,8 +38,8 @@ static inline int __sem_update_count(str
".subsection 2\n"
"2: br 1b\n"
".previous"
- : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
- : "Ir" (incr), "1" (tmp), "m" (sem->count));
+ : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count_alpha)
+ : "Ir" (incr), "1" (tmp), "m" (sem->count_alpha));

return old_count;
}
@@ -169,7 +169,7 @@ down(struct semaphore *sem)
#ifdef CONFIG_DEBUG_SEMAPHORE
printk("%s(%d): down(%p) <count=%d> from %p\n",
current->comm, current->pid, sem,
- atomic_read(&sem->count), __builtin_return_address(0));
+ atomic_read(&sem->count_alpha), __builtin_return_address(0));
#endif
__down(sem);
}
@@ -183,7 +183,7 @@ down_interruptible(struct semaphore *sem
#ifdef CONFIG_DEBUG_SEMAPHORE
printk("%s(%d): down(%p) <count=%d> from %p\n",
current->comm, current->pid, sem,
- atomic_read(&sem->count), __builtin_return_address(0));
+ atomic_read(&sem->count_alpha), __builtin_return_address(0));
#endif
return __down_interruptible(sem);
}
@@ -218,7 +218,7 @@ up(struct semaphore *sem)
#ifdef CONFIG_DEBUG_SEMAPHORE
printk("%s(%d): up(%p) <count=%d> from %p\n",
current->comm, current->pid, sem,
- atomic_read(&sem->count), __builtin_return_address(0));
+ atomic_read(&sem->count_alpha), __builtin_return_address(0));
#endif
__up(sem);
}
Index: 1394-dev/arch/s390/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/s390/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/s390/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -16,10 +16,10 @@
#include <asm/semaphore.h>

/*
- * Atomically update sem->count. Equivalent to:
- * old_val = sem->count.counter;
+ * Atomically update sem->count_s390. Equivalent to:
+ * old_val = sem->count_s390.counter;
* new_val = ((old_val >= 0) ? old_val : 0) + incr;
- * sem->count.counter = new_val;
+ * sem->count_s390.counter = new_val;
* return old_val;
*/
static inline int __sem_update_count(struct semaphore *sem, int incr)
@@ -34,8 +34,8 @@ static inline int __sem_update_count(str
" cs %0,%1,0(%3)\n"
" jl 0b\n"
: "=&d" (old_val), "=&d" (new_val),
- "=m" (sem->count)
- : "a" (&sem->count), "d" (incr), "m" (sem->count)
+ "=m" (sem->count_s390)
+ : "a" (&sem->count_s390), "d" (incr), "m" (sem->count_s390)
: "cc" );
return old_val;
}
Index: 1394-dev/arch/h8300/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/h8300/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/h8300/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -74,8 +74,8 @@ void __up(struct semaphore *sem)
add_wait_queue(&sem->wait, &wait); \
\
/* \
- * Ok, we're set up. sem->count is known to be less than zero \
- * so we must wait. \
+ * Ok, we're set up. sem->count_h8300 is known to be less than \
+ * zero so we must wait. \
* \
* We can let go the lock for purposes of waiting. \
* We re-acquire it after awaking so as to protect \
Index: 1394-dev/arch/sh/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/sh/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/sh/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -82,8 +82,8 @@ void __up(struct semaphore *sem)
add_wait_queue(&sem->wait, &wait); \
\
/* \
- * Ok, we're set up. sem->count is known to be less than zero \
- * so we must wait. \
+ * Ok, we're set up. sem->count_sh is known to be less than \
+ * zero so we must wait. \
* \
* We can let go the lock for purposes of waiting. \
* We re-acquire it after awaking so as to protect \
Index: 1394-dev/arch/m68k/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/m68k/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/m68k/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -74,8 +74,8 @@ void __up(struct semaphore *sem)
add_wait_queue(&sem->wait, &wait); \
\
/* \
- * Ok, we're set up. sem->count is known to be less than zero \
- * so we must wait. \
+ * Ok, we're set up. sem->count_m68k is known to be less than \
+ * zero so we must wait. \
* \
* We can let go the lock for purposes of waiting. \
* We re-acquire it after awaking so as to protect \
Index: 1394-dev/arch/ia64/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/ia64/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/ia64/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -64,7 +64,7 @@ void __sched __down (struct semaphore *s
* playing, because we own the spinlock in
* the wait_queue_head.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_ia64)) {
sem->sleepers = 0;
break;
}
@@ -107,7 +107,7 @@ int __sched __down_interruptible (struct
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_ia64);
break;
}

@@ -117,7 +117,7 @@ int __sched __down_interruptible (struct
* wait_queue_head. The "-1" is because we're
* still hoping to get the semaphore.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_ia64)) {
sem->sleepers = 0;
break;
}
@@ -156,7 +156,7 @@ __down_trylock (struct semaphore *sem)
* playing, because we own the spinlock in the
* wait_queue_head.
*/
- if (!atomic_add_negative(sleepers, &sem->count)) {
+ if (!atomic_add_negative(sleepers, &sem->count_ia64)) {
wake_up_locked(&sem->wait);
}

Index: 1394-dev/arch/cris/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/cris/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/cris/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -73,8 +73,8 @@ void __up(struct semaphore *sem)
add_wait_queue(&sem->wait, &wait); \
\
/* \
- * Ok, we're set up. sem->count is known to be less than zero \
- * so we must wait. \
+ * Ok, we're set up. sem->count_cris is known to be less than \
+ * zero so we must wait. \
* \
* We can let go the lock for purposes of waiting. \
* We re-acquire it after awaking so as to protect \
Index: 1394-dev/arch/sh64/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/sh64/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/sh64/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -83,8 +83,8 @@ void __up(struct semaphore *sem)
add_wait_queue(&sem->wait, &wait); \
\
/* \
- * Ok, we're set up. sem->count is known to be less than zero \
- * so we must wait. \
+ * Ok, we're set up. sem->count_sh64 is known to be less than \
+ * zero so we must wait. \
* \
* We can let go the lock for purposes of waiting. \
* We re-acquire it after awaking so as to protect \
Index: 1394-dev/arch/ppc64/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/ppc64/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/ppc64/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -25,12 +25,12 @@
#include <asm/errno.h>

/*
- * Atomically update sem->count.
+ * Atomically update sem->count_ppc64.
* This does the equivalent of the following:
*
- * old_count = sem->count;
+ * old_count = sem->count_ppc64;
* tmp = MAX(old_count, 0) + incr;
- * sem->count = tmp;
+ * sem->count_ppc64 = tmp;
* return old_count;
*/
static inline int __sem_update_count(struct semaphore *sem, int incr)
@@ -44,8 +44,8 @@ static inline int __sem_update_count(str
" add %1,%1,%4\n"
" stwcx. %1,0,%3\n"
" bne 1b"
- : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
- : "r" (&sem->count), "r" (incr), "m" (sem->count)
+ : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count_ppc64)
+ : "r" (&sem->count_ppc64), "r" (incr), "m" (sem->count_ppc64)
: "cc");

return old_count;
@@ -117,7 +117,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
/*
* A signal is pending - give up trying.
- * Set sem->count to 0 if it is negative,
+ * Set sem->count_ppc64 to 0 if it is negative,
* since we are no longer sleeping.
*/
__sem_update_count(sem, 0);
Index: 1394-dev/arch/ppc/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/ppc/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/ppc/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -21,12 +21,12 @@
#include <asm/errno.h>

/*
- * Atomically update sem->count.
+ * Atomically update sem->count_ppc.
* This does the equivalent of the following:
*
- * old_count = sem->count;
+ * old_count = sem->count_ppc;
* tmp = MAX(old_count, 0) + incr;
- * sem->count = tmp;
+ * sem->count_ppc = tmp;
* return old_count;
*/
static inline int __sem_update_count(struct semaphore *sem, int incr)
@@ -41,8 +41,8 @@ static inline int __sem_update_count(str
PPC405_ERR77(0,%3)
" stwcx. %1,0,%3\n"
" bne 1b"
- : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)
- : "r" (&sem->count), "r" (incr), "m" (sem->count)
+ : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count_ppc)
+ : "r" (&sem->count_ppc), "r" (incr), "m" (sem->count_ppc)
: "cc");

return old_count;
@@ -114,7 +114,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
/*
* A signal is pending - give up trying.
- * Set sem->count to 0 if it is negative,
+ * Set sem->count_ppc to 0 if it is negative,
* since we are no longer sleeping.
*/
__sem_update_count(sem, 0);
Index: 1394-dev/arch/v850/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/v850/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/v850/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -73,7 +73,7 @@ void __sched __down(struct semaphore * s
* Add "everybody else" into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_v850)) {
sem->sleepers = 0;
break;
}
@@ -113,7 +113,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_v850);
break;
}

@@ -123,7 +123,7 @@ int __sched __down_interruptible(struct
* "-1" is because we're still hoping to get
* the lock.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_v850)) {
sem->sleepers = 0;
break;
}
@@ -158,7 +158,7 @@ int __down_trylock(struct semaphore * se
* Add "everybody else" and us into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic_add_negative(sleepers, &sem->count))
+ if (!atomic_add_negative(sleepers, &sem->count_v850))
wake_up(&sem->wait);

spin_unlock_irqrestore(&semaphore_lock, flags);
Index: 1394-dev/arch/m32r/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/m32r/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/m32r/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -82,7 +82,7 @@ asmlinkage void __sched __down(struct se
* playing, because we own the spinlock in
* the wait_queue_head.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_m32r)) {
sem->sleepers = 0;
break;
}
@@ -125,7 +125,7 @@ asmlinkage int __sched __down_interrupti
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_m32r);
break;
}

@@ -135,7 +135,7 @@ asmlinkage int __sched __down_interrupti
* wait_queue_head. The "-1" is because we're
* still hoping to get the semaphore.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_m32r)) {
sem->sleepers = 0;
break;
}
@@ -177,7 +177,7 @@ asmlinkage int __down_trylock(struct sem
* playing, because we own the spinlock in the
* wait_queue_head.
*/
- if (!atomic_add_negative(sleepers, &sem->count)) {
+ if (!atomic_add_negative(sleepers, &sem->count_m32r)) {
wake_up_locked(&sem->wait);
}

Index: 1394-dev/arch/arm26/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/arm26/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/arm26/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -74,7 +74,7 @@ void __sched __down(struct semaphore * s
* Add "everybody else" into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_arm26)) {
sem->sleepers = 0;
break;
}
@@ -114,7 +114,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_arm26);
break;
}

@@ -124,7 +124,7 @@ int __sched __down_interruptible(struct
* "-1" is because we're still hoping to get
* the lock.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_arm26)) {
sem->sleepers = 0;
break;
}
@@ -163,7 +163,7 @@ int __down_trylock(struct semaphore * se
* Add "everybody else" and us into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic_add_negative(sleepers, &sem->count))
+ if (!atomic_add_negative(sleepers, &sem->count_arm26))
wake_up(&sem->wait);

spin_unlock_irqrestore(&semaphore_lock, flags);
Index: 1394-dev/arch/x86_64/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/x86_64/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/x86_64/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -74,7 +74,7 @@ void __sched __down(struct semaphore * s
* playing, because we own the spinlock in
* the wait_queue_head.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_x86_64)) {
sem->sleepers = 0;
break;
}
@@ -117,7 +117,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic_add(sleepers, &sem->count);
+ atomic_add(sleepers, &sem->count_x86_64);
break;
}

@@ -127,7 +127,7 @@ int __sched __down_interruptible(struct
* wait_queue_head. The "-1" is because we're
* still hoping to get the semaphore.
*/
- if (!atomic_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic_add_negative(sleepers - 1, &sem->count_x86_64)) {
sem->sleepers = 0;
break;
}
@@ -169,7 +169,7 @@ int __down_trylock(struct semaphore * se
* playing, because we own the spinlock in the
* wait_queue_head.
*/
- if (!atomic_add_negative(sleepers, &sem->count)) {
+ if (!atomic_add_negative(sleepers, &sem->count_x86_64)) {
wake_up_locked(&sem->wait);
}

Index: 1394-dev/arch/sparc/kernel/semaphore.c
===================================================================
--- 1394-dev.orig/arch/sparc/kernel/semaphore.c 2005-03-15 17:24:10.000000000 -0500
+++ 1394-dev/arch/sparc/kernel/semaphore.c 2005-03-15 17:24:16.000000000 -0500
@@ -62,7 +62,7 @@ void __sched __down(struct semaphore * s
* Add "everybody else" into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic24_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic24_add_negative(sleepers - 1, &sem->count_sparc)) {
sem->sleepers = 0;
break;
}
@@ -102,7 +102,7 @@ int __sched __down_interruptible(struct
if (signal_pending(current)) {
retval = -EINTR;
sem->sleepers = 0;
- atomic24_add(sleepers, &sem->count);
+ atomic24_add(sleepers, &sem->count_sparc);
break;
}

@@ -112,7 +112,7 @@ int __sched __down_interruptible(struct
* "-1" is because we're still hoping to get
* the lock.
*/
- if (!atomic24_add_negative(sleepers - 1, &sem->count)) {
+ if (!atomic24_add_negative(sleepers - 1, &sem->count_sparc)) {
sem->sleepers = 0;
break;
}
@@ -147,7 +147,7 @@ int __down_trylock(struct semaphore * se
* Add "everybody else" and us into it. They aren't
* playing, because we own the spinlock.
*/
- if (!atomic24_add_negative(sleepers, &sem->count))
+ if (!atomic24_add_negative(sleepers, &sem->count_sparc))
wake_up(&sem->wait);

spin_unlock_irqrestore(&semaphore_lock, flags);

2005-03-16 19:34:31

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 2/4] Add sem_getcount on arches that lack it


Adds sem_getcount() to architectures that were missing it. Renames
sema_count on arm for this purpose (sema_count has no current callers.)

Tested on i386, ia64, parisc.

Signed-off-by: Jody McIntyre <[email protected]>

Index: 1394-dev/include/asm-h8300/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-h8300/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-h8300/semaphore.h 2005-03-15 17:26:51.000000000 -0500
@@ -59,6 +59,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_h8300);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-sh64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sh64/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-sh64/semaphore.h 2005-03-15 17:28:46.000000000 -0500
@@ -72,6 +72,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_sh64);
+}
+
#if 0
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
Index: 1394-dev/include/asm-m68knommu/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m68knommu/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-m68knommu/semaphore.h 2005-03-15 17:27:30.000000000 -0500
@@ -59,6 +59,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_m68knommu);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-m32r/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m32r/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-m32r/semaphore.h 2005-03-15 17:27:12.000000000 -0500
@@ -64,6 +64,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_m32r);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-ia64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ia64/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-ia64/semaphore.h 2005-03-15 17:27:06.000000000 -0500
@@ -50,6 +50,11 @@ init_MUTEX_LOCKED (struct semaphore *sem
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_ia64);
+}
+
extern void __down (struct semaphore * sem);
extern int __down_interruptible (struct semaphore * sem);
extern int __down_trylock (struct semaphore * sem);
Index: 1394-dev/include/asm-i386/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-i386/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-i386/semaphore.h 2005-03-15 17:27:00.000000000 -0500
@@ -87,6 +87,13 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+typedef atomic_t semcount_t;
+
+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_i386);
+}
+
fastcall void __down_failed(void /* special register calling convention */);
fastcall int __down_failed_interruptible(void /* params in registers */);
fastcall int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-sparc/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sparc/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-sparc/semaphore.h 2005-03-15 17:28:51.000000000 -0500
@@ -48,6 +48,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_sparc);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern int __down_trylock(struct semaphore * sem);
Index: 1394-dev/include/asm-x86_64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-x86_64/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-x86_64/semaphore.h 2005-03-15 17:29:10.000000000 -0500
@@ -88,6 +88,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_x86_64);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-ppc/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ppc/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-ppc/semaphore.h 2005-03-15 17:28:19.000000000 -0500
@@ -62,6 +62,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_ppc);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
Index: 1394-dev/include/asm-ppc64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-ppc64/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-ppc64/semaphore.h 2005-03-15 17:28:24.000000000 -0500
@@ -56,6 +56,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_ppc64);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
Index: 1394-dev/include/asm-arm26/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-arm26/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-arm26/semaphore.h 2005-03-15 17:26:15.000000000 -0500
@@ -51,6 +51,11 @@ static inline void init_MUTEX_LOCKED(str
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_arm);
+}
+
/*
* special register calling convention
*/
Index: 1394-dev/include/asm-s390/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-s390/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-s390/semaphore.h 2005-03-15 17:28:35.000000000 -0500
@@ -53,6 +53,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_s390);
+}
+
asmlinkage void __down(struct semaphore * sem);
asmlinkage int __down_interruptible(struct semaphore * sem);
asmlinkage int __down_trylock(struct semaphore * sem);
Index: 1394-dev/include/asm-m68k/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-m68k/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-m68k/semaphore.h 2005-03-15 17:27:18.000000000 -0500
@@ -60,6 +60,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_m68k);
+}
+
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
asmlinkage int __down_failed_trylock(void /* params in registers */);
Index: 1394-dev/include/asm-arm/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-arm/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-arm/semaphore.h 2005-03-15 17:25:57.000000000 -0500
@@ -49,9 +49,9 @@ static inline void init_MUTEX_LOCKED(str
sema_init(sem, 0);
}

-static inline int sema_count(struct semaphore *sem)
+static inline int sem_getcount(struct semaphore *sem)
{
- return atomic_read(&sem->count);
+ return atomic_read(&sem->count_arm);
}

/*
Index: 1394-dev/include/asm-sparc64/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sparc64/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-sparc64/semaphore.h 2005-03-15 17:28:56.000000000 -0500
@@ -47,6 +47,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_sparc64);
+}
+
extern void up(struct semaphore *sem);
extern void down(struct semaphore *sem);
extern int down_trylock(struct semaphore *sem);
Index: 1394-dev/include/asm-sh/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-sh/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-sh/semaphore.h 2005-03-15 17:28:40.000000000 -0500
@@ -65,6 +65,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_sh);
+}
+
#if 0
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
Index: 1394-dev/include/asm-mips/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-mips/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-mips/semaphore.h 2005-03-15 17:27:35.000000000 -0500
@@ -70,6 +70,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_mips);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
Index: 1394-dev/include/asm-alpha/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-alpha/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-alpha/semaphore.h 2005-03-15 17:25:48.000000000 -0500
@@ -57,6 +57,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem.count_alpha);
+}
+
extern void down(struct semaphore *);
extern void __down_failed(struct semaphore *);
extern int down_interruptible(struct semaphore *);
Index: 1394-dev/include/asm-cris/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-cris/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-cris/semaphore.h 2005-03-15 17:26:26.000000000 -0500
@@ -57,6 +57,11 @@ extern inline void init_MUTEX_LOCKED (st
sema_init(sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_cris);
+}
+
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern int __down_trylock(struct semaphore * sem);
Index: 1394-dev/include/asm-v850/semaphore.h
===================================================================
--- 1394-dev.orig/include/asm-v850/semaphore.h 2005-03-15 17:24:16.000000000 -0500
+++ 1394-dev/include/asm-v850/semaphore.h 2005-03-15 17:29:02.000000000 -0500
@@ -42,6 +42,11 @@ static inline void init_MUTEX_LOCKED (st
sema_init (sem, 0);
}

+static inline int sem_getcount(struct semaphore *sem)
+{
+ return atomic_read(&sem->count_v850);
+}
+
/*
* special register calling convention
*/

2005-03-16 19:35:25

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 4/4] Use sem_getcount in ieee1394

Convert 1394's node manager to use sem_getcount instead of nasty hack.

Tested on parisc (where it eliminates a warning), ia64, i386.

Signed-off-by: Jody McIntyre <[email protected]>

Index: 1394-dev/drivers/ieee1394/nodemgr.c
===================================================================
--- 1394-dev.orig/drivers/ieee1394/nodemgr.c 2005-03-15 18:23:35.000000000 -0500
+++ 1394-dev/drivers/ieee1394/nodemgr.c 2005-03-15 18:23:35.000000000 -0500
@@ -284,7 +284,7 @@ static DEVICE_ATTR(bus_options,S_IRUGO,f
static ssize_t fw_show_ne_tlabels_free(struct device *dev, char *buf)
{
struct node_entry *ne = container_of(dev, struct node_entry, device);
- return sprintf(buf, "%d\n", atomic_read(&ne->tpool->count.count) + 1);
+ return sprintf(buf, "%d\n", sem_getcount(&ne->tpool->count) + 1);
}
static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL);

2005-03-16 19:35:25

by Jody McIntyre

[permalink] [raw]
Subject: Re: [PATCH, RFC 3/4] Use sem_getcount in XFS

Convert XFS to use sem_getcount instead of nasty hack. Fixes warning
with XFS debugging on parisc (untested since I can't find an obvious way
to enable XFS debugging) as well as the valusema macro, used in two places
in XFS.

Tested on i386, ia64, parisc.

Signed-off-by: Jody McIntyre <[email protected]>

Index: 1394-dev/fs/xfs/linux-2.6/xfs_buf.c
===================================================================
--- 1394-dev.orig/fs/xfs/linux-2.6/xfs_buf.c 2005-03-15 17:45:47.000000000 -0500
+++ 1394-dev/fs/xfs/linux-2.6/xfs_buf.c 2005-03-15 17:52:39.000000000 -0500
@@ -976,7 +976,7 @@ int
pagebuf_lock_value(
xfs_buf_t *pb)
{
- return(atomic_read(&pb->pb_sema.count));
+ return(sem_getcount(&pb->pb_sema));
}
#endif

Index: 1394-dev/fs/xfs/linux-2.6/sema.h
===================================================================
--- 1394-dev.orig/fs/xfs/linux-2.6/sema.h 2005-03-15 17:59:50.000000000 -0500
+++ 1394-dev/fs/xfs/linux-2.6/sema.h 2005-03-15 18:16:00.000000000 -0500
@@ -48,7 +48,7 @@ typedef struct semaphore sema_t;
#define initnsema(sp, val, name) sema_init(sp, val)
#define psema(sp, b) down(sp)
#define vsema(sp) up(sp)
-#define valusema(sp) (atomic_read(&(sp)->count))
+#define valusema(sp) (sem_getcount(sp))
#define freesema(sema)

/*