Changeset f410b31b in rtems


Ignore:
Timestamp:
Apr 11, 2019, 1:39:36 PM (6 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
ad40d05e
Parents:
e90486a
git-author:
Sebastian Huber <sebastian.huber@…> (04/11/19 13:39:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/12/19 07:44:48)
Message:

score: Improve _SMP_Multicast_action()

Let it work during system initialization.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/smpimpl.h

    re90486a rf410b31b  
    7979  SMP_FATAL_SHUTDOWN_RESPONSE,
    8080  SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED,
    81   SMP_FATAL_SCHEDULER_PIN_OR_UNPIN_NOT_SUPPORTED
     81  SMP_FATAL_SCHEDULER_PIN_OR_UNPIN_NOT_SUPPORTED,
     82  SMP_FATAL_WRONG_CPU_STATE_TO_PERFORM_JOBS
    8283} SMP_Fatal_code;
    8384
  • cpukit/score/src/percpu.c

    re90486a rf410b31b  
    9090          && state != PER_CPU_STATE_SHUTDOWN
    9191      ) {
     92        _Per_CPU_Perform_jobs( cpu );
    9293        _CPU_SMP_Processor_event_receive();
    9394        state = cpu->state;
     
    100101      ) {
    101102        _Per_CPU_State_before_multitasking_action( cpu );
     103        _Per_CPU_Perform_jobs( cpu );
    102104        _CPU_SMP_Processor_event_receive();
    103105        state = cpu->state;
  • cpukit/score/src/smpmulticastaction.c

    re90486a rf410b31b  
    3333#include <rtems/score/assert.h>
    3434#include <rtems/score/threaddispatch.h>
    35 #include <rtems/score/sysstate.h>
    3635
    3736typedef struct Per_CPU_Job Per_CPU_Job;
     
    182181    if ( _Processor_mask_Is_set( targets, cpu_index ) ) {
    183182      const Per_CPU_Job *job;
     183      Per_CPU_Control   *cpu;
    184184
    185185      job = &jobs->Jobs[ cpu_index ];
     186      cpu = _Per_CPU_Get_by_index( cpu_index );
    186187
    187188      while ( _Atomic_Load_ulong( &job->done, ATOMIC_ORDER_ACQUIRE ) == 0 ) {
    188         _Per_CPU_Try_perform_jobs( cpu_self );
     189        switch ( cpu->state ) {
     190          case PER_CPU_STATE_INITIAL:
     191          case PER_CPU_STATE_READY_TO_START_MULTITASKING:
     192          case PER_CPU_STATE_REQUEST_START_MULTITASKING:
     193            _CPU_SMP_Processor_event_broadcast();
     194            /* Fall through */
     195          case PER_CPU_STATE_UP:
     196            /*
     197             * Calling this function with the current processor is intentional.
     198             * We have to perform our own jobs here in case inter-processor
     199             * interrupts are not working.
     200             */
     201            _Per_CPU_Try_perform_jobs( cpu_self );
     202            break;
     203          default:
     204            _SMP_Fatal( SMP_FATAL_WRONG_CPU_STATE_TO_PERFORM_JOBS );
     205            break;
     206        }
    189207      }
    190208    }
     
    205223  _Assert( cpu_max <= CPU_MAXIMUM_PROCESSORS );
    206224
    207   if ( ! _System_state_Is_up( _System_state_Get() ) ) {
    208     ( *handler )( arg );
    209     return;
    210   }
    211 
    212225  if ( targets == NULL ) {
    213226    targets = _SMP_Get_online_processors();
  • testsuites/smptests/smpmulticast01/init.c

    re90486a rf410b31b  
    105105static void test_unicast(
    106106  test_context *ctx,
    107   void (*multicast_action)(const Processor_mask *, SMP_Action_handler, void *),
    108   bool before_multitasking
     107  void (*multicast_action)(const Processor_mask *, SMP_Action_handler, void *)
    109108)
    110109{
     
    112111  uint32_t i;
    113112  uint32_t n;
    114   uint32_t self;
    115113
    116114  T_plan(1);
    117115  step = 0;
    118   self = rtems_scheduler_get_processor();
    119116  n = rtems_scheduler_get_processor_maximum();
    120117
     
    135132      id = _Atomic_Load_uint(&ctx->id[j], ATOMIC_ORDER_RELAXED);
    136133
    137       if (before_multitasking) {
    138         if (j == self) {
    139           T_quiet_eq_uint(j + 1, id);
    140         } else {
    141           T_quiet_eq_uint(0, id);
    142         }
     134      if (j == i) {
     135        T_quiet_eq_uint(j + 1, id);
    143136      } else {
    144         if (j == i) {
    145           T_quiet_eq_uint(j + 1, id);
    146         } else {
    147           T_quiet_eq_uint(0, id);
    148         }
     137        T_quiet_eq_uint(0, id);
    149138      }
    150139    }
     
    156145static void test_broadcast(
    157146  test_context *ctx,
    158   void (*multicast_action)(const Processor_mask *, SMP_Action_handler, void *),
    159   bool before_multitasking
     147  void (*multicast_action)(const Processor_mask *, SMP_Action_handler, void *)
    160148)
    161149{
     
    163151  uint32_t i;
    164152  uint32_t n;
    165   uint32_t self;
    166153
    167154  T_plan(1);
    168155  step = 0;
    169   self = rtems_scheduler_get_processor();
    170156  n = rtems_scheduler_get_processor_maximum();
    171157
     
    182168      ++step;
    183169      id = _Atomic_Load_uint(&ctx->id[j], ATOMIC_ORDER_RELAXED);
    184 
    185       if (before_multitasking) {
    186         if (j == self) {
    187           T_quiet_eq_uint(j + 1, id);
    188         } else {
    189           T_quiet_eq_uint(0, id);
    190         }
    191       } else {
    192         T_quiet_eq_uint(j + 1, id);
    193       }
     170      T_quiet_eq_uint(j + 1, id);
    194171    }
    195172  }
     
    205182
    206183  T_case_begin("UnicastBeforeMultitasking", NULL);
    207   test_unicast(ctx, _SMP_Multicast_action, true);
     184  test_unicast(ctx, _SMP_Multicast_action);
    208185  T_case_end();
    209186
    210187  T_case_begin("UnicastBeforeMultitaskingIRQDisabled", NULL);
    211   test_unicast(ctx, multicast_action_irq_disabled, true);
     188  test_unicast(ctx, multicast_action_irq_disabled);
    212189  T_case_end();
    213190
    214191  T_case_begin("UnicastBeforeMultitaskingDispatchDisabled", NULL);
    215   test_unicast(ctx, multicast_action_dispatch_disabled, true);
     192  test_unicast(ctx, multicast_action_dispatch_disabled);
    216193  T_case_end();
    217194
    218195  T_case_begin("BroadcastBeforeMultitasking", NULL);
    219   test_broadcast(ctx, _SMP_Multicast_action, true);
     196  test_broadcast(ctx, _SMP_Multicast_action);
    220197  T_case_end();
    221198
    222199  T_case_begin("BroadcastBeforeMultitaskingIRQDisabled", NULL);
    223   test_broadcast(ctx, multicast_action_irq_disabled, true);
     200  test_broadcast(ctx, multicast_action_irq_disabled);
    224201  T_case_end();
    225202
    226203  T_case_begin("BroadcastBeforeMultitaskingDispatchDisabled", NULL);
    227   test_broadcast(ctx, multicast_action_dispatch_disabled, true);
     204  test_broadcast(ctx, multicast_action_dispatch_disabled);
    228205  T_case_end();
    229206}
     
    242219);
    243220
     221static void set_wrong_cpu_state(void *arg)
     222{
     223  Per_CPU_Control *cpu_self;
     224
     225  cpu_self = arg;
     226  T_step_eq_ptr(0, cpu_self, _Per_CPU_Get());
     227  cpu_self->state = 123;
     228
     229  while (true) {
     230    /* Do nothing */
     231  }
     232}
     233
     234static void test_wrong_cpu_state_to_perform_jobs(void)
     235{
     236  Per_CPU_Control *cpu_self;
     237  rtems_interrupt_level level;
     238  Processor_mask targets;
     239  uint32_t cpu_index;
     240
     241  T_case_begin("WrongCPUStateToPerformJobs", NULL);
     242  T_plan(4);
     243  cpu_self = _Thread_Dispatch_disable();
     244
     245  cpu_index = _Per_CPU_Get_index(cpu_self);
     246  cpu_index = (cpu_index + 1) % rtems_scheduler_get_processor_maximum();
     247  _Processor_mask_Zero(&targets);
     248  _Processor_mask_Set(&targets, cpu_index);
     249
     250  rtems_interrupt_local_disable(level);
     251
     252  _SMP_Multicast_action(
     253    &targets,
     254    set_wrong_cpu_state,
     255    _Per_CPU_Get_by_index(cpu_index)
     256  );
     257
     258  /* If everything is all right, we don't end up here */
     259  rtems_interrupt_local_enable(level);
     260  _Thread_Dispatch_enable(cpu_self);
     261  rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 0);
     262}
     263
    244264static void Init(rtems_task_argument arg)
    245265{
    246266  test_context *ctx;
     267
     268  ctx = &test_instance;
     269
     270  T_case_begin("UnicastDuringMultitasking", NULL);
     271  test_unicast(ctx, _SMP_Multicast_action);
     272  T_case_end();
     273
     274  T_case_begin("UnicastDuringMultitaskingIRQDisabled", NULL);
     275  test_unicast(ctx, multicast_action_irq_disabled);
     276  T_case_end();
     277
     278  T_case_begin("UnicastDuringMultitaskingDispatchDisabled", NULL);
     279  test_unicast(ctx, multicast_action_dispatch_disabled);
     280  T_case_end();
     281
     282  T_case_begin("BroadcastDuringMultitasking", NULL);
     283  test_broadcast(ctx, _SMP_Multicast_action);
     284  T_case_end();
     285
     286  T_case_begin("BroadcastDuringMultitaskingIRQDisabled", NULL);
     287  test_broadcast(ctx, multicast_action_irq_disabled);
     288  T_case_end();
     289
     290  T_case_begin("BroadcastDuringMultitaskingDispatchDisabled", NULL);
     291  test_broadcast(ctx, multicast_action_dispatch_disabled);
     292  T_case_end();
     293
     294  if (rtems_scheduler_get_processor_maximum() > 1) {
     295    test_wrong_cpu_state_to_perform_jobs();
     296  } else {
     297    rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 0);
     298  }
     299}
     300
     301static void fatal_extension(
     302  rtems_fatal_source source,
     303  bool always_set_to_false,
     304  rtems_fatal_code code
     305)
     306{
    247307  bool ok;
    248308
    249   ctx = &test_instance;
    250 
    251   T_case_begin("UnicastDuringMultitasking", NULL);
    252   test_unicast(ctx, _SMP_Multicast_action, false);
    253   T_case_end();
    254 
    255   T_case_begin("UnicastDuringMultitaskingIRQDisabled", NULL);
    256   test_unicast(ctx, multicast_action_irq_disabled, false);
    257   T_case_end();
    258 
    259   T_case_begin("UnicastDuringMultitaskingDispatchDisabled", NULL);
    260   test_unicast(ctx, multicast_action_dispatch_disabled, false);
    261   T_case_end();
    262 
    263   T_case_begin("BroadcastDuringMultitasking", NULL);
    264   test_broadcast(ctx, _SMP_Multicast_action, false);
    265   T_case_end();
    266 
    267   T_case_begin("BroadcastDuringMultitaskingIRQDisabled", NULL);
    268   test_broadcast(ctx, multicast_action_irq_disabled, false);
    269   T_case_end();
    270 
    271   T_case_begin("BroadcastDuringMultitaskingDispatchDisabled", NULL);
    272   test_broadcast(ctx, multicast_action_dispatch_disabled, false);
    273   T_case_end();
    274 
    275   ok = T_run_finalize();
    276   rtems_test_assert(ok);
    277   TEST_END();
    278   rtems_test_exit(0);
     309  if (source == RTEMS_FATAL_SOURCE_SMP) {
     310    T_step_eq_int(1, source, RTEMS_FATAL_SOURCE_SMP);
     311    T_step_false(2, always_set_to_false, "unexpected argument value");
     312    T_step_eq_int(3, code, SMP_FATAL_WRONG_CPU_STATE_TO_PERFORM_JOBS);
     313    T_case_end();
     314
     315    ok = T_run_finalize();
     316    rtems_test_assert(ok);
     317    TEST_END();
     318  } else if (source == RTEMS_FATAL_SOURCE_APPLICATION) {
     319    ok = T_run_finalize();
     320    rtems_test_assert(ok);
     321    TEST_END();
     322  }
    279323}
    280324
     
    285329#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
    286330
     331#define CONFIGURE_INITIAL_EXTENSIONS \
     332  { .fatal = fatal_extension }, \
     333  RTEMS_TEST_INITIAL_EXTENSION
     334
    287335#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    288336
  • testsuites/smptests/smpmulticast01/smpmulticast01.scn

    re90486a rf410b31b  
    11*** BEGIN OF TEST SMPMULTICAST 1 ***
    2 *** TEST VERSION: 5.0.0.c44199ccea624f31b1116fa2e47d547944e90909-modified
     2*** TEST VERSION: 5.0.0.d9c9d1af7a885bc402c57e88919635b27b363111
    33*** TEST STATE: EXPECTED-PASS
    44*** TEST BUILD: RTEMS_POSIX_API RTEMS_SMP
     
    77S:Platform:RTEMS
    88S:Compiler:7.4.0 20181206 (RTEMS 5, RSB e0aec65182449a4e22b820e773087636edaf5b32, Newlib 1d35a003f)
    9 S:Version:5.0.0.c44199ccea624f31b1116fa2e47d547944e90909
     9S:Version:5.0.0.d9c9d1af7a885bc402c57e88919635b27b363111
    1010S:BSP:qoriq_e6500_32
    1111S:RTEMS_DEBUG:0
     
    1515S:RTEMS_SMP:1
    1616B:UnicastBeforeMultitasking
    17 P:0:0:IDLE:init.c:150
    18 E:UnicastBeforeMultitasking:N:1:F:0:D:0.001999
     17P:0:0:IDLE:init.c:142
     18E:UnicastBeforeMultitasking:N:1:F:0:D:0.002206
    1919B:UnicastBeforeMultitaskingIRQDisabled
    20 P:0:0:IDLE:init.c:150
    21 E:UnicastBeforeMultitaskingIRQDisabled:N:1:F:0:D:0.001999
     20P:0:0:IDLE:init.c:142
     21E:UnicastBeforeMultitaskingIRQDisabled:N:1:F:0:D:0.002184
    2222B:UnicastBeforeMultitaskingDispatchDisabled
    23 P:0:0:IDLE:init.c:150
    24 E:UnicastBeforeMultitaskingDispatchDisabled:N:1:F:0:D:0.001999
     23P:0:0:IDLE:init.c:142
     24E:UnicastBeforeMultitaskingDispatchDisabled:N:1:F:0:D:0.002198
    2525B:BroadcastBeforeMultitasking
    26 P:0:0:IDLE:init.c:194
    27 E:BroadcastBeforeMultitasking:N:1:F:0:D:0.001999
     26P:0:0:IDLE:init.c:174
     27E:BroadcastBeforeMultitasking:N:1:F:0:D:0.004153
    2828B:BroadcastBeforeMultitaskingIRQDisabled
    29 P:0:0:IDLE:init.c:194
    30 E:BroadcastBeforeMultitaskingIRQDisabled:N:1:F:0:D:0.001999
     29P:0:0:IDLE:init.c:174
     30E:BroadcastBeforeMultitaskingIRQDisabled:N:1:F:0:D:0.004135
    3131B:BroadcastBeforeMultitaskingDispatchDisabled
    32 P:0:0:IDLE:init.c:194
    33 E:BroadcastBeforeMultitaskingDispatchDisabled:N:1:F:0:D:0.001999
     32P:0:0:IDLE:init.c:174
     33E:BroadcastBeforeMultitaskingDispatchDisabled:N:1:F:0:D:0.004123
    3434B:UnicastDuringMultitasking
    35 P:0:23:UI1:init.c:150
    36 E:UnicastDuringMultitasking:N:1:F:0:D:0.001999
     35P:0:23:UI1:init.c:142
     36E:UnicastDuringMultitasking:N:1:F:0:D:0.002270
    3737B:UnicastDuringMultitaskingIRQDisabled
    38 P:0:23:UI1:init.c:150
    39 E:UnicastDuringMultitaskingIRQDisabled:N:1:F:0:D:0.002000
     38P:0:23:UI1:init.c:142
     39E:UnicastDuringMultitaskingIRQDisabled:N:1:F:0:D:0.002272
    4040B:UnicastDuringMultitaskingDispatchDisabled
    41 P:0:23:UI1:init.c:150
    42 E:UnicastDuringMultitaskingDispatchDisabled:N:1:F:0:D:0.002000
     41P:0:23:UI1:init.c:142
     42E:UnicastDuringMultitaskingDispatchDisabled:N:1:F:0:D:0.002271
    4343B:BroadcastDuringMultitasking
    44 P:0:23:UI1:init.c:194
    45 E:BroadcastDuringMultitasking:N:1:F:0:D:0.002134
     44P:0:23:UI1:init.c:174
     45E:BroadcastDuringMultitasking:N:1:F:0:D:0.003904
    4646B:BroadcastDuringMultitaskingIRQDisabled
    47 P:0:23:UI1:init.c:194
    48 E:BroadcastDuringMultitaskingIRQDisabled:N:1:F:0:D:0.002165
     47P:0:23:UI1:init.c:174
     48E:BroadcastDuringMultitaskingIRQDisabled:N:1:F:0:D:0.003949
    4949B:BroadcastDuringMultitaskingDispatchDisabled
    50 P:0:23:UI1:init.c:194
    51 E:BroadcastDuringMultitaskingDispatchDisabled:N:1:F:0:D:0.002130
    52 Z:SMPMultiCast:C:12:N:12:F:0:D:0.125615
     50P:0:23:UI1:init.c:174
     51E:BroadcastDuringMultitaskingDispatchDisabled:N:1:F:0:D:0.003914
     52B:WrongCPUStateToPerformJobs
     53P:0:0:ISR:init.c:226
     54P:1:23:UI1:init.c:310
     55P:2:23:UI1:init.c:311
     56P:3:23:UI1:init.c:312
     57E:WrongCPUStateToPerformJobs:N:4:F:0:D:0.007911
     58Z:SMPMultiCast:C:13:N:16:F:0:D:0.153651
    5359
    5460*** END OF TEST SMPMULTICAST 1 ***
Note: See TracChangeset for help on using the changeset viewer.