[igt-dev] [PATCH i-g-t] lib: Make igt_while_interruptible() thread-safe

Kamil Konieczny kamil.konieczny at linux.intel.com
Mon Jun 12 17:23:10 UTC 2023


From: Chris Wilson <chris.p.wilson at linux.intel.com>

We have the ability to replace the ioctl() call by a wrapper that
performs signal injection (triggering the ioctl to return -EINTR). This
uses a global for handling the signal, which is broken if the test tries
to mixing SIGINT injection and threads. Switch to a thread-local
sigaction.

Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Signed-off-by: Chris Wilson <chris.p.wilson at linux.intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 lib/igt_aux.c        | 2 +-
 lib/ioctl_wrappers.c | 2 +-
 lib/ioctl_wrappers.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 386e25783..adff1a11d 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -93,7 +93,7 @@
  * fit into any other topic.
  */
 
-static struct __igt_sigiter_global {
+static __thread struct __igt_sigiter_global {
 	pid_t tid;
 	timer_t timer;
 	struct timespec offset;
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index ebd8a2f36..146973f0d 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -89,7 +89,7 @@
  * distinguish them.
  */
 
-int (*igt_ioctl)(int fd, unsigned long request, void *arg) = drmIoctl;
+__thread int (*igt_ioctl)(int fd, unsigned long request, void *arg) = drmIoctl;
 
 
 static int
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 4c232078d..b7d7c2ad9 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -48,7 +48,7 @@
  * This is a wrapper around drmIoctl(), which can be augmented with special code
  * blocks like #igt_while_interruptible.
  */
-extern int (*igt_ioctl)(int fd, unsigned long request, void *arg);
+extern __thread int (*igt_ioctl)(int fd, unsigned long request, void *arg);
 
 /* ioctl_wrappers.c:
  *
-- 
2.39.2



More information about the igt-dev mailing list