[v2,0/9] Optimize posix_spawn signal setup with clone3

Message ID 20220930192613.3491147-1-adhemerval.zanella@linaro.org
Headers
Series Optimize posix_spawn signal setup with clone3 |

Message

Adhemerval Zanella Netto Sept. 30, 2022, 7:26 p.m. UTC
  Currently posix_spawn has to issue at least NSIG sigaction syscalls
to obtain current signal disposition and more if they there are not
either SIG_IGN or SIG_DFL.  The new clone3 CLONE_CLEAR_SIGHAND flags
introduced with Linux 5.5 resets all signal handlers of the child not
set to SIG_IGN to SIG_DFL, thus allowing posix_spawn to skip this
preparation phase.

The exception is the signals defined by posix_spawnattr_setsigdefault
when POSIX_SPAWN_SETSIGDEF is set (since they can be SIG_IGN).  In
this case posix_spawn helper process needs to issue a sigction to 
set the signal disposition to SIG_DFL.

The patchset also adds clone3 implementation for aarch64, powerpc64,
s390x, riscv, arm, and mips.

Changes from v1:
  * Adeed arm and mips clone3 implementation.

Adhemerval Zanella (9):
  linux: Do not reset signal handler in posix_spawn if it is already
    SIG_DFL
  linux: Add clone3 CLONE_CLEAR_SIGHAND optimization to posix_spawn
  powerpc64le: Add the clone3 wrapper
  aarch64: Add the clone3 wrapper
  s390x: Add the clone3 wrapper
  riscv: Add the clone3 wrapper
  arm: Add the clone3 wrapper
  mips: Add the clone3 wrapper
  Linux: optimize clone3 internal usage

 include/clone_internal.h                      |  10 +
 posix/Makefile                                |   3 +-
 posix/tst-spawn7.c                            | 179 ++++++++++++++++++
 sysdeps/unix/sysv/linux/aarch64/clone3.S      |  90 +++++++++
 sysdeps/unix/sysv/linux/aarch64/sysdep.h      |   2 +
 sysdeps/unix/sysv/linux/arm/clone3.S          |  80 ++++++++
 sysdeps/unix/sysv/linux/arm/sysdep.h          |   1 +
 sysdeps/unix/sysv/linux/clone-internal.c      |  59 ++++--
 sysdeps/unix/sysv/linux/clone3.h              |   6 +
 sysdeps/unix/sysv/linux/kernel-features.h     |   9 +
 sysdeps/unix/sysv/linux/mips/clone3.S         | 147 ++++++++++++++
 sysdeps/unix/sysv/linux/mips/sysdep.h         |   2 +
 .../sysv/linux/powerpc/powerpc64/clone3.S     | 145 ++++++++++++++
 sysdeps/unix/sysv/linux/powerpc/sysdep.h      |   1 +
 sysdeps/unix/sysv/linux/riscv/clone3.S        |  83 ++++++++
 sysdeps/unix/sysv/linux/riscv/sysdep.h        |   1 +
 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S |  84 ++++++++
 sysdeps/unix/sysv/linux/s390/sysdep.h         |   1 +
 sysdeps/unix/sysv/linux/spawni.c              |  33 +++-
 19 files changed, 910 insertions(+), 26 deletions(-)
 create mode 100644 posix/tst-spawn7.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/clone3.S
 create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S
 create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/clone3.S
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S
  

Comments

Adhemerval Zanella Netto Oct. 27, 2022, 4:48 p.m. UTC | #1
Ping.

On 30/09/22 16:26, Adhemerval Zanella wrote:
> Currently posix_spawn has to issue at least NSIG sigaction syscalls
> to obtain current signal disposition and more if they there are not
> either SIG_IGN or SIG_DFL.  The new clone3 CLONE_CLEAR_SIGHAND flags
> introduced with Linux 5.5 resets all signal handlers of the child not
> set to SIG_IGN to SIG_DFL, thus allowing posix_spawn to skip this
> preparation phase.
> 
> The exception is the signals defined by posix_spawnattr_setsigdefault
> when POSIX_SPAWN_SETSIGDEF is set (since they can be SIG_IGN).  In
> this case posix_spawn helper process needs to issue a sigction to 
> set the signal disposition to SIG_DFL.
> 
> The patchset also adds clone3 implementation for aarch64, powerpc64,
> s390x, riscv, arm, and mips.
> 
> Changes from v1:
>   * Adeed arm and mips clone3 implementation.
> 
> Adhemerval Zanella (9):
>   linux: Do not reset signal handler in posix_spawn if it is already
>     SIG_DFL
>   linux: Add clone3 CLONE_CLEAR_SIGHAND optimization to posix_spawn
>   powerpc64le: Add the clone3 wrapper
>   aarch64: Add the clone3 wrapper
>   s390x: Add the clone3 wrapper
>   riscv: Add the clone3 wrapper
>   arm: Add the clone3 wrapper
>   mips: Add the clone3 wrapper
>   Linux: optimize clone3 internal usage
> 
>  include/clone_internal.h                      |  10 +
>  posix/Makefile                                |   3 +-
>  posix/tst-spawn7.c                            | 179 ++++++++++++++++++
>  sysdeps/unix/sysv/linux/aarch64/clone3.S      |  90 +++++++++
>  sysdeps/unix/sysv/linux/aarch64/sysdep.h      |   2 +
>  sysdeps/unix/sysv/linux/arm/clone3.S          |  80 ++++++++
>  sysdeps/unix/sysv/linux/arm/sysdep.h          |   1 +
>  sysdeps/unix/sysv/linux/clone-internal.c      |  59 ++++--
>  sysdeps/unix/sysv/linux/clone3.h              |   6 +
>  sysdeps/unix/sysv/linux/kernel-features.h     |   9 +
>  sysdeps/unix/sysv/linux/mips/clone3.S         | 147 ++++++++++++++
>  sysdeps/unix/sysv/linux/mips/sysdep.h         |   2 +
>  .../sysv/linux/powerpc/powerpc64/clone3.S     | 145 ++++++++++++++
>  sysdeps/unix/sysv/linux/powerpc/sysdep.h      |   1 +
>  sysdeps/unix/sysv/linux/riscv/clone3.S        |  83 ++++++++
>  sysdeps/unix/sysv/linux/riscv/sysdep.h        |   1 +
>  sysdeps/unix/sysv/linux/s390/s390-64/clone3.S |  84 ++++++++
>  sysdeps/unix/sysv/linux/s390/sysdep.h         |   1 +
>  sysdeps/unix/sysv/linux/spawni.c              |  33 +++-
>  19 files changed, 910 insertions(+), 26 deletions(-)
>  create mode 100644 posix/tst-spawn7.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S
>
  
