Blame SOURCES/0027-Implement-queueing-of-threads-before-dispatching-the.patch

904f19
From 496f922dad9b58b891f417b937ac5fb0b0a8649a Mon Sep 17 00:00:00 2001
904f19
From: Eugene Syromyatnikov <evgsyr@gmail.com>
904f19
Date: Wed, 8 Aug 2018 21:41:39 +0200
904f19
Subject: [PATCH 27/27] Implement queueing of threads before dispatching them
904f19
904f19
It is possible that some tracees call a lot of cheap syscalls too fast,
904f19
and that can stress the tracer to the point some tracees are not served
904f19
for indefinite amount of time.  In order to avoid that unfairness, try
904f19
to collect all the pending tracees first along with the relevant
904f19
information and only then dispatch the events.
904f19
904f19
* defs.h: Include "list.h".
904f19
(struct tcb): Add wait_data_idx, delayed_wait_data, and wait_list
904f19
fields.
904f19
* strace.c (struct tcb_wait_data): Add "msg" field.
904f19
(tcb_wait_tab, tcb_wait_tab_size): New static variables.
904f19
(alloctcb): Initialize wait_list.
904f19
(droptcb): Remove tcp from wait_list.
904f19
(maybe_switch_tcbs): Get old pid from
904f19
tcb_wait_tab[tcp->wait_data_idx].msg instead of calling
904f19
ptrace(PTRACE_GETEVENTMSG).
904f19
(trace_wait_data_size, init_trace_wait_data, copy_trace_wait_data,
904f19
free_trace_wait_data, tcb_wait_tab_check_size): New functions, in order
904f19
to allow the code outside next_event to operate with wait_data as with
904f19
an opaque object (needed for dispatch_event and restart_delayed_tcb).
904f19
(next_event): Add pending_tcps, extra_tcp, wait_nohang, elem, and
904f19
wait_tab_pos variables; check for elements in pending_tcps and skip
904f19
waiting if the list is not empty; check for extra_tcp and skip waiting
904f19
along with swapping wait_data_idx with wait_extra_data_idx;
904f19
after the initial wait4(), call wait4() in loop with WNOHANG flag set;
904f19
fetch siginfo on signal and eventmsg on PTRACE_EVENT_EXEC;
904f19
return the first tcp in pending_tcps list.
904f19
(dispatch_event): Store a pointer to a copy of tcb_wait_data in
904f19
tcp->delayed_wait_data if tcp's restart has to be delayed.
904f19
(restart_delayed_tcb): Use tcp->delayed_wait_data, create a stub
904f19
tcb_wait_data if it is NULL, free temporary trace_wait_data.
904f19
* tests/Makefile.am (XFAIL_TEST): Remove looping_threads.test.
904f19
904f19
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=478419
904f19
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=526740
904f19
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=851457
904f19
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1609318
904f19
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1610774
904f19
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
904f19
Co-Authored-by: Denys Vlasenko <dvlasenk@redhat.com>
904f19
Co-Authored-by: Andreas Schwab <aschwab@redhat.com>
904f19
Co-Authored-by: Jeff Law <law@redhat.com>
904f19
Co-Authored-by: DJ Delorie <dj@redhat.com>
904f19
904f19
Conflicts:
904f19
	defs.h
904f19
	tests/Makefile.am
904f19
---
904f19
 defs.h            |  12 ++
904f19
 strace.c          | 393 +++++++++++++++++++++++++++++++++++++-----------------
904f19
 tests/Makefile.am |   3 +-
904f19
 3 files changed, 283 insertions(+), 125 deletions(-)
904f19
904f19
diff --git a/defs.h b/defs.h
904f19
index 811bb0d..2a614a7 100644
904f19
--- a/defs.h
904f19
+++ b/defs.h
904f19
@@ -36,6 +36,7 @@
904f19
 #include "arch_defs.h"
904f19
 #include "error_prints.h"
904f19
 #include "gcc_compat.h"
904f19
+#include "list.h"
904f19
 #include "kernel_types.h"
904f19
 #include "macros.h"
