From: Stephen Hemminger <stephen@networkplumber.org>
To: Thomas Monjalon <thomas.monjalon@6wind.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] spinlock: fix atomic and out of order execution
Date: Thu, 2 Jan 2014 08:32:42 -0800 [thread overview]
Message-ID: <20140102083242.4651a353@nehalam.linuxnetplumber.net> (raw)
In-Reply-To: <1387582656-1892-1-git-send-email-thomas.monjalon@6wind.com>
On Sat, 21 Dec 2013 00:37:36 +0100
Thomas Monjalon <thomas.monjalon@6wind.com> wrote:
> 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");
The locked prefix is required for xchg instruction.
The processor does it automatically.
http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html
"The XCHG (exchange) instruction swaps the contents of two operands. This instruction takes the place of three
MOV instructions and does not require a temporary location to save the contents of one operand location while the
other is being loaded. When a memory operand is used with the XCHG instruction, the processor’s LOCK signal is
automatically asserted.
next prev parent reply other threads:[~2014-01-02 16:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-20 23:37 Thomas Monjalon
2014-01-02 16:32 ` Stephen Hemminger [this message]
2014-01-10 18:02 ` François-Frédéric Ozog
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=20140102083242.4651a353@nehalam.linuxnetplumber.net \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=thomas.monjalon@6wind.com \
/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;
as well as URLs for NNTP newsgroup(s).