DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] spinlock: fix atomic and out of order execution
@ 2013-12-20 23:37 Thomas Monjalon
  2014-01-02 16:32 ` Stephen Hemminger
  2014-01-10 18:02 ` François-Frédéric Ozog
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Monjalon @ 2013-12-20 23:37 UTC (permalink / raw)
  To: dev

From: Damien Millescamps <damien.millescamps@6wind.com>

Add lock prefix before xchg instructions in order to be atomic
and flush speculative values to ensure effective execution order
(as an acquire barrier).

MPLOCKED is a "lock" in multicore case.

Signed-off-by: Damien Millescamps <damien.millescamps@6wind.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 lib/librte_eal/common/include/rte_spinlock.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_spinlock.h b/lib/librte_eal/common/include/rte_spinlock.h
index f7a245a..8edb971 100644
--- a/lib/librte_eal/common/include/rte_spinlock.h
+++ b/lib/librte_eal/common/include/rte_spinlock.h
@@ -51,6 +51,7 @@
 extern "C" {
 #endif
 
+#include <rte_atomic.h>
 #include <rte_lcore.h>
 #ifdef RTE_FORCE_INTRINSICS
 #include <rte_common.h>
@@ -93,7 +94,7 @@ rte_spinlock_lock(rte_spinlock_t *sl)
 	int lock_val = 1;
 	asm volatile (
 			"1:\n"
-			"xchg %[locked], %[lv]\n"
+			MPLOCKED "xchg %[locked], %[lv]\n"
 			"test %[lv], %[lv]\n"
 			"jz 3f\n"
 			"2:\n"
@@ -124,7 +125,7 @@ rte_spinlock_unlock (rte_spinlock_t *sl)
 #ifndef RTE_FORCE_INTRINSICS
 	int unlock_val = 0;
 	asm volatile (
-			"xchg %[locked], %[ulv]\n"
+			MPLOCKED "xchg %[locked], %[ulv]\n"
 			: [locked] "=m" (sl->locked), [ulv] "=q" (unlock_val)
 			: "[ulv]" (unlock_val)
 			: "memory");
@@ -148,7 +149,7 @@ rte_spinlock_trylock (rte_spinlock_t *sl)
 	int lockval = 1;
 
 	asm volatile (
-			"xchg %[locked], %[lockval]"
+			MPLOCKED "xchg %[locked], %[lockval]"
 			: [locked] "=m" (sl->locked), [lockval] "=q" (lockval)
 			: "[lockval]" (lockval)
 			: "memory");
-- 
1.7.10.4

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

end of thread, other threads:[~2014-01-10 18:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-20 23:37 [dpdk-dev] [PATCH] spinlock: fix atomic and out of order execution Thomas Monjalon
2014-01-02 16:32 ` Stephen Hemminger
2014-01-10 18:02 ` François-Frédéric Ozog

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).