public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: jerome.marchand@ext.bull.net
To: linux-ia64@vger.kernel.org
Subject: Re: ia64 atomic_dec_and_lock() patch
Date: Thu, 11 Dec 2003 09:58:22 +0000	[thread overview]
Message-ID: <marc-linux-ia64-107113674613234@msgid-missing> (raw)
In-Reply-To: <marc-linux-ia64-107107082810707@msgid-missing>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2490 bytes --]


On Wed, 10 Dec 2003, David Mosberger wrote:

> Could you try replacing the inline-asm with cmpxchg() function?  That
> way, you won't break compilation with Intel's compiler.

OK, here's the new patch.
I also join the right patch for lockmeter.



diff -urN linux-2.6.0-test11.orig/arch/ia64/Kconfig
linux-2.6.0-test11/arch/ia64/Kconfig
--- linux-2.6.0-test11.orig/arch/ia64/Kconfig   2003-12-09
11:26:58.000000000 +0100
+++ linux-2.6.0-test11/arch/ia64/Kconfig        2003-12-09
11:34:09.000000000 +0100
@@ -375,6 +375,11 @@
        depends on IA32_SUPPORT
        default y

+config HAVE_DEC_LOCK
+       bool
+       depends on (SMP || PREEMPT)
+       default y
+
 config PERFMON
        bool "Performance monitor support"
        help
diff -urN linux-2.6.0-test11.orig/arch/ia64/lib/Makefile
linux-2.6.0-test11/arch/ia64/lib/Makefile
--- linux-2.6.0-test11.orig/arch/ia64/lib/Makefile      2003-12-09
11:26:58.000000000 +0100
+++ linux-2.6.0-test11/arch/ia64/lib/Makefile   2003-12-09
11:32:05.000000000 +0100
@@ -13,6 +13,7 @@
 lib-$(CONFIG_MCKINLEY) += copy_page_mck.o memcpy_mck.o
 lib-$(CONFIG_PERFMON)  += carta_random.o
 lib-$(CONFIG_MD_RAID5) += xor.o
+lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o

 AFLAGS___divdi3.o      =
 AFLAGS___udivdi3.o     = -DUNSIGNED
diff -urN linux-2.6.0-test11.orig/arch/ia64/lib/dec_and_lock.c
linux-2.6.0-test11/arch/ia64/lib/dec_and_lock.c
--- linux-2.6.0-test11.orig/arch/ia64/lib/dec_and_lock.c        1970-01-01
01:00:00.000000000 +0100
+++ linux-2.6.0-test11/arch/ia64/lib/dec_and_lock.c     2003-12-11
10:42:49.000000000 +0100
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003 Jerome Marchand, Bull S.A.
+ *
+ * This file is released under the GPLv2, or at
+ * your option any later version.
+ *
+ * ia64 version of "atomic_dec_and_lock()" using
+ * the atomic "cmpxchg" instruction.
+ * This code is an adaptation of the x86 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 counter;
+       int newcount;
+
+repeat:
+       counter = atomic_read(atomic);
+       newcount = counter-1;
+
+       if (!newcount)
+               goto slow_path;
+
+       if(cmpxchg(&atomic->counter, counter, newcount) != counter)
+               goto repeat;
+       return 0;
+
+slow_path:
+       spin_lock(lock);
+       if (atomic_dec_and_test(atomic))
+               return 1;
+       spin_unlock(lock);
+       return 0;
+}

[-- Attachment #2: lockmeter ia64 patch --]
[-- Type: TEXT/PLAIN, Size: 1914 bytes --]

diff -urN linux-2.6.0-test11.lockmeter.orig/arch/ia64/lib/dec_and_lock.c linux-2.6.0-test11.lockmeter/arch/ia64/lib/dec_and_lock.c
--- linux-2.6.0-test11.lockmeter.orig/arch/ia64/lib/dec_and_lock.c	2003-12-11 10:44:10.000000000 +0100
+++ linux-2.6.0-test11.lockmeter/arch/ia64/lib/dec_and_lock.c	2003-12-11 10:43:47.000000000 +0100
@@ -13,6 +13,7 @@
 #include <linux/spinlock.h>
 #include <asm/atomic.h>
 
+#ifndef ATOMIC_DEC_AND_LOCK
 int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
 {
 	int counter;
@@ -36,3 +37,4 @@
 	spin_unlock(lock);
 	return 0;
 }
+#endif
diff -urN linux-2.6.0-test11.lockmeter.orig/include/asm-ia64/spinlock.h linux-2.6.0-test11.lockmeter/include/asm-ia64/spinlock.h
--- linux-2.6.0-test11.lockmeter.orig/include/asm-ia64/spinlock.h	2003-12-11 10:09:42.000000000 +0100
+++ linux-2.6.0-test11.lockmeter/include/asm-ia64/spinlock.h	2003-12-11 10:15:45.000000000 +0100
@@ -247,13 +247,27 @@
 extern void _metered_spin_unlock(spinlock_t *lock);
 
 /*
- *  Use a less efficient, and inline, atomic_dec_and_lock() if lockmetering
- *  so we can see the callerPC of who is actually doing the spin_lock().
- *  Otherwise, all we see is the generic rollup of all locks done by
- *  atomic_dec_and_lock().
+ *  Matches what is in arch/ia64/lib/dec_and_lock.c, except this one is
+ *  "static inline" so that the spin_lock(), if actually invoked, is charged
+ *  against the real caller, not against the catch-all atomic_dec_and_lock
  */
 static inline int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
 {
+	int counter;
+	int newcount;
+
+repeat:
+	counter = atomic_read(atomic);
+	newcount = counter-1;
+
+	if (!newcount)
+		goto slow_path;
+
+	if(cmpxchg(&atomic->counter, counter, newcount) != counter)
+		goto repeat;
+	return 0;
+
+slow_path:
 	_metered_spin_lock(lock);
 	if (atomic_dec_and_test(atomic))
 		return 1;

  parent reply	other threads:[~2003-12-11  9:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-10 15:37 ia64 atomic_dec_and_lock() patch jerome.marchand
2003-12-10 15:44 ` Christoph Hellwig
2003-12-10 16:06 ` jerome.marchand
2003-12-10 17:33 ` David Mosberger
2003-12-11  9:58 ` jerome.marchand [this message]
2003-12-11 20:28 ` David Mosberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-ia64-107113674613234@msgid-missing \
    --to=jerome.marchand@ext.bull.net \
    --cc=linux-ia64@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox