LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha
@ 2001-10-08 15:42 Ivan Kokshaysky
  2001-10-08 17:24 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Kokshaysky @ 2001-10-08 15:42 UTC (permalink / raw)
  To: Richard Henderson; +Cc: linux-kernel

Similar to x86 version, but somewhat simpler due to ll/sc.

Ivan.

--- 2.4.11p5/arch/alpha/lib/dec_and_lock.c	Thu Jan  1 00:00:00 1970
+++ linux/arch/alpha/lib/dec_and_lock.c	Fri Oct  5 17:37:20 2001
@@ -0,0 +1,35 @@
+/*
+ * arch/alpha/lib/dec_and_lock.c
+ *
+ * ll/sc version of atomic_dec_and_lock()
+ */
+
+#include <linux/spinlock.h>
+#include <asm/atomic.h>
+
+int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
+{
+	int cnt;
+	__asm__ __volatile__(
+	"1:	ldl_l	%0,%1\n"
+	"	subl	%0,1,%0\n"
+	"	beq	%0,2f\n"
+	"	stl_c	%0,%1\n"
+	"	beq	%0,3f\n"
+	"	mb\n"
+	"	mov	$31,$0\n"
+	"	ret\n"
+	"2:\n"
+	".subsection 2\n"
+	"3:	br	1b\n"
+	".previous"
+	:"=&r" (cnt), "=m" (atomic->counter)
+	:"m" (atomic->counter) : "$0", "memory");
+
+	/* Slow path */
+	spin_lock(lock);
+	if (atomic_dec_and_test(atomic))
+		return 1;
+	spin_unlock(lock);
+	return 0;
+}
--- 2.4.11p5/arch/alpha/lib/Makefile	Wed Jun 20 22:10:27 2001
+++ linux/arch/alpha/lib/Makefile	Fri Oct  5 17:37:20 2001
@@ -49,6 +49,10 @@ OBJS =	__divqu.o __remqu.o __divlu.o __r
 	fpreg.o \
 	callback_srm.o srm_puts.o srm_printk.o
 
+ifeq ($(CONFIG_SMP),y)
+  OBJS += dec_and_lock.o
+endif
+
 lib.a: $(OBJS)
 	$(AR) rcs lib.a $(OBJS)
 
--- 2.4.11p5/arch/alpha/kernel/alpha_ksyms.c	Fri Sep 14 02:21:32 2001
+++ linux/arch/alpha/kernel/alpha_ksyms.c	Fri Oct  5 19:56:39 2001
@@ -215,6 +215,7 @@ EXPORT_SYMBOL(__global_cli);
 EXPORT_SYMBOL(__global_sti);
 EXPORT_SYMBOL(__global_save_flags);
 EXPORT_SYMBOL(__global_restore_flags);
+EXPORT_SYMBOL(atomic_dec_and_lock);
 #if DEBUG_SPINLOCK
 EXPORT_SYMBOL(spin_unlock);
 EXPORT_SYMBOL(debug_spin_lock);
--- 2.4.11p5/arch/alpha/config.in	Fri Oct  5 17:27:50 2001
+++ linux/arch/alpha/config.in	Fri Oct  5 17:37:20 2001
@@ -217,6 +217,10 @@ then
 	bool 'Symmetric multi-processing support' CONFIG_SMP
 fi
 
