Fix: thread exit vs futex wait/wakeup race
A message that is not in the archive (sent off-list or not yet received): [email protected]
Merged in master, stable-2.10, stable-2.9, and stable-2.8.
Thanks!
Jérémie
Quoted 103 lines · Mathieu Desnoyers
relayd_live_stopperforms, in this order:
CMM_STORE_SHARED(live_dispatch_thread_exit, 1); [A]
futex_nto1_wake(&viewer_conn_queue.futex); [B]whereas
thread_dispatcherdoes:while (!CMM_LOAD_SHARED(live_dispatch_thread_exit)) { [1] [...] futex_nto1_prepare(&viewer_conn_queue.futex); [2] [...] futex_nto1_wait(&viewer_conn_queue.futex); [3]Unfortunately, on the following sequence:
[1] [A] [B] [2] [3]
thread_dispatcherwill end up hanging.We need to move the
live_dispatch_thread_exitload between "prepare" and "wait" to fix this.There are similar scenarios with
relay_thread_dispatcher, and the session daemonthread_dispatch_ust_registration, which are also fixed here.Signed-off-by Mathieu Desnoyers <[email protected]>--- src/bin/lttng-relayd/live.c | 6 +++++- src/bin/lttng-relayd/main.c | 6 +++++- src/bin/lttng-sessiond/main.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-)src/bin/lttng-relayd/live.c +5
-1@@ -654,12 +654,16 @@ void *thread_dispatcher(void *data)health_code_update (); -while (!CMM_LOAD_SHARED (live_dispatch_thread_exit)) { +for (;;) {health_code_update ();/* Atomically prepare the queue futex */ futex_nto1_prepare (&viewer_conn_queue.futex); +if (CMM_LOAD_SHARED (live_dispatch_thread_exit)) { +break ; + } + do { health_code_update();src/bin/lttng-relayd/main.c +5
-1@@ -977,12 +977,16 @@ static void *relay_thread_dispatcher(void *data)health_code_update (); -while (!CMM_LOAD_SHARED (dispatch_thread_exit)) { +for (;;) {health_code_update ();/* Atomically prepare the queue futex */ futex_nto1_prepare (&relay_conn_queue.futex); +if (CMM_LOAD_SHARED (dispatch_thread_exit)) { +break ; + } + do { health_code_update();src/bin/lttng-sessiond/main.c +5
-2@@ -1934,12 +1934,16 @@ static void *thread_dispatch_ust_registration(void *data)DBG ("[thread] Dispatch UST command started" ); -while (!CMM_LOAD_SHARED (dispatch_thread_exit)) { +for (;;) {health_code_update ();/* Atomically prepare the queue futex */ futex_nto1_prepare (&ust_cmd_queue.futex); +if (CMM_LOAD_SHARED (dispatch_thread_exit)) { +break ; + } + do { struct ust_app *app = NULL; ust_cmd = NULL; --2.1.4
Signature · 7 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev