From: Arun Sharma <asharma@fb.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Arun Sharma <asharma@fb.com>, David Miller <davem@davemloft.net>,
Maximilian Engelhardt <maxi@daemonizer.de>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
StuStaNet Vorstand <vorstand@stusta.mhn.de>,
Yann Dupont <Yann.Dupont@univ-nantes.fr>,
Denys Fedoryshchenko <denys@visp.net.lb>,
Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>
Subject: Re: Kernel crash after using new Intel NIC (igb)
Date: Fri, 27 May 2011 14:14:19 -0700 [thread overview]
Message-ID: <20110527211419.GA6793@dev1756.snc6.facebook.com> (raw)
In-Reply-To: <1306526219.2533.3.camel@edumazet-laptop>
On Fri, May 27, 2011 at 09:56:59PM +0200, Eric Dumazet wrote:
> >
> > This looks very similar to atomic_add_unless(). If we had a
> >
> > __atomic_add_unless() that returned "old", we could then do:
> >
> > atomic_add_unless() { return __atomic_add_unless() != u }
> > atomic_add_unless_return() { return __atomic_add_unless() + a}
> >
>
> Sure !
>
> I preferred to not touch lot of files in kernel (atomic_add_unless() is
> defined in several files) because its a stable candidate patch (2.6.36+)
>
> So a cleanup patch for 2.6.40+ is certainly doable, do you want to do
> this ?
The attached works for me for x86_64. Cc'ing Ingo/Thomas for comment.
-Arun
atomic: Refactor atomic_add_unless
Commit 686a7e3 (inetpeer: fix race in unused_list manipulations)
in net-2.6 added a atomic_add_unless_return() variant that tries
to detect 0->1 transitions of an atomic reference count.
This sounds like a generic functionality that could be expressed
in terms of an __atomic_add_unless() that returned the old value
instead of a bool.
Signed-off-by: Arun Sharma <asharma@fb.com>
---
arch/x86/include/asm/atomic.h | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index 952a826..bbdbffe 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -221,15 +221,15 @@ static inline int atomic_xchg(atomic_t *v, int new)
}
/**
- * atomic_add_unless - add unless the number is already a given value
+ * __atomic_add_unless - add unless the number is already a given value
* @v: pointer of type atomic_t
* @a: the amount to add to v...
* @u: ...unless v is equal to u.
*
* Atomically adds @a to @v, so long as @v was not already @u.
- * Returns non-zero if @v was not @u, and zero otherwise.
+ * Returns the old value of v
*/
-static inline int atomic_add_unless(atomic_t *v, int a, int u)
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
{
int c, old;
c = atomic_read(v);
@@ -241,7 +241,21 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
break;
c = old;
}
- return c != (u);
+ return c;
+}
+
+/**
+ * atomic_add_unless - add unless the number is already a given value
+ * @v: pointer of type atomic_t
+ * @a: the amount to add to v...
+ * @u: ...unless v is equal to u.
+ *
+ * Atomically adds @a to @v, so long as @v was not already @u.
+ * Returns non-zero if @v was not @u, and zero otherwise.
+ */
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+ return __atomic_add_unless(v, a, u) != u;
}
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
--
1.7.4
next prev parent reply other threads:[~2011-05-27 21:14 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-24 22:32 Kernel crash after using new Intel NIC (igb) Maximilian Engelhardt
2011-04-26 23:34 ` Wyborny, Carolyn
2011-04-27 11:46 ` Maximilian Engelhardt
2011-04-27 12:04 ` Eric Dumazet
2011-04-27 4:24 ` Eric Dumazet
2011-04-27 4:32 ` Eric Dumazet
2011-04-27 11:51 ` Maximilian Engelhardt
2011-05-12 21:10 ` Arun Sharma
2011-05-12 21:15 ` Eric Dumazet
2011-05-24 21:33 ` Arun Sharma
2011-05-25 2:44 ` Eric Dumazet
2011-05-25 6:06 ` Arun Sharma
2011-05-25 6:35 ` Eric Dumazet
2011-05-26 15:06 ` Ben Hutchings
2011-05-26 19:30 ` Arun Sharma
2011-05-26 19:47 ` Eric Dumazet
2011-05-26 21:48 ` Arun Sharma
2011-05-26 22:01 ` Eric Dumazet
2011-05-27 0:09 ` Arun Sharma
2011-05-27 3:27 ` Eric Dumazet
2011-05-27 7:56 ` Yann Dupont
2011-05-27 17:40 ` David Miller
2011-05-27 17:52 ` Arun Sharma
2011-05-27 19:56 ` Eric Dumazet
2011-05-27 21:14 ` Arun Sharma [this message]
2011-05-28 5:41 ` Eric Dumazet
2011-05-28 18:04 ` Ingo Molnar
2011-05-29 7:33 ` Eric Dumazet
2011-05-29 7:38 ` Ingo Molnar
2011-05-29 7:43 ` Eric Dumazet
2011-05-29 12:33 ` Ingo Molnar
2011-05-30 18:34 ` Arun Sharma
2011-05-31 10:50 ` Ingo Molnar
2011-07-13 13:38 ` Maximilian Engelhardt
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=20110527211419.GA6793@dev1756.snc6.facebook.com \
--to=asharma@fb.com \
--cc=Yann.Dupont@univ-nantes.fr \
--cc=davem@davemloft.net \
--cc=denys@visp.net.lb \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maxi@daemonizer.de \
--cc=mingo@elte.hu \
--cc=netdev@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=vorstand@stusta.mhn.de \
/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