#3459 closed enhancement (fixed)

Rework initialization and interrupt stack support

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 5.1
Component: score Version: 5
Severity: normal Keywords: qualification
Cc: Blocked By:
Blocking: #3433

Description

We need an initialization stack to run the sequential system initialization before multitasking is enabled. The system initialization is done with interrupts disabled.

We need an interrupt stack for interrupt processing. This helps to avoid a per thread stack overhead for interrupt processing. The size for interrupt stack is application dependent, e.g. maximum interrupt nest level, stack demands of interrupt handlers.

The initialization and interrupt stacks are needed for each processor in the system.

Since interrupts are disabled during the sequential system initialization we can re-use the interrupt stack for the initialization stack. This is important for low end targets, with very limited RAM sizes. We need the initialization stack before a proper C run-time environment is set up e.g. we cannot assume that the access to global data is available. The stack memory area begin and size should be available via global symbols (named addresses). On some BSPs, e.g. ARM, this is done via the linker command file.

It should be possible to set the stack size via the CONFIGURE_INTERRUPT_STACK_SIZE configuration option and not via some magic stuff in linker command files.

Many BSPs set the BSS area to zero during system initialization. Thus, the initialization stack must not be contained in the BSS area.

The interrupt stack implementation is currently controlled by the following CPU port defines:

/**
 * Does RTEMS manage a dedicated interrupt stack in software?
 *
 * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
 * If FALSE, nothing is done.
 *
 * If the CPU supports a dedicated interrupt stack in hardware,
 * then it is generally the responsibility of the BSP to allocate it
 * and set it up.
 *
 * If the CPU does not support a dedicated interrupt stack, then
 * the porter has two options: (1) execute interrupts on the
 * stack of the interrupted task, and (2) have RTEMS manage a dedicated
 * interrupt stack.
 *
 * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
 *
 * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
 * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
 * possible that both are FALSE for a particular CPU.  Although it
 * is unclear what that would imply about the interrupt processing
 * procedure on that CPU.
 *
 * Port Specific Information:
 *
 * XXX document implementation including references if appropriate
 */
#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE

/**
 * Does this CPU have hardware support for a dedicated interrupt stack?
 *
 * If TRUE, then it must be installed during initialization.
 * If FALSE, then no installation is performed.
 *
 * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
 *
 * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
 * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
 * possible that both are FALSE for a particular CPU.  Although it
 * is unclear what that would imply about the interrupt processing
 * procedure on that CPU.
 *
 * Port Specific Information:
 *
 * XXX document implementation including references if appropriate
 */
#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE

/**
 * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
 *
 * If TRUE, then the memory is allocated during initialization.
 * If FALSE, then the memory is allocated during initialization.
 *
 * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
 *
 * Port Specific Information:
 *
 * XXX document implementation including references if appropriate
 */
#define CPU_ALLOCATE_INTERRUPT_STACK TRUE

Do the following steps to unify and simplify the initialization and interrupt stack support.

  1. Add RTEMS_DECLARE_GLOBAL_SYMBOL() and RTEMS_DEFINE_GLOBAL_SYMBOL() macros to basedefs.h, to allow a global symbol definition via C code, e.g. in confdefs.h, to make the interrupt stack size available to the low level initialization code.
  1. Add a special input section ".rtemsstack" to the linker command files to allow a placement of the interrupt stacks. The BSPs can provide the optimal memory location for this section, e.g. on-chip RAM, tightly-coupled memory.

This makes the CPU_HAS_SOFTWARE_INTERRUPT_STACK and CPU_HAS_HARDWARE_INTERRUPT_STACK CPU port defines superfluous, since the low level initialization code has all information available via global symbols.

This makes the CPU_ALLOCATE_INTERRUPT_STACK CPU port define superfluous, since the interrupt stacks are allocated by confdefs.h for all architectures. There is no need for BSP-specific linker command file magic.

The optional _CPU_Interrupt_stack_setup() is still useful to customize the registration of the interrupt stack area in the per-CPU information.

Change History (36)

comment:1 Changed on 06/18/18 at 06:30:48 by Sebastian Huber

Blocking: 3433 added

comment:2 Changed on 06/19/18 at 13:27:08 by Sebastian Huber <sebastian.huber@…>

