DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Gavin Hu (Arm Technology China)" <Gavin.Hu@arm.com>
To: "jerinj@marvell.com" <jerinj@marvell.com>,
	Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Cc: "david.marchand@redhat.com" <david.marchand@redhat.com>,
	"chaozhu@linux.vnet.ibm.com" <chaozhu@linux.vnet.ibm.com>,
	nd <nd@arm.com>,
	"bruce.richardson@intel.com" <bruce.richardson@intel.com>,
	"thomas@monjalon.net" <thomas@monjalon.net>,
	"Joyce Kong (Arm Technology China)" <Joyce.Kong@arm.com>,
	"hemant.agrawal@nxp.com" <hemant.agrawal@nxp.com>,
	"stephen@networkplumber.org" <stephen@networkplumber.org>
Subject: Re: [dpdk-dev] [EXT] [PATCH v3 5/6] spinlock: reimplement with atomic one-way barrier builtins
Date: Mon, 14 Jan 2019 17:08:26 +0000	[thread overview]
Message-ID: <VI1PR08MB316719BE8656CC4AD3022CE58F800@VI1PR08MB3167.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <151223caad2754b36e4887bb2b1d1dfec2094e3e.camel@marvell.com>

> > > > > *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))
> > > > {
> > > >
> > > > How about remove explict exp = 0 and change to
> > > > __atomic_test_and_set(flag, __ATOMIC_ACQUIRE);
> > >
> > > Yes, __atomic_test_and_set means simpler code and better, but
> > > __atomic_test_and_set takes the first argument as a pointer to type
> > > bool or
> > > char, in our case, sl->locked is of type uint32.
> > > We can force it to uint8, or just pass in the 32bit pointer, only
> > > one byte/bit is
> > > really used in this case, is that ok?
> > >
> > > "It should be only used for operands of type bool or char. For
> > > other types only
> > > part of the value may be set."
> > > https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/_005f_005fatomic-
> > > Builtins.html
> > >
> > > From performance perspective, in our testing, the performance was
> > > very close,
> > > compared to __atomic.
> > If performance is close, I suggest we go with the existing patch.
> > Changing sl->locked to bool/char would be an ABI change and will
> > affect x86 TM based implementation as well.
> > Jerin, what do you think?
> 
> Looks good to me.
> 
I tested __atomic_test_and_test based patch(I did not push this, it is in internal review), it caused 10 times performance degradation on ThunderX2.
In the internal review, Ola Liljedahl's comment well explained the degradation:
"Unlike the old code, the new code will write the lock location (and thus get exclusive access to the whole cache line) repeatedly while it is busy waiting. This is bad for the lock owner if it is accessing other data located in the same cache line as the lock (which is often the case)."
The real difference is __atomic_test_and_test keeps writing the lock location(whether it is locked or not) and monopolizing the cache line, it is bad to the lock owner and other contenders. 

  reply	other threads:[~2019-01-14 17:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27  4:13 [dpdk-dev] [PATCH v3 0/6] spinlock optimization and test case enhancements Gavin Hu
2018-12-27  4:13 ` [dpdk-dev] [PATCH v3 1/6] eal: fix clang compilation error on x86 Gavin Hu
2018-12-27  6:36   ` [dpdk-dev] [EXT] " Jerin Jacob Kollanukkaran
2018-12-27  4:13 ` [dpdk-dev] [PATCH v3 2/6] test/spinlock: remove 1us delay for correct benchmarking Gavin Hu
2018-12-27  7:20   ` [dpdk-dev] [EXT] " Jerin Jacob Kollanukkaran
2018-12-27  4:13 ` [dpdk-dev] [PATCH v3 3/6] test/spinlock: get timestamp more precisely Gavin Hu
2018-12-27  7:27   ` [dpdk-dev] [EXT] " Jerin Jacob Kollanukkaran
2019-01-03 18:22     ` Honnappa Nagarahalli
2018-12-27  4:13 ` [dpdk-dev] [PATCH v3 4/6] test/spinlock: amortize the cost of getting time Gavin Hu
2018-12-27  4:13 ` [dpdk-dev] [PATCH v3 5/6] spinlock: reimplement with atomic one-way barrier builtins Gavin Hu
2018-12-27  7:42   ` [dpdk-dev] [EXT] " Jerin Jacob Kollanukkaran
2018-12-27  9:02     ` Gavin Hu (Arm Technology China)
2019-01-03 20:35       ` Honnappa Nagarahalli
2019-01-11 13:52     ` Gavin Hu (Arm Technology China)
2019-01-14  5:54       ` Honnappa Nagarahalli
2019-01-14  7:39         ` Jerin Jacob Kollanukkaran
2019-01-14 17:08           ` Gavin Hu (Arm Technology China) [this message]
2019-01-14  7:57         ` Gavin Hu (Arm Technology China)
2018-12-27  4:13 ` [dpdk-dev] [PATCH v3 6/6] spinlock: ticket based to improve fairness Gavin Hu
2018-12-27  6:58   ` [dpdk-dev] [EXT] " Jerin Jacob Kollanukkaran
2018-12-27 10:05     ` Gavin Hu (Arm Technology China)
2018-12-27 12:08       ` Jerin Jacob Kollanukkaran
2018-12-27 23:41         ` Stephen Hemminger
2018-12-28  4:39           ` Jerin Jacob Kollanukkaran
2018-12-28 10:04             ` Gavin Hu (Arm Technology China)
2019-01-03 18:35             ` Honnappa Nagarahalli
2019-01-03 19:53               ` Stephen Hemminger
2019-01-04  7:06                 ` Honnappa Nagarahalli

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=VI1PR08MB316719BE8656CC4AD3022CE58F800@VI1PR08MB3167.eurprd08.prod.outlook.com \
    --to=gavin.hu@arm.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=Joyce.Kong@arm.com \
    --cc=bruce.richardson@intel.com \
    --cc=chaozhu@linux.vnet.ibm.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=jerinj@marvell.com \
    --cc=nd@arm.com \
    --cc=stephen@networkplumber.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).