sr-761-b.patch 4.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
From 9523f10395e54ee354e4c577b2657bd1df4f305a Mon Sep 17 00:00:00 2001
From: Hubertus Franke <frankeh@us.ibm.com>
Date: Wed, 24 Feb 2016 17:58:40 -0500
Subject: [PATCH] Enable notification to libpwq before semaphore waiting

Drew's reroll with:

* libpwq update to origin/master (e16bcd6c4b4df3fd85939a981baf94b30968a1ba)
* futex support (although it doesn't fix deadlock) per https://bugs.swift.org/browse/SR-761?focusedCommentId=12435&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12435
* More futex support (although it doesn't fix deadlock) per https://bugs.swift.org/browse/SR-761?focusedCommentId=12442&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12442
* Disabling futex to fix deadlock per https://bugs.swift.org/browse/SR-761?focusedCommentId=12440&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12440

Signed-off-by: Drew Crawford <drew@sealedabstract.com>
---
 configure.ac    |  3 ---
 libpwq          |  2 +-
 src/semaphore.c | 15 +++++++++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 73dd498..2696bed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -301,9 +301,6 @@ AC_MSG_CHECKING([what semaphore type to use]);
 AS_IF([test "x$have_mach" = "xtrue"],
   [AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores])
     AC_MSG_RESULT([Mach semaphores])],
-  [test "x$have_futex" = "xtrue"],
-  [AC_DEFINE(USE_FUTEX_SEM, 1, [Define to use Futex semaphores])
-    AC_MSG_RESULT([Futex semaphores])],
   [test "x$have_sem_init" = "xtrue"],
   [AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores])
     AC_MSG_RESULT([POSIX semaphores])],
diff --git a/libpwq b/libpwq
index 4312f99..e16bcd6 160000
--- a/libpwq
+++ b/libpwq
@@ -1 +1 @@
-Subproject commit 4312f994da24d35fb355ad6701418752ab8fdf3a
+Subproject commit e16bcd6c4b4df3fd85939a981baf94b30968a1ba
diff --git a/src/semaphore.c b/src/semaphore.c
index db40161..9f6055d 100644
--- a/src/semaphore.c
+++ b/src/semaphore.c
@@ -301,6 +301,13 @@ dispatch_semaphore_signal(dispatch_semaphore_t dsema)
 	return _dispatch_semaphore_signal_slow(dsema);
 }
 
+#if (USE_POSIX_SEM || USE_FUTEX_SEM) && HAVE_PTHREAD_WORKQUEUES
+extern void pthread_workqueue_signal_np(void);
+#define _dispatch_threadmgr_inform_wait() pthread_workqueue_signal_np()
+#else
+#define _dispatch_threadmgr_inform_wait()  do { } while (0)
+#endif
+
 DISPATCH_NOINLINE
 static long
 _dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
@@ -371,6 +378,7 @@ again:
 			uint64_t nsec = _dispatch_time_to_nanoseconds(timeout);
 			_timeout.tv_sec = (typeof(_timeout.tv_sec))(nsec / NSEC_PER_SEC);
 			_timeout.tv_nsec = (typeof(_timeout.tv_nsec))(nsec % NSEC_PER_SEC);
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(sem_timedwait(&dsema->dsema_sem, &_timeout));
 		} while (ret == -1 && errno == EINTR);
 
@@ -383,6 +391,7 @@ again:
 			uint64_t nsec = _dispatch_time_to_nanoseconds(timeout);
 			_timeout.tv_sec = (typeof(_timeout.tv_sec))(nsec / NSEC_PER_SEC);
 			_timeout.tv_nsec = (typeof(_timeout.tv_nsec))(nsec % NSEC_PER_SEC);
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(_dispatch_futex_wait(&dsema->dsema_futex, &_timeout));
 		} while (ret == false && errno == EINTR);
 
@@ -425,11 +434,13 @@ again:
 		DISPATCH_SEMAPHORE_VERIFY_KR(kr);
 #elif USE_POSIX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = sem_wait(&dsema->dsema_sem);
 		} while (ret != 0);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
 #elif USE_FUTEX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = _dispatch_futex_wait(&dsema->dsema_futex, NULL);
 		} while (ret == false && errno == EINTR);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
@@ -636,6 +647,7 @@ again:
 			uint64_t nsec = _dispatch_time_to_nanoseconds(timeout);
 			_timeout.tv_sec = (typeof(_timeout.tv_sec))(nsec / NSEC_PER_SEC);
 			_timeout.tv_nsec = (typeof(_timeout.tv_nsec))(nsec % NSEC_PER_SEC);
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(sem_timedwait(&dsema->dsema_sem, &_timeout));
 		} while (ret == -1 && errno == EINTR);
 
@@ -649,6 +661,7 @@ again:
 			uint64_t nsec = _dispatch_timeout(timeout);
 			_timeout.tv_sec = nsec / NSEC_PER_SEC;
 			_timeout.tv_nsec = nsec % NSEC_PER_SEC;
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(_dispatch_futex_wait(&dsema->dsema_futex, &_timeout));
 		} while (ret == false && errno == EINTR);
 
@@ -691,11 +704,13 @@ again:
 		DISPATCH_GROUP_VERIFY_KR(kr);
 #elif USE_POSIX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = sem_wait(&dsema->dsema_sem);
 		} while (ret == -1 && errno == EINTR);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
 #elif USE_FUTEX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = _dispatch_futex_wait(&dsema->dsema_futex, NULL);
 		} while (ret == false && errno == EINTR);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
-- 
2.5.4 (Apple Git-61)