In b0c3ba2f/rtems:

bsps: Remove superfluous bsp_processor_count

This is unused copy and paste stuff.

Update #3459.

comment:3 Changed on 06/20/18 at 07:34:03 by Sebastian Huber

Just for reference, the reuse of the initialization stack for the interrupt stack is only possible because boot_card() is a no-return function. This was not the case in RTEMS versions before 4.11.

comment:4 Changed on 06/22/18 at 04:30:39 by Sebastian Huber <sebastian.huber@…>

In cc3edaa/rtems:

config: SMP only CONFIGURE_MAXIMUM_PROCESSORS

Do not set the CONFIGURE_MAXIMUM_PROCESSORS in uni-processor default
configuration, since this may lead to an oversize workspace.

Update #3459.

comment:5 Changed on 06/22/18 at 04:30:49 by Sebastian Huber <sebastian.huber@…>

In 8ff5916c/rtems:

stackchk: Remove dead code

Update #3459.

comment:6 Changed on 06/22/18 at 04:31:00 by Sebastian Huber <sebastian.huber@…>

In 1cb2e748/rtems:

stackchk: Refactor Stack_check_Dump_threads_usage

Update #3459.

comment:7 Changed on 06/22/18 at 04:31:10 by Sebastian Huber <sebastian.huber@…>

In c47ad8e/rtems:

stackchk: Add SMP support

Check the interrupt stacks of all processors. Set up the interrupt
stack of the current processor for high water testing in the thread
begin extension. This must be done after multi-threading started, since
the initialization stacks may reuse the interrupt stacks. Disable
thread dispatching in SMP configurations to prevent thread migration.
Writing to the interrupt stack is only safe if done from the
corresponding processor in thread context.

Update #3459.

comment:8 Changed on 06/22/18 at 04:31:21 by Sebastian Huber <sebastian.huber@…>

In fe46647e/rtems:

score: Macros to declare and define global symbols

Add RTEMS_DEFINE_GLOBAL_SYMBOL() and add RTEMS_DECLARE_GLOBAL_SYMBOL().

Update #3459.

comment:9 Changed on 06/29/18 at 09:53:49 by Sebastian Huber <sebastian.huber@…>

In c8df844/rtems:

score: Add CPU_INTERRUPT_STACK_ALIGNMENT

Add CPU port define for the interrupt stack alignment. The alignment
should take the stack ABI and the cache line size into account.

Update #3459.

comment:10 Changed on 06/29/18 at 09:54:00 by Sebastian Huber <sebastian.huber@…>

In 715d616/rtems:

bsps: Support .rtemsstack.* linker input sections

Use a dedicated memory region or place it between the BSS and workspace.

Update #3459.

comment:11 Changed on 06/29/18 at 09:54:14 by Sebastian Huber <sebastian.huber@…>

In 511dc4b/rtems:

Rework initialization and interrupt stack support

Statically initialize the interrupt stack area
(_Configuration_Interrupt_stack_area_begin,
_Configuration_Interrupt_stack_area_end, and
_Configuration_Interrupt_stack_size) via <rtems/confdefs.h>. Place the
interrupt stack area in a special section ".rtemsstack.interrupt". Let
BSPs define the optimal placement of this section in their linker
command files (e.g. in a fast on-chip memory).

This change makes makes the CPU_HAS_SOFTWARE_INTERRUPT_STACK and
CPU_HAS_HARDWARE_INTERRUPT_STACK CPU port defines superfluous, since the
low level initialization code has all information available via global
symbols.

This change makes the CPU_ALLOCATE_INTERRUPT_STACK CPU port define
superfluous, since the interrupt stacks are allocated by confdefs.h for
all architectures. There is no need for BSP-specific linker command
file magic (except the section placement), see previous ARM linker
command file as a bad example.

Remove _CPU_Install_interrupt_stack(). Initialize the hardware
interrupt stack in _CPU_Initialize() if necessary (e.g.
m68k_install_interrupt_stack()).

The optional _CPU_Interrupt_stack_setup() is still useful to customize
the registration of the interrupt stack area in the per-CPU information.

