[igt-dev] [PATCH i-g-t] lib: Make igt_while_interruptible() thread-safe
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Fri Jul 21 10:52:54 UTC 2023
On Mon, Jun 12, 2023 at 07:23:10PM +0200, Kamil Konieczny wrote:
> 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>
I had to experiment with this code to understand what's on the hood.
And yes, for threads sharing __igt_sigiter + igt_ioctl is problematic.
So for change to tls:
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
--
Zbigniew
> ---
> 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