From: Ingo Molnar <mingo@elte.hu>
To: linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>,
Andrew Morton <akpm@osdl.org>
Cc: Arjan van de Ven <arjanv@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
David Howells <dhowells@redhat.com>,
Alexander Viro <viro@parcelfarce.linux.theplanet.co.uk>,
Oleg Nesterov <oleg@tv-sign.ru>, Paul Jackson <pj@sgi.com>
Subject: [patch 04/15] Generic Mutex Subsystem, add-atomic-call-func-x86_64.patch
Date: Mon, 19 Dec 2005 02:35:08 +0100 [thread overview]
Message-ID: <20051219013507.GE27658@elte.hu> (raw)
add two new atomic ops to x86_64: atomic_dec_call_if_negative() and
atomic_inc_call_if_nonpositive(), which are conditional-call-if atomic
operations. Needed by the new mutex code.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
----
include/asm-x86_64/atomic.h | 56 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 56 insertions(+)
Index: linux/include/asm-x86_64/atomic.h
===================================================================
--- linux.orig/include/asm-x86_64/atomic.h
+++ linux/include/asm-x86_64/atomic.h
@@ -203,6 +203,62 @@ static __inline__ int atomic_sub_return(
#define atomic_inc_return(v) (atomic_add_return(1,v))
#define atomic_dec_return(v) (atomic_sub_return(1,v))
+/**
+ * atomic_dec_call_if_negative - decrement and call function if negative
+ * @v: pointer of type atomic_t
+ * @fn: function to call if the result is negative
+ *
+ * Atomically decrements @v and calls a function if the result is negative.
+ * NOTE: the function is type-checked and must be a fastcall.
+ */
+#define atomic_dec_call_if_negative(v, fn_name) \
+do { \
+ fastcall void (*__tmp)(atomic_t *) = fn_name; \
+ \
+ (void)__tmp; \
+ typecheck(atomic_t *, v); \
+ \
+ __asm__ __volatile__( \
+ LOCK "decl (%%rdi)\n" \
+ "js 2f\n" \
+ "1:\n" \
+ LOCK_SECTION_START("") \
+ "2: call "#fn_name"\n\t" \
+ "jmp 1b\n" \
+ LOCK_SECTION_END \
+ : \
+ :"D" (v) \
+ :"memory"); \
+} while (0)
+
+/**
+ * atomic_inc_call_if_nonpositive - increment and call function if nonpositive
+ * @v: pointer of type atomic_t
+ * @fn: function to call if the result is nonpositive
+ *
+ * Atomically increments @v and calls a function if the result is nonpositive.
+ * NOTE: the function is type-checked and must be a fastcall.
+ */
+#define atomic_inc_call_if_nonpositive(v, fn_name) \
+do { \
+ fastcall void (*__tmp)(atomic_t *) = fn_name; \
+ \
+ (void)__tmp; \
+ typecheck(atomic_t *, v); \
+ \
+ __asm__ __volatile__( \
+ LOCK "incl (%%rdi)\n" \
+ "jle 2f\n" \
+ "1:\n" \
+ LOCK_SECTION_START("") \
+ "2: call "#fn_name"\n\t" \
+ "jmp 1b\n" \
+ LOCK_SECTION_END \
+ : \
+ :"D" (v) \
+ :"memory"); \
+} while (0)
+
/* An 64bit atomic type */
typedef struct { volatile long counter; } atomic64_t;
next reply other threads:[~2005-12-19 1:36 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-19 1:35 Ingo Molnar [this message]
2005-12-19 17:49 ` Zwane Mwaikambo
2005-12-19 20:58 ` David Woodhouse
2005-12-20 4:31 ` Ingo Molnar
2005-12-20 6:30 ` Nicolas Pitre
2005-12-20 8:12 ` Nick Piggin
2005-12-20 14:10 ` Nicolas Pitre
2005-12-20 14:12 ` Nick Piggin
2005-12-20 14:35 ` Nicolas Pitre
2005-12-20 15:05 ` Nick Piggin
2005-12-20 16:35 ` Nicolas Pitre
2005-12-20 19:20 ` Russell King
2005-12-20 19:32 ` Arjan van de Ven
2005-12-20 19:37 ` Russell King
2005-12-20 19:59 ` Nicolas Pitre
2005-12-20 19:43 ` Steven Rostedt
2005-12-20 19:57 ` Russell King
2005-12-20 20:35 ` Horst von Brand
2005-12-20 19:55 ` Nicolas Pitre
2005-12-20 18:27 ` Linus Torvalds
2005-12-20 19:34 ` Russell King
2005-12-20 20:10 ` Linus Torvalds
2005-12-20 21:18 ` Nicolas Pitre
2005-12-20 22:04 ` Linus Torvalds
2005-12-20 22:19 ` Steven Rostedt
2005-12-20 22:43 ` Nicolas Pitre
2005-12-21 6:00 ` Ingo Molnar
2005-12-21 2:12 ` Nick Piggin
2005-12-20 19:49 ` Nicolas Pitre
2005-12-20 18:25 ` Linus Torvalds
2005-12-21 6:20 ` Ingo Molnar
2005-12-21 4:16 ` Nicolas Pitre
2005-12-21 6:26 ` Ingo Molnar
2005-12-20 4:29 ` Ingo Molnar
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=20051219013507.GE27658@elte.hu \
--to=mingo@elte.hu \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjanv@infradead.org \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@tv-sign.ru \
--cc=pj@sgi.com \
--cc=rostedt@goodmis.org \
--cc=torvalds@osdl.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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
all inboxes | Powered by JetHome®