+if [ "$CONFIG_SMP" = "y" ]; then
+   define_bool CONFIG_HAVE_DEC_LOCK y
+fi
+
 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
    bool 'Discontiguous Memory Support' CONFIG_DISCONTIGMEM
    if [ "$CONFIG_DISCONTIGMEM" = "y" ]; then

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha
  2001-10-08 15:42 [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha Ivan Kokshaysky
@ 2001-10-08 17:24 ` Richard Henderson
  2001-10-09 10:30   ` Ivan Kokshaysky
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2001-10-08 17:24 UTC (permalink / raw)
  To: Ivan Kokshaysky; +Cc: linux-kernel

On Mon, Oct 08, 2001 at 07:42:57PM +0400, Ivan Kokshaysky wrote:
> +	"	ret\n"

I am extremely uncomfortable with you returning out of the middle of
an asm statement.  What if the compiler decides to allocate a stack
frame for some reason?  You'll return without deallocating it.

Please write the whole thing in assembly or avoid the early return.


r~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha
  2001-10-08 17:24 ` Richard Henderson
@ 2001-10-09 10:30   ` Ivan Kokshaysky
  2001-10-11 18:28     ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Kokshaysky @ 2001-10-09 10:30 UTC (permalink / raw)
  To: linux-kernel

On Mon, Oct 08, 2001 at 10:24:12AM -0700, Richard Henderson wrote:
> I am extremely uncomfortable with you returning out of the middle of
> an asm statement.  What if the compiler decides to allocate a stack
> frame for some reason?  You'll return without deallocating it.

Indeed.

> Please write the whole thing in assembly or avoid the early return.

OK. I prefer the latter - rewriting in assembly won't allow DEBUG_SPINLOCK
stuff in this function. OTOH, moving the return outside an asm statement
adds only one instruction - conditional branch that falls through in the
fast path.

Ivan.

--- 2.4.11p5/arch/alpha/lib/dec_and_lock.c	Thu Jan  1 00:00:00 1970
+++ linux/arch/alpha/lib/dec_and_lock.c	Tue Oct  9 14:15:01 2001
@@ -0,0 +1,37 @@
+/*
+ * arch/alpha/lib/dec_and_lock.c
+ *
+ * ll/sc version of atomic_dec_and_lock()
+ */
+
+#include <linux/compiler.h>
+#include <linux/spinlock.h>
+#include <asm/atomic.h>
+
+int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
+{
+	long cnt;
+	__asm__ __volatile__(
+	"1:	ldl_l	%0,%1\n"
+	"	subl	%0,1,%0\n"
+	"	beq	%0,2f\n"
+	"	stl_c	%0,%1\n"
+	"	beq	%0,3f\n"
+	"	mb\n"
+	"2:\n"
+	".subsection 2\n"
+	"3:	br	1b\n"
+	".previous"
+	:"=&r" (cnt), "=m" (atomic->counter)
+	:"m" (atomic->counter) : "memory");
+
+	if (likely(cnt))
+		return 0;
+
+	/* Slow path */
+	spin_lock(lock);
+	if (atomic_dec_and_test(atomic))
+		return 1;
+	spin_unlock(lock);
+	return 0;
+}
--- 2.4.11p5/arch/alpha/lib/Makefile	Wed Jun 20 22:10:27 2001
+++ linux/arch/alpha/lib/Makefile	Fri Oct  5 17:37:20 2001
@@ -49,6 +49,10 @@ OBJS =	__divqu.o __remqu.o __divlu.o __r
 	fpreg.o \
 	callback_srm.o srm_puts.o srm_printk.o
 
+ifeq ($(CONFIG_SMP),y)
+  OBJS += dec_and_lock.o
+endif
+
 lib.a: $(OBJS)
 	$(AR) rcs lib.a $(OBJS)
 
--- 2.4.11p5/arch/alpha/kernel/alpha_ksyms.c	Fri Sep 14 02:21:32 2001
+++ linux/arch/alpha/kernel/alpha_ksyms.c	Fri Oct  5 19:56:39 2001
@@ -215,6 +215,7 @@ EXPORT_SYMBOL(__global_cli);
 EXPORT_SYMBOL(__global_sti);
 EXPORT_SYMBOL(__global_save_flags);
 EXPORT_SYMBOL(__global_restore_flags);
+EXPORT_SYMBOL(atomic_dec_and_lock);
 #if DEBUG_SPINLOCK
 EXPORT_SYMBOL(spin_unlock);
 EXPORT_SYMBOL(debug_spin_lock);
--- 2.4.11p5/arch/alpha/config.in	Fri Oct  5 17:27:50 2001
+++ linux/arch/alpha/config.in	Fri Oct  5 17:37:20 2001
@@ -217,6 +217,10 @@ then
 	bool 'Symmetric multi-processing support' CONFIG_SMP
 fi
 
+if [ "$CONFIG_SMP" = "y" ]; then
+   define_bool CONFIG_HAVE_DEC_LOCK y
+fi
+
 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
    bool 'Discontiguous Memory Support' CONFIG_DISCONTIGMEM
    if [ "$CONFIG_DISCONTIGMEM" = "y" ]; then

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha
  2001-10-09 10:30   ` Ivan Kokshaysky
@ 2001-10-11 18:28     ` Richard Henderson
  2001-10-12 12:35       ` Ivan Kokshaysky
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2001-10-11 18:28 UTC (permalink / raw)
  To: Ivan Kokshaysky; +Cc: linux-kernel

On Tue, Oct 09, 2001 at 02:30:13PM +0400, Ivan Kokshaysky wrote:
> OK. I prefer the latter - rewriting in assembly won't allow DEBUG_SPINLOCK
> stuff in this function. OTOH, moving the return outside an asm statement
> adds only one instruction - conditional branch that falls through in the
> fast path.

Hmm.  What about a mixture:


  asm (".text					\n\
	.global atomic_dec_and_lock		\n\
	.ent atomic_dec_and_lock		\n\
atomic_dec_and_lock:				\n\
	.prologue 0				\n\
1:	ldl_l	$1, 0($16)			\n\
	subl	$1, 1, $1			\n\
	beq	2f				\n\
	stl_c	$1, 0($16)			\n\
	beq	$1, 3f				\n\
	mb					\n\
	ret					\n\
	.align	4				\n\
3:	br	1b				\n\
2:	lda	$27, atomic_dec_and_lock_1");

	/* FALLTHRU */
	
static int
atomic_dec_and_lock_1(atomic_t *atomic, spinlock_t *lock)
{
	/* Slow path */
	spin_lock(lock);
	if (atomic_dec_and_test(atomic))
		return 1;
	spin_unlock(lock);
	return 0;
}


r~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha
  2001-10-11 18:28     ` Richard Henderson
@ 2001-10-12 12:35       ` Ivan Kokshaysky
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Kokshaysky @ 2001-10-12 12:35 UTC (permalink / raw)
  To: linux-kernel

On Thu, Oct 11, 2001 at 11:28:10AM -0700, Richard Henderson wrote:
> Hmm.  What about a mixture:

...

> 2:	lda	$27, atomic_dec_and_lock_1");
> 
> 	/* FALLTHRU */
> 	
> static int
> atomic_dec_and_lock_1(atomic_t *atomic, spinlock_t *lock)

Oh cool.
I've made a patch of the above (with some minor changes), but
are you certain that these two will be linked in proper order
under any circumstances? Or "br atomic_dec_and_lock_1" is
needed?

Ivan.

--- 2.4.13p1/arch/alpha/lib/dec_and_lock.c	Thu Jan  1 00:00:00 1970
+++ linux/arch/alpha/lib/dec_and_lock.c	Fri Oct 12 14:48:57 2001
@@ -0,0 +1,41 @@
+/*
+ * arch/alpha/lib/dec_and_lock.c
+ *
+ * ll/sc version of atomic_dec_and_lock() and nice example
+ * of mixing C and assembly.
+ * 
+ */
+
+#include <linux/spinlock.h>
+#include <asm/atomic.h>
+
+  asm (".text					\n\
+	.global atomic_dec_and_lock		\n\
+	.ent atomic_dec_and_lock		\n\
+	.align	4				\n\
+atomic_dec_and_lock:				\n\
+	.prologue 0				\n\
+1:	ldl_l	$1, 0($16)			\n\
+	subl	$1, 1, $1			\n\
+	beq	$1, 2f				\n\
+	stl_c	$1, 0($16)			\n\
+	beq	$1, 3f				\n\
+	mb					\n\
+	clr	$0				\n\
+	ret					\n\
+3:	br	1b				\n\
+2:	lda	$27, atomic_dec_and_lock_1	\n\
+	.end atomic_dec_and_lock");
+
+	/* FALLTHRU */
+
+static int __attribute__((unused))
+atomic_dec_and_lock_1(atomic_t *atomic, spinlock_t *lock)
+{
+	/* Slow path */
+	spin_lock(lock);
+	if (atomic_dec_and_test(atomic))
+		return 1;
+	spin_unlock(lock);
+	return 0;
+}
--- 2.4.13p1/arch/alpha/lib/Makefile	Wed Jun 20 22:10:27 2001
+++ linux/arch/alpha/lib/Makefile	Fri Oct  5 17:37:20 2001
@@ -49,6 +49,10 @@ OBJS =	__divqu.o __remqu.o __divlu.o __r
 	fpreg.o \
 	callback_srm.o srm_puts.o srm_printk.o
 
+ifeq ($(CONFIG_SMP),y)
+  OBJS += dec_and_lock.o
+endif
+
 lib.a: $(OBJS)
 	$(AR) rcs lib.a $(OBJS)
 
--- 2.4.13p1/arch/alpha/kernel/alpha_ksyms.c	Fri Sep 14 02:21:32 2001
+++ linux/arch/alpha/kernel/alpha_ksyms.c	Fri Oct  5 19:56:39 2001
@@ -215,6 +215,7 @@ EXPORT_SYMBOL(__global_cli);
 EXPORT_SYMBOL(__global_sti);
 EXPORT_SYMBOL(__global_save_flags);
 EXPORT_SYMBOL(__global_restore_flags);
+EXPORT_SYMBOL(atomic_dec_and_lock);
 #if DEBUG_SPINLOCK
 EXPORT_SYMBOL(spin_unlock);
 EXPORT_SYMBOL(debug_spin_lock);
--- 2.4.13p1/arch/alpha/config.in	Fri Oct  5 17:27:50 2001
+++ linux/arch/alpha/config.in	Fri Oct  5 17:37:20 2001
@@ -217,6 +217,10 @@ then
 	bool 'Symmetric multi-processing support' CONFIG_SMP
 fi
 
+if [ "$CONFIG_SMP" = "y" ]; then
+   define_bool CONFIG_HAVE_DEC_LOCK y
+fi
+
 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
    bool 'Discontiguous Memory Support' CONFIG_DISCONTIGMEM
    if [ "$CONFIG_DISCONTIGMEM" = "y" ]; then

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-10-12 12:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-08 15:42 [patch 2.4.11-pre5] atomic_dec_and_lock() for alpha Ivan Kokshaysky
2001-10-08 17:24 ` Richard Henderson
2001-10-09 10:30   ` Ivan Kokshaysky
2001-10-11 18:28     ` Richard Henderson
2001-10-12 12:35       ` Ivan Kokshaysky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).