All of lore.kernel.org
 help / color / mirror / Atom feed
From: Imre Deak <imre.deak@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@intel.com>
Subject: [IGT PATCH 1/2] aux: Suspend signal helper for shell commands
Date: Thu, 12 Oct 2017 16:22:06 +0300	[thread overview]
Message-ID: <20171012132207.27508-1-imre.deak@intel.com> (raw)

The clone() system call with a larger executable (like /bin/sh) may have
difficulty to make progress on some platforms if interrupted frequently.
So suspend the signal helper process for the duration of the syscall.
This is needed to solve an actual problem by the next patch.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/igt_aux.c  | 38 ++++++++++++++++++++++++++++++++++++++
 lib/igt_aux.h  |  2 ++
 lib/igt_core.c |  9 +++++++++
 3 files changed, 49 insertions(+)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index fa6594c3..36dfab43 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -350,6 +350,44 @@ void igt_stop_signal_helper(void)
 	sig_stat = 0;
 }
 
+/**
+ * igt_suspend_signal_helper:
+ *
+ * Suspends the child process spawned with igt_fork_signal_helper().
+ *
+ * This should be called before code that has difficulty to make progress if
+ * interrupted frequently, like the clone() syscall spawning a large
+ * executable.
+ */
+void igt_suspend_signal_helper(void)
+{
+	int status;
+
+	if (!signal_helper.running)
+		return;
+
+	kill(signal_helper.pid, SIGSTOP);
+	while (waitpid(signal_helper.pid, &status, WUNTRACED) == -1 &&
+	       errno == EINTR)
+		;
+}
+
+/**
+ * igt_suspend_signal_helper:
+ *
+ * Resumes the child process spawned with igt_fork_signal_helper().
+ *
+ * This should be paired with igt_suspend_signal_helper() and called after the
+ * problematic code sensitive to signals.
+ */
+void igt_resume_signal_helper(void)
+{
+	if (!signal_helper.running)
+		return;
+
+	kill(signal_helper.pid, SIGCONT);
+}
+
 static struct igt_helper_process shrink_helper;
 static void __attribute__((noreturn)) shrink_helper_process(int fd, pid_t pid)
 {
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 499a1679..688ad1b8 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -55,6 +55,8 @@ extern int num_trash_bos;
 /* generally useful helpers */
 void igt_fork_signal_helper(void);
 void igt_stop_signal_helper(void);
+void igt_suspend_signal_helper(void);
+void igt_resume_signal_helper(void);
 
 void igt_fork_shrink_helper(int fd);
 void igt_stop_shrink_helper(void);
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 950ea9b0..ea4b5fa6 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -2282,6 +2282,13 @@ int igt_system(const char *command)
 	if (pipe(errpipe) < 0)
 		goto err;
 
+	/*
+	 * The clone() system call forking a large executable has difficulty
+	 * to make progress if interrupted too frequently, so suspend it for
+	 * the time of the syscall.
+	 */
+	igt_suspend_signal_helper();
+
 	igt_fork_helper(&process) {
 		close(outpipe[0]);
 		close(errpipe[0]);
@@ -2298,6 +2305,8 @@ int igt_system(const char *command)
 		exit(EXIT_FAILURE);
 	}
 
+	igt_resume_signal_helper();
+
 	close(outpipe[1]);
 	close(errpipe[1]);
 
-- 
2.13.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

             reply	other threads:[~2017-10-12 13:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12 13:22 Imre Deak [this message]
2017-10-12 13:22 ` [IGT PATCH 2/2] aux: Use IGT version of system() call to run rtcwake Imre Deak
2017-10-12 13:57   ` Chris Wilson
2017-10-12 13:51 ` [IGT PATCH 1/2] aux: Suspend signal helper for shell commands Chris Wilson
2017-10-12 13:52 ` Chris Wilson
2017-10-13 11:22   ` Imre Deak
2017-10-12 17:52 ` Daniel Vetter

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=20171012132207.27508-1-imre.deak@intel.com \
    --to=imre.deak@intel.com \
    --cc=daniel.vetter@intel.com \
    --cc=intel-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.