From: "Kaigai Kohei" <kaigai@ak.jp.nec.com>
To: "Andi Kleen" <ak@muc.de>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH]atomic_inc_return() for i386/x86_64 (Re: RCU issue with SELinux)
Date: Tue, 31 Aug 2004 17:19:34 +0900 [thread overview]
Message-ID: <01b401c48f33$3fb05000$f97d220a@linux.bs1.fc.nec.co.jp> (raw)
In-Reply-To: <m3k6vjco9e.fsf@averell.firstfloor.org>
[-- Attachment #1: Type: text/plain, Size: 1484 bytes --]
Hi Andi, thanks for your comment.
Sorry, I have not noticed your mail in the flood of Linux-Kernel ML.
> > atomic_inc_return() is not defined for arm,arm26,i386,x86_64 and um archtectures.
> > This attached patch adds atomic_inc_return() and atomic_dec_return() to arm,i386 and x86_64.
> >
> > It is implemented by 'xaddl' operation with LOCK prefix for i386 and x86_64.
> > But this operation is permitted after i486 processor only.
> > Another implementation may be necessary for i386SX/DX processor.
> > But 'xaddl' operation is used in 'include/asm-i386/rwsem.h' unconditionally.
> > I think it has agreed on using 'xaddl' operation in past days.
>
> We don't support SMP on 386 boxes. What you can do for 386 is to use
> alternative() and just use an non SMP safe version for 386 and xadd
> for 486+
We can avoid the problem by the simple solution, since SMP
on 386 boxes isn't supported. It is to disable interrupt
while updating atomic_t variable.
The attached patch modifies the include/asm-i386/atomic.h.
If the target processor is 386, then atomic_add_return() use
non-atomic operations between local_irq_disable() and local_irq_enable().
Otherwise, atomic_add_return() use 'xadd' operation with LOCK prefix.
By the way, do you know why 'xadd' operation is used
unconditionally in 'include/asm-i386/rwsem.h'?
Thanks.
Signed-off-by: KaiGai, Kohei <kaigai@ak.jp.nec.com>
Signed-off-by: Takayoshi Kochi <t-kochi@bq.jp.nec.com>
--------
Kai Gai <kaigai@ak.jp.nec.com>
[-- Attachment #2: atomic_inc_return-2.6.8.1.M386.patch --]
[-- Type: application/octet-stream, Size: 3067 bytes --]
--- linux-2.6.8.1/include/asm-arm/atomic.h 2004-08-14 19:54:50.000000000 +0900
+++ linux-2.6.8.1.rcu/include/asm-arm/atomic.h 2004-08-24 19:31:56.000000000 +0900
@@ -194,8 +194,10 @@
#define atomic_dec(v) atomic_sub(1, v)
#define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
#define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
+#define atomic_inc_return(v) (atomic_add_return(1, v))
+#define atomic_dec_return(v) (atomic_sub_return(1, v))
#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
/* Atomic operations are already serializing on ARM */
--- linux-2.6.8.1/include/asm-i386/atomic.h 2004-08-14 19:55:09.000000000 +0900
+++ linux-2.6.8.1.rcu/include/asm-i386/atomic.h 2004-08-31 13:10:48.000000000 +0900
@@ -1,8 +1,9 @@
#ifndef __ARCH_I386_ATOMIC__
#define __ARCH_I386_ATOMIC__
#include <linux/config.h>
+#include <asm/system.h>
/*
* Atomic operations that C can't guarantee us. Useful for
* resource counting etc..
@@ -175,8 +176,41 @@
:"ir" (i), "m" (v->counter) : "memory");
return c;
}
+/**
+ * atomic_add_return - add and return
+ * @v: pointer of type atomic_t
+ * @i: integer value to add
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static __inline__ int atomic_add_return(int i, atomic_t *v)
+{
+ int __i;
+#ifdef CONFIG_M386
+ local_irq_disable();
+ __i = atomic_read(v);
+ atomic_set(v, i + __i);
+ local_irq_enable();
+#else
+ __i = i;
+ __asm__ __volatile__(
+ LOCK "xaddl %0, %1;"
+ :"=r"(i)
+ :"m"(v->counter), "0"(i));
+#endif
+ return i + __i;
+}
+
+static __inline__ int atomic_sub_return(int i, atomic_t *v)
+{
+ return atomic_add_return(-i,v);
+}
+
+#define atomic_inc_return(v) (atomic_add_return(1,v))
+#define atomic_dec_return(v) (atomic_sub_return(1,v))
+
/* These are x86-specific, used by some header files */
#define atomic_clear_mask(mask, addr) \
__asm__ __volatile__(LOCK "andl %0,%1" \
: : "r" (~(mask)),"m" (*addr) : "memory")
--- linux-2.6.8.1/include/asm-x86_64/atomic.h 2004-08-14 19:56:23.000000000 +0900
+++ linux-2.6.8.1.rcu/include/asm-x86_64/atomic.h 2004-08-25 11:57:36.000000000 +0900
@@ -177,8 +177,33 @@
:"ir" (i), "m" (v->counter) : "memory");
return c;
}
+/**
+ * atomic_add_return - add and return
+ * @v: pointer of type atomic_t
+ * @i: integer value to add
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static __inline__ int atomic_add_return(int i, atomic_t *v)
+{
+ int __i = i;
+ __asm__ __volatile__(
+ LOCK "xaddl %0, %1;"
+ :"=r"(i)
+ :"m"(v->counter), "0"(i));
+ return i + __i;
+}
+
+static __inline__ int atomic_sub_return(int i, atomic_t *v)
+{
+ return atomic_add_return(-i,v);
+}
+
+#define atomic_inc_return(v) (atomic_add_return(1,v))
+#define atomic_dec_return(v) (atomic_sub_return(1,v))
+
/* These are x86-specific, used by some header files */
#define atomic_clear_mask(mask, addr) \
__asm__ __volatile__(LOCK "andl %0,%1" \
: : "r" (~(mask)),"m" (*addr) : "memory")
next prev parent reply other threads:[~2004-08-31 8:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2wJxj-7g2-23@gated-at.bofh.it>
[not found] ` <2x2JC-3Uu-11@gated-at.bofh.it>
2004-08-28 14:48 ` Andi Kleen
2004-08-31 8:19 ` Kaigai Kohei [this message]
2004-08-31 8:49 ` Andi Kleen
2004-09-01 6:22 ` Kaigai Kohei
2004-08-24 13:24 RCU issue with SELinux (Re: SELINUX performance issues) James Morris
2004-08-25 9:52 ` [PATCH]atomic_inc_return() for i386/x86_64 (Re: RCU issue with SELinux) Kaigai Kohei
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='01b401c48f33$3fb05000$f97d220a@linux.bs1.fc.nec.co.jp' \
--to=kaigai@ak.jp.nec.com \
--cc=ak@muc.de \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®