[PATCH] score: Add _CPU_Context_switch_no_return()

Gedare Bloom gedare at rtems.org
Mon May 17 21:42:28 UTC 2021


ok to me

On Mon, May 17, 2021 at 5:43 AM Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
> The __builtin_unreachable() cannot be used with current GCC versions to
> tell the compiler that a function does not return to the caller, see:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99151
>
> Add a no return variant of _CPU_Context_switch() to avoid generation of
> dead code in _Thread_Start_multitasking() if RTEMS was built with SMP
> support enabled.
> ---
>  bsps/powerpc/shared/cpu_asm.S                 |  2 ++
>  cpukit/score/cpu/arm/cpu_asm.S                |  3 ++
>  .../score/cpu/arm/include/rtems/score/cpu.h   |  5 ++++
>  .../cpu/no_cpu/include/rtems/score/cpu.h      | 30 +++++++++++++++++--
>  .../cpu/powerpc/include/rtems/score/cpu.h     |  5 ++++
>  .../score/cpu/riscv/include/rtems/score/cpu.h |  5 ++++
>  cpukit/score/cpu/riscv/riscv-context-switch.S |  2 ++
>  cpukit/score/cpu/sparc/cpu_asm.S              |  2 ++
>  .../score/cpu/sparc/include/rtems/score/cpu.h |  5 ++++
>  cpukit/score/src/threadstartmultitasking.c    |  2 +-
>  10 files changed, 57 insertions(+), 4 deletions(-)
>
> diff --git a/bsps/powerpc/shared/cpu_asm.S b/bsps/powerpc/shared/cpu_asm.S
> index e4d627016c..63f6a3fdfe 100644
> --- a/bsps/powerpc/shared/cpu_asm.S
> +++ b/bsps/powerpc/shared/cpu_asm.S
> @@ -258,7 +258,9 @@ PROC (_CPU_Context_restore_fp):
>
>         ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER)
>         PUBLIC_PROC (_CPU_Context_switch)
> +       PUBLIC_PROC (_CPU_Context_switch_no_return)
>  PROC (_CPU_Context_switch):
> +PROC (_CPU_Context_switch_no_return):
>
>  #ifdef BSP_USE_SYNC_IN_CONTEXT_SWITCH
>         sync
> diff --git a/cpukit/score/cpu/arm/cpu_asm.S b/cpukit/score/cpu/arm/cpu_asm.S
> index 66f8ba6032..46eb46b914 100644
> --- a/cpukit/score/cpu/arm/cpu_asm.S
> +++ b/cpukit/score/cpu/arm/cpu_asm.S
> @@ -54,6 +54,9 @@
>   */
>
>  DEFINE_FUNCTION_ARM(_CPU_Context_switch)
> +       .globl  _CPU_Context_switch_no_return
> +       .set    _CPU_Context_switch_no_return, _CPU_Context_switch
> +
>  /* Start saving context */
>         GET_SELF_CPU_CONTROL    r2
>         ldr     r3, [r2, #PER_CPU_ISR_DISPATCH_DISABLE]
> diff --git a/cpukit/score/cpu/arm/include/rtems/score/cpu.h b/cpukit/score/cpu/arm/include/rtems/score/cpu.h
> index e5b23e7100..dcda4d525c 100644
> --- a/cpukit/score/cpu/arm/include/rtems/score/cpu.h
> +++ b/cpukit/score/cpu/arm/include/rtems/score/cpu.h
> @@ -465,6 +465,11 @@ void _CPU_ISR_install_vector(
>   */
>  void _CPU_Context_switch( Context_Control *run, Context_Control *heir );
>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(
> +  Context_Control *executing,
> +  Context_Control *heir
> +);
> +
>  RTEMS_NO_RETURN void _CPU_Context_restore( Context_Control *new_context );
>
>  #if defined(ARM_MULTILIB_ARCH_V7M)
> diff --git a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
> index c067501502..c437ded5fb 100644
> --- a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
> +++ b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
> @@ -1054,22 +1054,46 @@ void _CPU_ISR_install_vector(
>  void *_CPU_Thread_Idle_body( uintptr_t ignored );
>
>  /**
> + * @brief Peforms a context switch from the executing thread to the heir
> + *   thread.
> + *
>   * @addtogroup RTEMSScoreCPUExampleContext
>   *
>   * This routine switches from the run context to the heir context.
>   *
> - * @param[in] run points to the context of the currently executing task
> - * @param[in] heir points to the context of the heir task
> + * @param[out] executing points to the context of the currently executing task.
> + *
> + * @param[in, out] heir points to the context of the heir task.
>   *
>   * Port Specific Information:
>   *
>   * XXX document implementation including references if appropriate
>   */
>  void _CPU_Context_switch(
> -  Context_Control  *run,
> +  Context_Control  *executing,
>    Context_Control  *heir
>  );
>
> +/**
> + * @brief Peforms a context switch from the executing thread to the heir thread
> + *   and does not return.
> + *
> + * @addtogroup RTEMSScoreCPUExampleContext
> + *
> + * This routine shall be a strong alias to _CPU_Context_switch().  It shall be
> + * provided for all target architectures which support an SMP build
> + * configuration (RTEMS_SMP).  The purpose is help to compiler to avoid
> + * generation of dead code in _Thread_Start_multitasking().
> + *
> + * @param[out] executing points to the context of the currently executing task.
> + *
> + * @param[in, out] heir points to the context of the heir task.
> + */
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(
> +  Context_Control *executing,
> +  Context_Control *heir
> +);
> +
>  /**
>   * @addtogroup RTEMSScoreCPUExampleContext
>   *
> diff --git a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
> index 996b6f8e60..f22e1cd7ec 100644
> --- a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
> +++ b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
> @@ -914,6 +914,11 @@ void _CPU_Context_switch(
>    Context_Control  *heir
>  );
>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(
> +  Context_Control *executing,
> +  Context_Control *heir
> +);
> +
>  /*
>   *  _CPU_Context_restore
>   *
> diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
> index 38eb92394d..a44b815b12 100644
> --- a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
> +++ b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
> @@ -383,6 +383,11 @@ void _CPU_Context_switch(
>    Context_Control  *heir
>  );
>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(
> +  Context_Control *executing,
> +  Context_Control *heir
> +);
> +
>  /*
>   *  _CPU_Context_restore
>   *
> diff --git a/cpukit/score/cpu/riscv/riscv-context-switch.S b/cpukit/score/cpu/riscv/riscv-context-switch.S
> index 96c117b3de..830f8629a4 100644
> --- a/cpukit/score/cpu/riscv/riscv-context-switch.S
> +++ b/cpukit/score/cpu/riscv/riscv-context-switch.S
> @@ -37,9 +37,11 @@
>         .align  2
>
>  PUBLIC(_CPU_Context_switch)
> +PUBLIC(_CPU_Context_switch_no_return)
>  PUBLIC(_CPU_Context_restore)
>
>  SYM(_CPU_Context_switch):
> +SYM(_CPU_Context_switch_no_return):
>         GET_SELF_CPU_CONTROL    a2
>         lw      a3, PER_CPU_ISR_DISPATCH_DISABLE(a2)
>
> diff --git a/cpukit/score/cpu/sparc/cpu_asm.S b/cpukit/score/cpu/sparc/cpu_asm.S
> index e884fb2f9e..a7b87ad5f8 100644
> --- a/cpukit/score/cpu/sparc/cpu_asm.S
> +++ b/cpukit/score/cpu/sparc/cpu_asm.S
> @@ -57,7 +57,9 @@
>
>          .align 4
>          PUBLIC(_CPU_Context_switch)
> +        PUBLIC(_CPU_Context_switch_no_return)
>  SYM(_CPU_Context_switch):
> +SYM(_CPU_Context_switch_no_return):
>          st      %g5, [%o0 + G5_OFFSET]       ! save the global registers
>
>          /*
> diff --git a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
> index 8c5330b8ce..6c167e3f08 100644
> --- a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
> +++ b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
> @@ -971,6 +971,11 @@ void _CPU_Context_switch(
>    Context_Control  *heir
>  );
>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(
> +  Context_Control *executing,
> +  Context_Control *heir
> +);
> +
>  /**
>   * @brief SPARC specific context restore.
>   *
> diff --git a/cpukit/score/src/threadstartmultitasking.c b/cpukit/score/src/threadstartmultitasking.c
> index a0b465a226..094a535394 100644
> --- a/cpukit/score/src/threadstartmultitasking.c
> +++ b/cpukit/score/src/threadstartmultitasking.c
> @@ -59,7 +59,7 @@ void _Thread_Start_multitasking( void )
>       * executing to the currently selected heir thread.
>       */
>      _CPU_Context_Set_is_executing( &trash, true );
> -    _CPU_Context_switch( &trash, &heir->Registers );
> +    _CPU_Context_switch_no_return( &trash, &heir->Registers );
>      RTEMS_UNREACHABLE();
>    }
>  #else
> --
> 2.26.2
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list