DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH 3/4] eal/x86: reduce contention when retrying TSX
Date: Mon,  5 Nov 2018 17:39:12 +0000	[thread overview]
Message-ID: <20181105173913.61225-4-bruce.richardson@intel.com> (raw)
In-Reply-To: <20181105173913.61225-1-bruce.richardson@intel.com>

When TSX transactions abort, it is generally worth retrying a number of
times before falling back to the traditional locking path, as the
parallelism benefits from TSX can be worth it when a transaction does
succeed. For cases with multiple threads and high contention rates, it can
be useful to have increasing delays between retry attempts, so as to avoid
having the same threads repeatedly collide.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_eal/common/include/arch/x86/rte_spinlock.h | 19 ++++++++++++++++---
 lib/librte_eal/linuxapp/eal/eal_alarm.c               |  2 ++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/include/arch/x86/rte_spinlock.h b/lib/librte_eal/common/include/arch/x86/rte_spinlock.h
index 60321da..961a3c0 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_spinlock.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_spinlock.h
@@ -15,8 +15,9 @@
 #include "rte_branch_prediction.h"
 #include "rte_common.h"
 #include "rte_pause.h"
+#include "rte_cycles.h"
 
-#define RTE_RTM_MAX_RETRIES (10)
+#define RTE_RTM_MAX_RETRIES (20)
 #define RTE_XABORT_LOCK_BUSY (0xff)
 
 #ifndef RTE_FORCE_INTRINSICS
@@ -87,7 +88,7 @@ static inline int rte_tm_supported(void)
 
 		unsigned int status = rte_xbegin();
 
-		if (likely(RTE_XBEGIN_STARTED == status)) {
+		if (RTE_XBEGIN_STARTED == status) {
 			if (unlikely(*lock))
 				rte_xabort(RTE_XABORT_LOCK_BUSY);
 			else
@@ -97,8 +98,20 @@ static inline int rte_tm_supported(void)
 			rte_pause();
 
 		if ((status & RTE_XABORT_EXPLICIT) &&
-			(RTE_XABORT_CODE(status) == RTE_XABORT_LOCK_BUSY))
+		    (RTE_XABORT_CODE(status) == RTE_XABORT_LOCK_BUSY)) {
+			/* add a small delay before retrying, basing the
+			 * delay on the number of times we've already tried,
+			 * to give a back-off type of behaviour. We
+			 * randomize trycount by taking bits from the tsc count
+			 */
+			int try_count = RTE_RTM_MAX_RETRIES - retries;
+			int pause_count = (rte_rdtsc() & 0x7) | 1;
+			pause_count <<= try_count;
+			int i;
+			for (i = 0; i < pause_count; i++)
+				rte_pause();
 			continue;
+		}
 
 		if ((status & RTE_XABORT_RETRY) == 0) /* do not retry */
 			break;
diff --git a/lib/librte_eal/linuxapp/eal/eal_alarm.c b/lib/librte_eal/linuxapp/eal/eal_alarm.c
index 391d2a6..840ede7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_alarm.c
+++ b/lib/librte_eal/linuxapp/eal/eal_alarm.c
@@ -30,7 +30,9 @@
 #define NS_PER_US 1000
 #define US_PER_MS 1000
 #define MS_PER_S 1000
+#ifndef US_PER_S
 #define US_PER_S (US_PER_MS * MS_PER_S)
+#endif
 
 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
-- 
1.8.5.6

  parent reply	other threads:[~2018-11-05 17:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-05 17:39 [dpdk-dev] [PATCH 0/4] fixes for rte_hash with TSX Bruce Richardson
2018-11-05 17:39 ` [dpdk-dev] [PATCH 1/4] hash: fix TSX aborts with newer gcc Bruce Richardson
2018-11-05 17:39 ` [dpdk-dev] [PATCH 2/4] hash: add local cache for TSX region Bruce Richardson
2018-11-09 15:59   ` Bruce Richardson
2018-11-05 17:39 ` Bruce Richardson [this message]
2018-11-05 17:39 ` [dpdk-dev] [PATCH 4/4] test/test: improve output for hash read-write test Bruce Richardson
2018-11-12 10:47 ` [dpdk-dev] [PATCH v2 0/4] fixes for rte_hash with TSX Bruce Richardson
2018-11-12 10:47   ` [dpdk-dev] [PATCH v2 1/4] hash: fix TSX aborts with newer gcc Bruce Richardson
2018-11-12 10:47   ` [dpdk-dev] [PATCH v2 2/4] hash: add local cache for TSX region Bruce Richardson
2018-11-12 18:34     ` Honnappa Nagarahalli
2018-11-13 16:40       ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2018-11-13 17:16         ` Honnappa Nagarahalli
2018-11-13 17:24           ` Wang, Yipeng1
2018-11-13 17:48             ` Bruce Richardson
2018-11-12 10:47   ` [dpdk-dev] [PATCH v2 3/4] eal/x86: reduce contention when retrying TSX Bruce Richardson
2018-11-12 10:47   ` [dpdk-dev] [PATCH v2 4/4] test/test: improve output for hash read-write test Bruce Richardson
2018-11-14  0:06   ` [dpdk-dev] [PATCH v2 0/4] fixes for rte_hash with TSX Thomas Monjalon

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=20181105173913.61225-4-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /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).