Changeset c47ad8e in rtems


Ignore:
Timestamp:
Jun 20, 2018, 10:03:54 AM (16 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
fe46647e
Parents:
1cb2e748
git-author:
Sebastian Huber <sebastian.huber@…> (06/20/18 10:03:54)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/20/18 10:07:08)
Message:

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.

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/stackchk.h

    r1cb2e748 rc47ad8e  
    9797);
    9898
     99void rtems_stack_checker_begin_extension( Thread_Control *executing );
     100
    99101/**
    100102 * @brief Stack Checker Task Context Switch Extension
     
    126128  0,                                           /* rtems_task_delete  */ \
    127129  rtems_stack_checker_switch_extension,        /* task_switch  */ \
    128   0,                                           /* task_begin   */ \
     130  rtems_stack_checker_begin_extension,         /* task_begin   */ \
    129131  0,                                           /* task_exitted */ \
    130132  0,                                           /* fatal        */ \
  • cpukit/libmisc/stackchk/check.c

    r1cb2e748 rc47ad8e  
    6161 *  Variable to indicate when the stack checker has been initialized.
    6262 */
    63 static int   Stack_check_Initialized = 0;
     63static bool Stack_check_Initialized;
    6464
    6565/*
     
    138138    ((_the_stack)->size - PATTERN_SIZE_BYTES)
    139139
    140 static Stack_Control Stack_check_Interrupt_stack;
     140#if defined(RTEMS_SMP)
     141static Stack_Control Stack_check_Interrupt_stack[ CPU_MAXIMUM_PROCESSORS ];
     142#else
     143static Stack_Control Stack_check_Interrupt_stack[ 1 ];
     144#endif
    141145
    142146/*
     
    146150#define Stack_check_Dope_stack(_stack) \
    147151  memset((_stack)->area, BYTE_PATTERN, (_stack)->size)
    148 
    149 /*
    150  *  Stack_check_Initialize
    151  */
    152 static void Stack_check_Initialize( void )
    153 {
    154   if ( Stack_check_Initialized )
    155     return;
    156 
    157   /*
    158    * If appropriate, setup the interrupt stack for high water testing
    159    * also.
    160    */
    161   #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
    162     if (_CPU_Interrupt_stack_low && _CPU_Interrupt_stack_high) {
    163       Stack_check_Interrupt_stack.area = _CPU_Interrupt_stack_low;
    164       Stack_check_Interrupt_stack.size = (char *) _CPU_Interrupt_stack_high -
    165                                   (char *) _CPU_Interrupt_stack_low;
    166       Stack_check_Dope_stack(&Stack_check_Interrupt_stack);
    167    }
    168   #endif
    169 
    170   Stack_check_Initialized = 1;
    171 }
    172152
    173153static bool Stack_check_Is_pattern_valid(const Thread_Control *the_thread)
     
    188168)
    189169{
    190   Stack_check_Initialize();
     170  Stack_check_Initialized = true;
     171
    191172  Stack_check_Dope_stack(&the_thread->Start.Initial_stack);
    192 
    193173  memcpy(
    194174    Stack_check_Get_pattern(&the_thread->Start.Initial_stack),
     
    198178
    199179  return true;
     180}
     181
     182void rtems_stack_checker_begin_extension( Thread_Control *executing )
     183{
     184#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
     185  Per_CPU_Control *cpu_self;
     186  uint32_t         cpu_self_index;
     187  Stack_Control   *stack;
     188
     189  /*
     190   * If appropriate, set up the interrupt stack of the current processor for
     191   * high water testing also.  This must be done after multi-threading started,
     192   * since the initialization stacks may reuse the interrupt stacks.  Disable
     193   * thread dispatching in SMP configurations to prevent thread migration.
     194   * Writing to the interrupt stack is only safe if done from the corresponding
     195   * processor in thread context.
     196   */
     197
     198#if defined(RTEMS_SMP)
     199  cpu_self = _Thread_Dispatch_disable();
     200#else
     201  cpu_self = _Per_CPU_Get();
     202#endif
     203
     204  cpu_self_index = _Per_CPU_Get_index( cpu_self );
     205  stack = &Stack_check_Interrupt_stack[ cpu_self_index ];
     206
     207  if ( stack->area == NULL ) {
     208    stack->area = cpu_self->interrupt_stack_low;
     209    stack->size = (size_t) ( (char *) cpu_self->interrupt_stack_high -
     210      (char *) cpu_self->interrupt_stack_low );
     211    Stack_check_Dope_stack( stack );
     212  }
     213
     214#if defined(RTEMS_SMP)
     215  _Thread_Dispatch_enable( cpu_self );
     216#endif
     217#endif
    200218}
    201219
     
    366384  );
    367385
    368   if (Stack_check_Initialized == 0) {
     386  if (Stack_check_Initialized) {
     387    rtems_printf( printer, "%6" PRId32 "\n", used );
     388  } else {
    369389    rtems_printf( printer, "N/A\n" );
    370   } else {
    371     rtems_printf( printer, "%6" PRId32 "\n", used );
    372390  }
    373391
     
    397415static void Stack_check_Dump_interrupt_stack_usage(
    398416  const Stack_Control *stack,
     417  uint32_t             id,
    399418  const rtems_printer *printer
    400419)
     
    403422    stack,
    404423    NULL,
    405     "INTR",
    406     0xffffffff,
     424    "Interrupt Stack",
     425    id,
    407426    printer
    408427  );
     
    417436)
    418437{
     438  uint32_t cpu_max;
     439  uint32_t cpu_index;
     440
    419441  rtems_printf(
    420442     printer,
     
    429451  );
    430452
    431   Stack_check_Dump_interrupt_stack_usage(
    432     &Stack_check_Interrupt_stack,
    433     printer
    434   );
     453  cpu_max = rtems_get_processor_count();
     454
     455  for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
     456    Stack_check_Dump_interrupt_stack_usage(
     457      &Stack_check_Interrupt_stack[ cpu_index ],
     458      cpu_index,
     459      printer
     460    );
     461  }
    435462}
    436463
Note: See TracChangeset for help on using the changeset viewer.