Carlos O'Donell Jan. 11, 2023, 9:11 p.m. UTC | #2
On 9/30/22 15:26, Adhemerval Zanella via Libc-alpha wrote:
> Currently posix_spawn has to issue at least NSIG sigaction syscalls
> to obtain current signal disposition and more if they there are not
> either SIG_IGN or SIG_DFL.  The new clone3 CLONE_CLEAR_SIGHAND flags
> introduced with Linux 5.5 resets all signal handlers of the child not
> set to SIG_IGN to SIG_DFL, thus allowing posix_spawn to skip this
> preparation phase.
> 
> The exception is the signals defined by posix_spawnattr_setsigdefault
> when POSIX_SPAWN_SETSIGDEF is set (since they can be SIG_IGN).  In
> this case posix_spawn helper process needs to issue a sigction to 
> set the signal disposition to SIG_DFL.
> 
> The patchset also adds clone3 implementation for aarch64, powerpc64,
> s390x, riscv, arm, and mips.
> 

I would like to trim this down for glibc 2.37.

I think we can get the default implementation in place and enable this for x86_64.

Everything else that adds custom assembly should be something we commit once 2.38
opens and so we can have time to review the generated code and make sure we don't
break anything.

I'd like to see a v3 posted with just the 3 patches required to turn this on:
1/9 linux: Do not reset signal handler in posix_spawn if it is already SIG_DFL
2/9 linux: Add clone3 CLONE_CLEAR_SIGHAND optimization to posix_spawn
9/9 Linux: optimize clone3 internal usage

> Changes from v1:
>   * Adeed arm and mips clone3 implementation.
> 
> Adhemerval Zanella (9):
>   linux: Do not reset signal handler in posix_spawn if it is already
>     SIG_DFL
>   linux: Add clone3 CLONE_CLEAR_SIGHAND optimization to posix_spawn
>   powerpc64le: Add the clone3 wrapper
>   aarch64: Add the clone3 wrapper
>   s390x: Add the clone3 wrapper
>   riscv: Add the clone3 wrapper
>   arm: Add the clone3 wrapper
>   mips: Add the clone3 wrapper
>   Linux: optimize clone3 internal usage
> 
>  include/clone_internal.h                      |  10 +
>  posix/Makefile                                |   3 +-
>  posix/tst-spawn7.c                            | 179 ++++++++++++++++++
>  sysdeps/unix/sysv/linux/aarch64/clone3.S      |  90 +++++++++
>  sysdeps/unix/sysv/linux/aarch64/sysdep.h      |   2 +
>  sysdeps/unix/sysv/linux/arm/clone3.S          |  80 ++++++++
>  sysdeps/unix/sysv/linux/arm/sysdep.h          |   1 +
>  sysdeps/unix/sysv/linux/clone-internal.c      |  59 ++++--
>  sysdeps/unix/sysv/linux/clone3.h              |   6 +
>  sysdeps/unix/sysv/linux/kernel-features.h     |   9 +
>  sysdeps/unix/sysv/linux/mips/clone3.S         | 147 ++++++++++++++
>  sysdeps/unix/sysv/linux/mips/sysdep.h         |   2 +
>  .../sysv/linux/powerpc/powerpc64/clone3.S     | 145 ++++++++++++++
>  sysdeps/unix/sysv/linux/powerpc/sysdep.h      |   1 +
>  sysdeps/unix/sysv/linux/riscv/clone3.S        |  83 ++++++++
>  sysdeps/unix/sysv/linux/riscv/sysdep.h        |   1 +
>  sysdeps/unix/sysv/linux/s390/s390-64/clone3.S |  84 ++++++++
>  sysdeps/unix/sysv/linux/s390/sysdep.h         |   1 +
>  sysdeps/unix/sysv/linux/spawni.c              |  33 +++-
>  19 files changed, 910 insertions(+), 26 deletions(-)
>  create mode 100644 posix/tst-spawn7.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/clone3.S
>  create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S
>