904f19
 #include "mpers_type.h"
904f19
@@ -218,6 +219,17 @@ struct tcb {
904f19
 
904f19
 	struct mmap_cache_t *mmap_cache;
904f19
 
904f19
+	/*
904f19
+	 * Data that is stored during process wait traversal.
904f19
+	 * We use indices as the actual data is stored in an array
904f19
+	 * that is realloc'ed at runtime.
904f19
+	 */
904f19
+	size_t wait_data_idx;
904f19
+	/** Wait data storage for a delayed process. */
904f19
+	struct tcb_wait_data *delayed_wait_data;
904f19
+	struct list_item wait_list;
904f19
+
904f19
+
904f19
 #ifdef HAVE_LINUX_KVM_H
904f19
 	struct vcpu_info *vcpu_info_list;
904f19
 #endif
904f19
diff --git a/strace.c b/strace.c
904f19
index 0745838..0914dc7 100644
904f19
--- a/strace.c
904f19
+++ b/strace.c
904f19
@@ -141,6 +141,7 @@ static struct tcb *current_tcp;
904f19
 struct tcb_wait_data {
904f19
 	enum trace_event te; /**< Event passed to dispatch_event() */
904f19
 	int status;          /**< status, returned by wait4() */
904f19
+	unsigned long msg;   /**< Value returned by PTRACE_GETEVENTMSG */
904f19
 	siginfo_t si;        /**< siginfo, returned by PTRACE_GETSIGINFO */
904f19
 };
904f19
 
904f19
@@ -148,6 +149,10 @@ static struct tcb **tcbtab;
904f19
 static unsigned int nprocs;
904f19
 static size_t tcbtabsize;
904f19
 
904f19
+static struct tcb_wait_data *tcb_wait_tab;
904f19
+static size_t tcb_wait_tab_size;
904f19
+
904f19
+
904f19
 #ifndef HAVE_PROGRAM_INVOCATION_NAME
904f19
 char *program_invocation_name;
904f19
 #endif
904f19
@@ -745,6 +750,7 @@ alloctcb(int pid)
904f19
 		tcp = tcbtab[i];
904f19
 		if (!tcp->pid) {
904f19
 			memset(tcp, 0, sizeof(*tcp));
904f19
+			list_init(&tcp->wait_list);
904f19
 			tcp->pid = pid;
904f19
 #if SUPPORTED_PERSONALITIES > 1
904f19
 			tcp->currpers = current_personality;
904f19
@@ -833,6 +839,8 @@ droptcb(struct tcb *tcp)
904f19
 	if (printing_tcp == tcp)
904f19
 		printing_tcp = NULL;
904f19
 
904f19
+	list_remove(&tcp->wait_list);
904f19
+
904f19
 	memset(tcp, 0, sizeof(*tcp));
904f19
 }
904f19
 
904f19
@@ -2051,10 +2059,8 @@ maybe_switch_tcbs(struct tcb *tcp, const int pid)
904f19
 {
904f19
 	FILE *fp;
904f19
 	struct tcb *execve_thread;
904f19
-	long old_pid = 0;
904f19
+	long old_pid = tcb_wait_tab[tcp->wait_data_idx].msg;
904f19
 
904f19
-	if (ptrace(PTRACE_GETEVENTMSG, pid, NULL, &old_pid) < 0)
904f19
-		return tcp;
904f19
 	/* Avoid truncation in pid2tcb() param passing */
904f19
 	if (old_pid <= 0 || old_pid == pid)
904f19
 		return tcp;
904f19
@@ -2207,20 +2213,74 @@ print_event_exit(struct tcb *tcp)
904f19
 	line_ended();
904f19
 }
904f19
 
904f19
-static const struct tcb_wait_data *
904f19
-next_event(void)
904f19
+static size_t
904f19
+trace_wait_data_size(struct tcb *tcp)
904f19
 {
904f19
-	static struct tcb_wait_data wait_data;
904f19
+	return sizeof(struct tcb_wait_data);
904f19
+}
904f19
 
904f19
-	int pid;
904f19
-	int status;
904f19
-	struct tcb *tcp;
904f19
-	struct tcb_wait_data *wd = &wait_data;
904f19
-	struct rusage ru;
904f19
+static struct tcb_wait_data *
904f19
+init_trace_wait_data(void *p)
904f19
+{
904f19
+	struct tcb_wait_data *wd = p;
904f19
+
904f19
+	memset(wd, 0, sizeof(*wd));
904f19
+
904f19
+	return wd;
904f19
+}
904f19
 
904f19
+static struct tcb_wait_data *
904f19
+copy_trace_wait_data(const struct tcb_wait_data *wd)
904f19
+{
904f19
+	struct tcb_wait_data *new_wd = xmalloc(sizeof(*new_wd));
904f19
+
904f19
+	memcpy(new_wd, wd, sizeof(*wd));
904f19
+
904f19
+	return new_wd;
904f19
+}
904f19
+
904f19
+static void
904f19
+free_trace_wait_data(struct tcb_wait_data *wd)
904f19
+{
904f19
+	free(wd);
904f19
+}
904f19
+
904f19
+static void
904f19
+tcb_wait_tab_check_size(const size_t size)
904f19
+{
904f19
+	while (size >= tcb_wait_tab_size) {
904f19
+		tcb_wait_tab = xgrowarray(tcb_wait_tab,
904f19
+					  &tcb_wait_tab_size,
904f19
+					  sizeof(tcb_wait_tab[0]));
904f19
+	}
904f19
+}
904f19
+
904f19
+static const struct tcb_wait_data *
904f19
+next_event(void)
904f19
+{
904f19
 	if (interrupted)
904f19
 		return NULL;
904f19
 
904f19
+	struct tcb *tcp = NULL;
904f19
+	struct list_item *elem;
904f19
+
904f19
+	static EMPTY_LIST(pending_tcps);
904f19
+	/* Handle the queued tcbs before waiting for new events.  */
904f19
+	if (!list_is_empty(&pending_tcps))
904f19
+		goto next_event_get_tcp;
904f19
+
904f19
+	static struct tcb *extra_tcp;
904f19
+	static size_t wait_extra_data_idx;
904f19
+	/* Handle the extra tcb event.  */
904f19
+	if (extra_tcp) {
904f19
+		tcp = extra_tcp;
904f19
+		extra_tcp = NULL;
904f19
+		tcp->wait_data_idx = wait_extra_data_idx;
904f19
+
904f19
+		debug_msg("dequeued extra event for pid %u", tcp->pid);
904f19
+		goto next_event_exit;
904f19
+	}
904f19
+
904f19
 	/*
904f19
 	 * Used to exit simply when nprocs hits zero, but in this testcase:
904f19
 	 *  int main(void) { _exit(!!fork()); }
904f19
@@ -2262,8 +2322,10 @@ next_event(void)
904f19
 	 * then the system call will be interrupted and
904f19
 	 * the expiration will be handled by the signal handler.
904f19
 	 */
904f19
-	pid = wait4(-1, &status, __WALL, (cflag ? &ru : NULL));
904f19
-	const int wait_errno = errno;
904f19
+	int status;
904f19
+	struct rusage ru;
904f19
+	int pid = wait4(-1, &status, __WALL, (cflag ? &ru : NULL));
904f19
+	int wait_errno = errno;
904f19
 
904f19
 	/*
904f19
 	 * The window of opportunity to handle expirations
904f19
@@ -2279,135 +2341,202 @@ next_event(void)
904f19
 			return NULL;
904f19
 	}
904f19
 
904f19
-	if (pid < 0) {
904f19
-		if (wait_errno == EINTR) {
904f19
-			wd->te = TE_NEXT;
904f19
-			return wd;
904f19
+	size_t wait_tab_pos = 0;
904f19
+	bool wait_nohang = false;
904f19
+
904f19
+	/*
904f19
+	 * Wait for new events until wait4() returns 0 (meaning that there's
904f19
+	 * nothing more to wait for for now), or a second event for some tcb
904f19
+	 * appears (which may happen if a tracee was SIGKILL'ed, for example).
904f19
+	 */
904f19
+	for (;;) {
904f19
+		struct tcb_wait_data *wd;
904f19
+
904f19
+		if (pid < 0) {
904f19
+			if (wait_errno == EINTR)
904f19
+				break;
904f19
+			if (wait_nohang)
904f19
+				break;
904f19
+			if (nprocs == 0 && wait_errno == ECHILD)
904f19
+				return NULL;
904f19
+			/*
904f19
+			 * If nprocs > 0, ECHILD is not expected,
904f19
+			 * treat it as any other error here:
904f19
+			 */
904f19
+			errno = wait_errno;
904f19
+			perror_msg_and_die("wait4(__WALL)");
904f19
 		}
904f19
-		if (nprocs == 0 && wait_errno == ECHILD)
904f19
-			return NULL;
904f19
-		/*
904f19
-		 * If nprocs > 0, ECHILD is not expected,
904f19
-		 * treat it as any other error here:
904f19
-		 */
904f19
-		errno = wait_errno;
904f19
-		perror_msg_and_die("wait4(__WALL)");
904f19
-	}
904f19
 
904f19
-	wd->status = status;
904f19
+		if (!pid)
904f19
+			break;
904f19
 
904f19
-	if (pid == popen_pid) {
904f19
-		if (!WIFSTOPPED(status))
904f19
-			popen_pid = 0;
904f19
-		wd->te = TE_NEXT;
904f19
-		return wd;
904f19
-	}
904f19
+		if (pid == popen_pid) {
904f19
+			if (!WIFSTOPPED(status))
904f19
+				popen_pid = 0;
904f19
+			break;
904f19
+		}
904f19
 
904f19
-	if (debug_flag)
904f19
-		print_debug_info(pid, status);
904f19
+		if (debug_flag)
904f19
+			print_debug_info(pid, status);
904f19
 
904f19
-	/* Look up 'pid' in our table. */
904f19
-	tcp = pid2tcb(pid);
904f19
+		/* Look up 'pid' in our table. */
904f19
+		tcp = pid2tcb(pid);
904f19
 
904f19
-	if (!tcp) {
904f19
-		tcp = maybe_allocate_tcb(pid, status);
904f19
 		if (!tcp) {
904f19
-			wd->te = TE_NEXT;
904f19
-			return wd;
904f19
+			tcp = maybe_allocate_tcb(pid, status);
904f19
+			if (!tcp)
904f19
+				goto next_event_wait_next;
904f19
 		}
904f19
-	}
904f19
 
904f19
-	clear_regs(tcp);
904f19
+		if (cflag) {
904f19
+			struct timespec stime = {
904f19
+				.tv_sec = ru.ru_stime.tv_sec,
904f19
+				.tv_nsec = ru.ru_stime.tv_usec * 1000
904f19
+			};
904f19
+			ts_sub(&tcp->dtime, &stime, &tcp->stime);
904f19
+			tcp->stime = stime;
904f19
+		}
904f19
 
904f19
-	/* Set current output file */
904f19
-	set_current_tcp(tcp);
904f19
+		tcb_wait_tab_check_size(wait_tab_pos);
904f19
 
904f19
-	if (cflag) {
904f19
-		struct timespec stime = {
904f19
-			.tv_sec = ru.ru_stime.tv_sec,
904f19
-			.tv_nsec = ru.ru_stime.tv_usec * 1000
904f19
-		};
904f19
-		ts_sub(&tcp->dtime, &stime, &tcp->stime);
904f19
-		tcp->stime = stime;
904f19
-	}
904f19
+		/* Initialise a new wait data structure.  */
904f19
+		wd = tcb_wait_tab + wait_tab_pos;
904f19
+		init_trace_wait_data(wd);
904f19
+		wd->status = status;
904f19
 
904f19
-	if (WIFSIGNALED(status)) {
904f19
-		wd->te = TE_SIGNALLED;
904f19
-		return wd;
904f19
-	}
904f19
+		if (WIFSIGNALED(status)) {
904f19
+			wd->te = TE_SIGNALLED;
904f19
+		} else if (WIFEXITED(status)) {
904f19
+			wd->te = TE_EXITED;
904f19
+		} else {
904f19
+			/*
904f19
+			 * As WCONTINUED flag has not been specified to wait4,
904f19
+			 * it cannot be WIFCONTINUED(status), so the only case
904f19
+			 * that remains is WIFSTOPPED(status).
904f19
+			 */
904f19
 
904f19
-	if (WIFEXITED(status)) {
904f19
-		wd->te = TE_EXITED;
904f19
-		return wd;
904f19
+			const unsigned int sig = WSTOPSIG(status);
904f19
+			const unsigned int event = (unsigned int) status >> 16;
904f19
+
904f19
+			switch (event) {
904f19
+			case 0:
904f19
+				/*
904f19
+				 * Is this post-attach SIGSTOP?
904f19
+				 * Interestingly, the process may stop
904f19
+				 * with STOPSIG equal to some other signal
904f19
+				 * than SIGSTOP if we happened to attach
904f19
+				 * just before the process takes a signal.
904f19
+				 */
904f19
+				if (sig == SIGSTOP &&
904f19
+				    (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
904f19
+					debug_func_msg("ignored SIGSTOP on "
904f19
+						       "pid %d", tcp->pid);
904f19
+					tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
904f19
+					wd->te = TE_RESTART;
904f19
+				} else if (sig == syscall_trap_sig) {
904f19
+					wd->te = TE_SYSCALL_STOP;
904f19
+				} else {
904f19
+					/*
904f19
+					 * True if tracee is stopped by signal
904f19
+					 * (as opposed to "tracee received
904f19
+					 * signal").
904f19
+					 * TODO: shouldn't we check for
904f19
+					 * errno == EINVAL too?
904f19
+					 * We can get ESRCH instead, you know...
904f19
+					 */
904f19
+					bool stopped = ptrace(PTRACE_GETSIGINFO,
904f19
+						pid, 0, &wd->si) < 0;
904f19
+
904f19
+					wd->te = stopped ? TE_GROUP_STOP
904f19
+							 : TE_SIGNAL_DELIVERY_STOP;
904f19
+				}
904f19
+				break;
904f19
+			case PTRACE_EVENT_STOP:
904f19
+				/*
904f19
+				 * PTRACE_INTERRUPT-stop or group-stop.
904f19
+				 * PTRACE_INTERRUPT-stop has sig == SIGTRAP here.
904f19
+				 */
904f19
+				switch (sig) {
904f19
+				case SIGSTOP:
904f19
+				case SIGTSTP:
904f19
+				case SIGTTIN:
904f19
+				case SIGTTOU:
904f19
+					wd->te = TE_GROUP_STOP;
904f19
+					break;
904f19
+				default:
904f19
+					wd->te = TE_RESTART;
904f19
+				}
904f19
+				break;
904f19
+			case PTRACE_EVENT_EXEC:
904f19
+					/*
904f19
+					 * TODO: shouldn't we check for
904f19
+					 * errno == EINVAL here, too?
904f19
+					 * We can get ESRCH instead, you know...
904f19
+					 */
904f19
+				if (ptrace(PTRACE_GETEVENTMSG, pid, NULL,
904f19
+				    &wd->msg) < 0)
904f19
+					wd->msg = 0;
904f19
+
904f19
+				wd->te = TE_STOP_BEFORE_EXECVE;
904f19
+				break;
904f19
+			case PTRACE_EVENT_EXIT:
904f19
+				wd->te = TE_STOP_BEFORE_EXIT;
904f19
+				break;
904f19
+			default:
904f19
+				wd->te = TE_RESTART;
904f19
+			}
904f19
+		}
904f19
+
904f19
+		if (!wd->te)
904f19
+			error_func_msg("Tracing event hasn't been determined "
904f19
+				       "for pid %d, status %0#x", pid, status);
904f19
+
904f19
+		if (!list_is_empty(&tcp->wait_list)) {
904f19
+			wait_extra_data_idx = wait_tab_pos;
904f19
+			extra_tcp = tcp;
904f19
+			debug_func_msg("queued extra pid %d", tcp->pid);
904f19
+		} else {
904f19
+			tcp->wait_data_idx = wait_tab_pos;
904f19
+			list_append(&pending_tcps, &tcp->wait_list);
904f19
+			debug_func_msg("queued pid %d", tcp->pid);
904f19
+		}
904f19
+
904f19
+		wait_tab_pos++;
904f19
+
904f19
+		if (extra_tcp)
904f19
+			break;
904f19
+
904f19
+next_event_wait_next:
904f19
+		pid = wait4(-1, &status, __WALL | WNOHANG, (cflag ? &ru : NULL));
904f19
+		wait_errno = errno;
904f19
+		wait_nohang = true;
904f19
 	}
904f19
 
904f19
-	/*
904f19
-	 * As WCONTINUED flag has not been specified to wait4,
904f19
-	 * it cannot be WIFCONTINUED(status), so the only case
904f19
-	 * that remains is WIFSTOPPED(status).
904f19
-	 */
904f19
+next_event_get_tcp:
904f19
+	elem = list_remove_head(&pending_tcps);
904f19
+
904f19
+	if (!elem) {
904f19
+		tcb_wait_tab_check_size(0);
904f19
+		memset(tcb_wait_tab, 0, sizeof(*tcb_wait_tab));
904f19
+		tcb_wait_tab->te = TE_NEXT;
904f19
 
904f19
+		return tcb_wait_tab;
904f19
+	} else {
904f19
+		tcp = list_elem(elem, struct tcb, wait_list);
904f19
+		debug_func_msg("dequeued pid %d", tcp->pid);
904f19
+	}
904f19
+
904f19
+next_event_exit:
904f19
 	/* Is this the very first time we see this tracee stopped? */
904f19
 	if (tcp->flags & TCB_STARTUP)
904f19
 		startup_tcb(tcp);
904f19
 
904f19
-	const unsigned int sig = WSTOPSIG(status);
904f19
-	const unsigned int event = (unsigned int) status >> 16;
904f19
+	clear_regs(tcp);
904f19
 
904f19
-	switch (event) {
904f19
-	case 0:
904f19
-		/*
904f19
-		 * Is this post-attach SIGSTOP?
904f19
-		 * Interestingly, the process may stop
904f19
-		 * with STOPSIG equal to some other signal
904f19
-		 * than SIGSTOP if we happened to attach
904f19
-		 * just before the process takes a signal.
904f19
-		 */
904f19
-		if (sig == SIGSTOP && (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
904f19
-			debug_func_msg("ignored SIGSTOP on pid %d", tcp->pid);
904f19
-			tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
904f19
-			wd->te = TE_RESTART;
904f19
-		} else if (sig == syscall_trap_sig) {
904f19
-			wd->te = TE_SYSCALL_STOP;
904f19
-		} else {
904f19
-			memset(&wd->si, 0, sizeof(wd->si));
904f19
-			/*
904f19
-			 * True if tracee is stopped by signal
904f19
-			 * (as opposed to "tracee received signal").
904f19
-			 * TODO: shouldn't we check for errno == EINVAL too?
904f19
-			 * We can get ESRCH instead, you know...
904f19
-			 */
904f19
-			bool stopped = ptrace(PTRACE_GETSIGINFO, pid, 0, &wd->si) < 0;
904f19
-			wd->te = stopped ? TE_GROUP_STOP : TE_SIGNAL_DELIVERY_STOP;
904f19
-		}
904f19
-		break;
904f19
-	case PTRACE_EVENT_STOP:
904f19
-		/*
904f19
-		 * PTRACE_INTERRUPT-stop or group-stop.
904f19
-		 * PTRACE_INTERRUPT-stop has sig == SIGTRAP here.
904f19
-		 */
904f19
-		switch (sig) {
904f19
-		case SIGSTOP:
904f19
-		case SIGTSTP:
904f19
-		case SIGTTIN:
904f19
-		case SIGTTOU:
904f19
-			wd->te = TE_GROUP_STOP;
904f19
-			break;
904f19
-		default:
904f19
-			wd->te = TE_RESTART;
904f19
-		}
904f19
-		break;
904f19
-	case PTRACE_EVENT_EXEC:
904f19
-		wd->te = TE_STOP_BEFORE_EXECVE;
904f19
-		break;
904f19
-	case PTRACE_EVENT_EXIT:
904f19
-		wd->te = TE_STOP_BEFORE_EXIT;
904f19
-		break;
904f19
-	default:
904f19
-		wd->te = TE_RESTART;
904f19
-	}
904f19
+	/* Set current output file */
904f19
+	set_current_tcp(tcp);
904f19
 
904f19
-	return wd;
904f19
+	return tcb_wait_tab + tcp->wait_data_idx;
904f19
 }
904f19
 
904f19
 static int
904f19
@@ -2569,8 +2698,15 @@ dispatch_event(const struct tcb_wait_data *wd)
904f19
 		return false;
904f19
 
904f19
 	/* If the process is being delayed, do not ptrace_restart just yet */
904f19
-	if (syscall_delayed(current_tcp))
904f19
+	if (syscall_delayed(current_tcp)) {
904f19
+		if (current_tcp->delayed_wait_data)
904f19
+			error_func_msg("pid %d has delayed wait data set"
904f19
+				       " already", current_tcp->pid);
904f19
+
904f19
+		current_tcp->delayed_wait_data = copy_trace_wait_data(wd);
904f19
+
904f19
 		return true;
904f19
+	}
904f19
 
904f19
 	if (ptrace_restart(restart_op, current_tcp, restart_sig) < 0) {
904f19
 		/* Note: ptrace_restart emitted error message */
904f19
@@ -2583,7 +2719,15 @@ dispatch_event(const struct tcb_wait_data *wd)
904f19
 static bool
904f19
 restart_delayed_tcb(struct tcb *const tcp)
904f19
 {
904f19
-	const struct tcb_wait_data wd = { .te = TE_RESTART };
904f19
+	struct tcb_wait_data *wd = tcp->delayed_wait_data;
904f19
+
904f19
+	if (!wd) {
904f19
+		error_func_msg("No delayed wait data found for pid %d",
904f19
+			       tcp->pid);
904f19
+		wd = init_trace_wait_data(alloca(trace_wait_data_size(tcp)));
904f19
+	}
904f19
+
904f19
+	wd->te = TE_RESTART;
904f19
 
904f19
 	debug_func_msg("pid %d", tcp->pid);
904f19
 
904f19
@@ -2591,9 +2735,12 @@ restart_delayed_tcb(struct tcb *const tcp)
904f19
 
904f19
 	struct tcb *const prev_tcp = current_tcp;
904f19
 	current_tcp = tcp;
904f19
-	bool ret = dispatch_event(&wd;;
904f19
+	bool ret = dispatch_event(wd);
904f19
 	current_tcp = prev_tcp;
904f19
 
904f19
+	free_trace_wait_data(tcp->delayed_wait_data);
904f19
+	tcp->delayed_wait_data = NULL;
904f19
+
904f19
 	return ret;
904f19
 }
904f19
 
904f19
diff --git a/tests/Makefile.am b/tests/Makefile.am
904f19
index de7a3d2..51f00a9 100644
904f19
--- a/tests/Makefile.am
904f19
+++ b/tests/Makefile.am
904f19
@@ -350,8 +350,7 @@ XFAIL_TESTS_m32 = $(STACKTRACE_TESTS)
904f19
 XFAIL_TESTS_mx32 = $(STACKTRACE_TESTS)
904f19
 XFAIL_TESTS_x86_64 = int_0x80.gen.test
904f19
 XFAIL_TESTS_x32 = int_0x80.gen.test
904f19
-XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH)) \
904f19
-	      looping_threads.test
904f19
+XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH))
904f19
 
904f19
 TEST_LOG_COMPILER = env
904f19
 AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) STRACE_NATIVE_ARCH=$(NATIVE_ARCH) \
904f19
-- 
904f19
2.1.4
904f19