The initialization stack can reuse the interrupt stack, since

  • interrupts are disabled during the sequential system initialization, and
  • the boot_card() function does not return.

This stack resuse saves memory.

Changes per architecture:

arm:

  • Mostly replace the linker symbol based configuration of stacks with the standard <rtems/confdefs.h> configuration via CONFIGURE_INTERRUPT_STACK_SIZE. The size of the FIQ, ABT and UND mode stack is still defined via linker symbols. These modes are rarely used in applications and the default values provided by the BSP should be sufficient in most cases.
  • Remove the bsp_processor_count linker symbol hack used for the SMP support. This is possible since the interrupt stack area is now allocated by the linker and not allocated from the heap. This makes some configure.ac stuff obsolete. Remove the now superfluous BSP variants altcycv_devkit_smp and realview_pbx_a9_qemu_smp.

bfin:

  • Remove unused magic linker command file allocation of initialization stack. Maybe a previous linker command file copy and paste problem? In the start.S the initialization stack is set to a hard coded value.

lm32, m32c, mips, nios2, riscv, sh, v850:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.

m68k:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.

powerpc:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.
  • Used dedicated memory region (REGION_RTEMSSTACK) for the interrupt stack on BSPs using the shared linkcmds.base (replacement for REGION_RWEXTRA).

sparc:

  • Remove the hard coded initialization stack. Use the interrupt stack for the initialization stack on the boot processor. This saves 16KiB of RAM.

Update #3459.

comment:12 Changed on 07/03/18 at 05:07:40 by Sebastian Huber <sebastian.huber@…>

In 156b227/rtems-tools:

tester: Remove obsolete BSP variants

Update #3459.

comment:13 Changed on 07/03/18 at 05:12:58 by Sebastian Huber <sebastian.huber@…>

In 25f4db0/rtems-source-builder:

5: Update tools to not build obsolete BSP variants

Update #3459.

comment:14 Changed on 07/19/18 at 05:38:20 by Sebastian Huber <sebastian.huber@…>

Resolution: fixed
Status: assignedclosed

In efd581f/rtems-docs:

cpu-supplement: Update interrupt stack paragraph

Close #3459.

comment:15 Changed on 07/31/18 at 05:13:55 by Sebastian Huber <sebastian.huber@…>

In 334e1d2/rtems:

confdefs: Fix uniprocessor configuration

Introduce a new internal define _CONFIGURE_MAXIMUM_PROCESSORS and ensure
that it is _CONFIGURE_MAXIMUM_PROCESSORS > 1 only in SMP configurations.

This avoids to allocate data structures for non-existing additional
processors in uniprocessor configuration.

Update #3459.

comment:16 Changed on 08/03/18 at 11:04:49 by Sebastian Huber <sebastian.huber@…>

In 42f9963d/rtems:

score: Remove superfluous semicolon

This avoids warnings like this:

warning: ISO C does not allow extra ';' outside of a function [-Wpedantic]

RTEMS_DECLARE_GLOBAL_SYMBOL( abc );


Update #3459.

comment:17 Changed on 09/03/18 at 05:03:42 by Sebastian Huber <sebastian.huber@…>

In fad3f79b/rtems:

bsps: BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN

Remove the BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN hack. The interrupt
stacks are now allocated by the linker.

Update #3459.

comment:18 Changed on 09/06/18 at 05:05:31 by Sebastian Huber <sebastian.huber@…>

In 54d87f2/rtems:

bsps/powerpc: Simplify ppc_exc_initialize()

Remove parameters from ppc_exc_initialize() since all BSPs passed the
same values.

Update #3459.

comment:19 Changed on 09/21/18 at 06:08:11 by Sebastian Huber <sebastian.huber@…>

In 56e61e24/rtems:

Remove INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL

The configured interrupt stack size (CONFIGURE_INTERRUPT_STACK_SIZE) is
checked against the minimum task stack size. The minium tasks task
stack size is also a configuration option
(CONFIGURE_MINIMUM_TASK_STACK_SIZE). So, this check does not really
help in case of configuration errors. In addition, the interrupt stack
is also re-used as the initialization stack in most BSPs. It is
probably better to use a stack checker to detect problems.

Update #3459.

