DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
To: "gavin.hu@arm.com" <gavin.hu@arm.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: "i.maximets@samsung.com" <i.maximets@samsung.com>,
	"chaozhu@linux.vnet.ibm.com" <chaozhu@linux.vnet.ibm.com>,
	"nd@arm.com" <nd@arm.com>,
	"nipun.gupta@nxp.com" <nipun.gupta@nxp.com>,
	"thomas@monjalon.net" <thomas@monjalon.net>,
	"hemant.agrawal@nxp.com" <hemant.agrawal@nxp.com>,
	"stable@dpdk.org" <stable@dpdk.org>,
	"Honnappa.Nagarahalli@arm.com" <Honnappa.Nagarahalli@arm.com>
Subject: Re: [dpdk-dev] [EXT] [PATCH v8 3/3] spinlock: reimplement with atomic one-way barrier builtins
Date: Tue, 12 Mar 2019 14:53:41 +0000	[thread overview]
Message-ID: <cac33527947a4c5019a4d57f8aabd5d747a48fe6.camel@marvell.com> (raw)
In-Reply-To: <1552031797-146710-4-git-send-email-gavin.hu@arm.com>

On Fri, 2019-03-08 at 15:56 +0800, Gavin Hu wrote:
> -------------------------------------------------------------------
> ---
> The __sync builtin based implementation generates full memory
> barriers
> ('dmb ish') on Arm platforms. Using C11 atomic builtins to generate
> one way
> barriers.
> 
> 
>  lib/librte_eal/common/include/generic/rte_spinlock.h | 18
> +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_eal/common/include/generic/rte_spinlock.h
> b/lib/librte_eal/common/include/generic/rte_spinlock.h
> index c4c3fc3..87ae7a4 100644
> --- a/lib/librte_eal/common/include/generic/rte_spinlock.h
> +++ b/lib/librte_eal/common/include/generic/rte_spinlock.h
> @@ -61,9 +61,14 @@ rte_spinlock_lock(rte_spinlock_t *sl);
>  static inline void
>  rte_spinlock_lock(rte_spinlock_t *sl)
>  {
> -	while (__sync_lock_test_and_set(&sl->locked, 1))
> -		while(sl->locked)
> +	int exp = 0;
> +
> +	while (!__atomic_compare_exchange_n(&sl->locked, &exp, 1, 0,
> +				__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {

Would it be clean to use __atomic_test_and_set()
to avoid explicit exp =
0.


> +		while (__atomic_load_n(&sl->locked, __ATOMIC_RELAXED))
>  			rte_pause();
> +		exp = 0;
> +	}
>  }
>  #endif
>  
> @@ -80,7 +85,7 @@ rte_spinlock_unlock (rte_spinlock_t *sl);
>  static inline void
>  rte_spinlock_unlock (rte_spinlock_t *sl)
>  {
> -	__sync_lock_release(&sl->locked);
> +	__atomic_store_n(&sl->locked, 0, __ATOMIC_RELEASE);

__atomic_clear(.., __ATOMIC_RELEASE) looks more clean to me.

>  }
>  #endif
>  
> @@ -99,7 +104,10 @@ rte_spinlock_trylock (rte_spinlock_t *sl);
>  static inline int
>  rte_spinlock_trylock (rte_spinlock_t *sl)
>  {
> -	return __sync_lock_test_and_set(&sl->locked,1) == 0;
> +	int exp = 0;
> +	return __atomic_compare_exchange_n(&sl->locked, &exp, 1,
> +				0, /* disallow spurious failure */
> +				__ATOMIC_ACQUIRE, __ATOMIC_RELAXED);

return  (__atomic_test_and_set(.., __ATOMIC_ACQUIRE) == 0) will be more
clean version.

>  }
>  #endif
>  
> @@ -113,7 +121,7 @@ rte_spinlock_trylock (rte_spinlock_t *sl)
>   */
>  static inline int rte_spinlock_is_locked (rte_spinlock_t *sl)
>  {
> -	return sl->locked;
> +	return __atomic_load_n(&sl->locked, __ATOMIC_ACQUIRE);

Does __ATOMIC_RELAXED will be sufficient?


>  }
>  
>  /**

  reply	other threads:[~2019-03-12 14:53 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-20 10:42 [dpdk-dev] [PATCH v1 0/5] spinlock optimization and test case enhancements Gavin Hu
2018-12-20 10:42 ` [dpdk-dev] [PATCH v1 1/5] test/spinlock: remove 1us delay for correct spinlock benchmarking Gavin Hu
2018-12-20 10:42 ` [dpdk-dev] [PATCH v1 2/5] test/spinlock: get timestamp more precisely Gavin Hu
2018-12-20 10:42 ` [dpdk-dev] [PATCH v1 3/5] test/spinlock: amortize the cost of getting time Gavin Hu
2018-12-20 10:42 ` [dpdk-dev] [PATCH v1 4/5] spinlock: move the implementation to arm specific file Gavin Hu
2018-12-20 12:47   ` David Marchand
2018-12-20 12:55     ` David Marchand
2018-12-20 14:40       ` Gavin Hu (Arm Technology China)
2018-12-20 14:36     ` Gavin Hu (Arm Technology China)
2018-12-20 15:09       ` David Marchand
2018-12-20 15:58         ` Gavin Hu (Arm Technology China)
2018-12-20 15:59           ` David Marchand
2018-12-20 10:42 ` [dpdk-dev] [PATCH v1 5/5] spinlock: reimplement with atomic one-way barrier builtins Gavin Hu
2018-12-20 17:42 ` [dpdk-dev] [PATCH v2 0/5] spinlock optimization and test case enhancements Gavin Hu
2018-12-20 17:42   ` [dpdk-dev] [PATCH v2 1/5] test/spinlock: remove 1us delay for correct benchmarking Gavin Hu
2018-12-20 17:42   ` [dpdk-dev] [PATCH v2 2/5] test/spinlock: get timestamp more precisely Gavin Hu
2018-12-20 17:42   ` [dpdk-dev] [PATCH v2 3/5] test/spinlock: amortize the cost of getting time Gavin Hu
2018-12-20 17:42   ` [dpdk-dev] [PATCH v2 4/5] spinlock: reimplement with atomic one-way barrier builtins Gavin Hu
2018-12-20 17:42   ` [dpdk-dev] [PATCH v2 5/5] eal: fix clang compilation error on x86 Gavin Hu
2019-01-15  7:54 ` [dpdk-dev] [PATCH v4 0/4] spinlock optimization and test case enhancements gavin hu
2019-01-15  7:54 ` [dpdk-dev] [PATCH v4 1/4] eal: fix clang compilation error on x86 gavin hu
2019-01-15  7:54 ` [dpdk-dev] [PATCH v4 2/4] test/spinlock: remove 1us delay for correct benchmarking gavin hu
2019-01-15  7:54 ` [dpdk-dev] [PATCH v4 3/4] test/spinlock: amortize the cost of getting time gavin hu
2019-01-15  7:54 ` [dpdk-dev] [PATCH v4 4/4] spinlock: reimplement with atomic one-way barrier builtins gavin hu
2019-01-15 10:32 ` [dpdk-dev] [PATCH v5 0/4] spinlock optimization and test case enhancements gavin hu
2019-01-15 10:32 ` [dpdk-dev] [PATCH v5 1/4] eal: fix clang compilation error on x86 gavin hu
2019-01-15 17:42   ` Honnappa Nagarahalli
2019-01-15 10:32 ` [dpdk-dev] [PATCH v5 2/4] test/spinlock: remove 1us delay for correct benchmarking gavin hu
2019-01-15 10:32 ` [dpdk-dev] [PATCH v5 3/4] test/spinlock: amortize the cost of getting time gavin hu
2019-01-15 10:32 ` [dpdk-dev] [PATCH v5 4/4] spinlock: reimplement with atomic one-way barrier builtins gavin hu
2019-03-08  7:16 ` [dpdk-dev] [PATCH v6 0/3] generic spinlock optimization and test case enhancements Gavin Hu
2019-03-08  7:16 ` [dpdk-dev] [PATCH v6 1/3] test/spinlock: dealy 1 us to create contention Gavin Hu
2019-03-08  7:16 ` [dpdk-dev] [PATCH v6 2/3] test/spinlock: amortize the cost of getting time Gavin Hu
2019-03-08  7:16 ` [dpdk-dev] [PATCH v6 3/3] spinlock: reimplement with atomic one-way barrier builtins Gavin Hu
2019-03-08  7:37 ` [dpdk-dev] [PATCH v7 0/3] generic spinlock optimization and test case enhancements Gavin Hu
2019-03-08  7:37 ` [dpdk-dev] [PATCH v7 1/3] test/spinlock: remove 1us delay for correct benchmarking Gavin Hu
2019-03-08  7:37 ` [dpdk-dev] [PATCH v7 2/3] test/spinlock: amortize the cost of getting time Gavin Hu
2019-03-08  7:37 ` [dpdk-dev] [PATCH v7 3/3] spinlock: reimplement with atomic one-way barrier builtins Gavin Hu
2019-03-08  7:56 ` [dpdk-dev] [PATCH v8 0/3] generic spinlock optimization and test case enhancements Gavin Hu
2019-03-11 12:21   ` Nipun Gupta
2019-03-15 12:21   ` Ananyev, Konstantin
2019-03-15 12:21     ` Ananyev, Konstantin
2019-03-28  7:47   ` Thomas Monjalon
2019-03-28  7:47     ` Thomas Monjalon
2019-03-08  7:56 ` [dpdk-dev] [PATCH v8 1/3] test/spinlock: remove 1us delay for correct benchmarking Gavin Hu
2019-03-08  7:56 ` [dpdk-dev] [PATCH v8 2/3] test/spinlock: amortize the cost of getting time Gavin Hu
2019-03-08  7:56 ` [dpdk-dev] [PATCH v8 3/3] spinlock: reimplement with atomic one-way barrier builtins Gavin Hu
2019-03-12 14:53   ` Jerin Jacob Kollanukkaran [this message]
2019-03-14  0:31     ` [dpdk-dev] [EXT] " Honnappa Nagarahalli
2019-03-14  0:31       ` Honnappa Nagarahalli
2019-03-14  2:36       ` Gavin Hu (Arm Technology China)
2019-03-14  2:36         ` Gavin Hu (Arm Technology China)
2019-03-14 14:22   ` Jerin Jacob Kollanukkaran
2019-03-14 14:22     ` Jerin Jacob Kollanukkaran

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=cac33527947a4c5019a4d57f8aabd5d747a48fe6.camel@marvell.com \
    --to=jerinj@marvell.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=chaozhu@linux.vnet.ibm.com \
    --cc=dev@dpdk.org \
    --cc=gavin.hu@arm.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=i.maximets@samsung.com \
    --cc=nd@arm.com \
    --cc=nipun.gupta@nxp.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    /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).