comment:20 Changed on 09/21/18 at 06:08:34 by Sebastian Huber <sebastian.huber@…>

In 4221d93/rtems:

stackchk: Improve support for interrupt stacks

Prepare the interrupt stack which may be used by the boot processor as
initialization stack with the stack sanity pattern. Check the interrupt
stack of the current processor in the thread begin and switch extension.

Update #3459.

comment:21 Changed on 09/24/18 at 07:16:51 by Sebastian Huber <sebastian.huber@…>

In 7d1acc03/rtems:

stackchk: Fix interrupt stack preparation

We have to prepare the interrupt stack of each processor.

Update #3459.

comment:22 Changed on 11/08/18 at 07:11:03 by Sebastian Huber <sebastian.huber@…>

In ff081aee/rtems:

score: Rename interrupt stack symbols

Rename

  • _Configuration_Interrupt_stack_area_begin in _ISR_Stack_area_begin,
  • _Configuration_Interrupt_stack_area_end in _ISR_Stack_area_end, and
  • _Configuration_Interrupt_stack_size in _ISR_Stack_size.

Move definitions to <rtems/score/isr.h>. The new names are considerable
shorter and in the right namespace.

Update #3459.

comment:23 Changed on 11/14/18 at 07:00:19 by Sebastian Huber <sebastian.huber@…>

In 5f32da0/rtems:

bsp/or1k: Use interrupt stack for init stack

Update #3459.

comment:24 Changed on 11/14/18 at 07:48:05 by Sebastian Huber <sebastian.huber@…>

In a13b89b/rtems:

bsp/i386: Use interrupt stack for init stack

Update #3459.

comment:25 Changed on 11/19/18 at 06:20:40 by Sebastian Huber <sebastian.huber@…>

In cc61d5c/rtems:

bsps/m68k: Use interrupt stack for init stack

Update #3459.

comment:26 Changed on 11/19/18 at 06:20:49 by Sebastian Huber <sebastian.huber@…>

In 84e59b7c/rtems:

bsps/powerpc: Use interrupt stack for init stack

Move start.o to separate file.

Update #3459.

comment:27 Changed on 11/19/18 at 06:20:57 by Sebastian Huber <sebastian.huber@…>

In 508f319e/rtems:

bsps/mips: Use interrupt stack for init stack

Update #3459.

comment:28 Changed on 11/19/18 at 06:21:05 by Sebastian Huber <sebastian.huber@…>

In a74ee417/rtems:

bsps/bfin: Use interrupt stack for init stack

Update #3459.

comment:29 Changed on 11/19/18 at 06:21:13 by Sebastian Huber <sebastian.huber@…>

In 0ce6bf3/rtems:

bsps/epiphany: Use interrupt stack for init stack

Update #3459.

comment:30 Changed on 11/19/18 at 06:21:22 by Sebastian Huber <sebastian.huber@…>

In 5f5bbd1/rtems:

bsps/x86_64: Use interrupt stack for init stack

Update #3459.

comment:31 Changed on 11/19/18 at 06:21:30 by Sebastian Huber <sebastian.huber@…>

In 0989001/rtems:

bsps/sparc64: Use interrupt stack for init stack

Update #3459.

comment:32 Changed on 11/19/18 at 06:21:37 by Sebastian Huber <sebastian.huber@…>

In 38f81bfc/rtems:

bsps/nios2: Use interrupt stack for init stack

Update #3459.

comment:33 Changed on 11/19/18 at 06:21:45 by Sebastian Huber <sebastian.huber@…>

In 0a6a4ddb/rtems:

bsps/moxie: Use interrupt stack for init stack

Update #3459.

comment:34 Changed on 01/21/19 at 08:18:34 by Sebastian Huber <sebastian.huber@…>

In 95c1921/rtems:

bsps/arm: Remove unused bsp_stack_irq_size

Update #3459.

comment:35 Changed on 03/15/19 at 06:34:26 by Sebastian Huber <sebastian.huber@…>

In 9e48958/rtems:

bsps/powerpc: Initialize stack earlier

The eabi() call may use the stack.

Update #3459.

comment:36 Changed on 06/23/21 at 07:16:03 by Sebastian Huber

Keywords: qualification added
Note: See TracTickets for help on using tickets.