Changeset 351c14d in rtems for testsuites/smptests


Ignore:
Timestamp:
Sep 27, 2016, 9:33:36 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
6a82f1a
Parents:
2403473
git-author:
Sebastian Huber <sebastian.huber@…> (09/27/16 09:33:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/02/16 09:05:43)
Message:

score: Add new SMP scheduler helping protocol

Update #2556.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/smptests/smpmutex01/init.c

    r2403473 r351c14d  
    4343  REQ_MTX_2_RELEASE = RTEMS_EVENT_6,
    4444  REQ_SEM_OBTAIN_RELEASE = RTEMS_EVENT_7,
    45   REQ_SEM_RELEASE = RTEMS_EVENT_8
     45  REQ_SEM_RELEASE = RTEMS_EVENT_8,
     46  REQ_SET_DONE = RTEMS_EVENT_9,
     47  REQ_WAIT_FOR_DONE = RTEMS_EVENT_10,
     48  REQ_SEND_EVENT_2 = RTEMS_EVENT_11,
     49  REQ_SEND_EVENT_3 = RTEMS_EVENT_12
    4650} request_id;
    4751
     
    6468  rtems_id sem;
    6569  rtems_id tasks[TASK_COUNT];
     70  Atomic_Uint done;
     71  task_id id_2;
     72  rtems_event_set events_2;
     73  task_id id_3;
     74  rtems_event_set events_3;
    6675  int generation[TASK_COUNT];
    6776  int expected_generation[TASK_COUNT];
     
    6978
    7079static test_context test_instance;
     80
     81static void assert_cpu(uint32_t expected_cpu)
     82{
     83  rtems_test_assert(rtems_get_current_processor() == expected_cpu);
     84}
    7185
    7286static void test_task_get_priority_not_defined(test_context *ctx)
     
    124138}
    125139
     140static void set_event_2(
     141  test_context *ctx,
     142  task_id id_2,
     143  rtems_event_set events_2
     144)
     145{
     146  ctx->id_2 = id_2;
     147  ctx->events_2 = events_2;
     148}
     149
     150static void set_event_3(
     151  test_context *ctx,
     152  task_id id_3,
     153  rtems_event_set events_3
     154)
     155{
     156  ctx->id_3 = id_3;
     157  ctx->events_3 = events_3;
     158}
     159
     160static void clear_done(test_context *ctx)
     161{
     162  _Atomic_Store_uint(&ctx->done, 0, ATOMIC_ORDER_RELAXED);
     163}
     164
     165static void set_done(test_context *ctx)
     166{
     167  _Atomic_Store_uint(&ctx->done, 1, ATOMIC_ORDER_RELEASE);
     168}
     169
     170static bool is_done(test_context *ctx)
     171{
     172  return _Atomic_Load_uint(&ctx->done, ATOMIC_ORDER_ACQUIRE) != 0;
     173}
     174
     175static void wait_for_done(test_context *ctx)
     176{
     177  while (!is_done(ctx)) {
     178    /* Wait */
     179  }
     180}
     181
     182static void request_pre_emption(test_context *ctx, task_id id)
     183{
     184  clear_done(ctx);
     185  send_event(ctx, id, REQ_SET_DONE);
     186  wait_for_done(ctx);
     187}
     188
    126189static rtems_event_set wait_for_events(void)
    127190{
     
    158221{
    159222  send_event(ctx, id, req);
    160   sync_with_helper(ctx);
     223  clear_done(ctx);
     224
     225  if (rtems_get_current_processor() == 0) {
     226    id = H_B;
     227  } else {
     228    id = H_A;
     229  }
     230
     231  send_event(ctx, id, REQ_SET_DONE);
     232  wait_for_done(ctx);
    161233}
    162234
     
    240312    rtems_test_assert(ctx->generation[i] == ctx->expected_generation[i]);
    241313  }
     314}
     315
     316static void set_prio(test_context *ctx, task_id id, rtems_task_priority prio)
     317{
     318  rtems_status_code sc;
     319
     320  sc = rtems_task_set_priority(ctx->tasks[id], prio, &prio);
     321  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    242322}
    243323
     
    304384      sem_release(ctx);
    305385    }
     386
     387    if ((events & REQ_SET_DONE) != 0) {
     388      set_done(ctx);
     389    }
    306390  }
    307391}
     
    344428      ++ctx->generation[id];
    345429      sem_release(ctx);
     430    }
     431
     432    if ((events & REQ_SEND_EVENT_2) != 0) {
     433      send_event(ctx, ctx->id_2, ctx->events_2);
     434    }
     435
     436    if ((events & REQ_SEND_EVENT_3) != 0) {
     437      send_event(ctx, ctx->id_3, ctx->events_3);
     438    }
     439
     440    if ((events & REQ_SET_DONE) != 0) {
     441      set_done(ctx);
     442    }
     443
     444    if ((events & REQ_WAIT_FOR_DONE) != 0) {
     445      wait_for_done(ctx);
    346446    }
    347447  }
     
    673773}
    674774
     775static void test_omip_pre_emption(test_context *ctx)
     776{
     777  assert_cpu(0);
     778  obtain(ctx);
     779  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     780  assert_prio_by_scheduler(ctx, M, SCHED_B, PRIO_NONE);
     781
     782  request(ctx, B_5_0, REQ_MTX_OBTAIN);
     783  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     784  assert_prio_by_scheduler(ctx, M, SCHED_B, 5);
     785  check_generations(ctx, NONE, NONE);
     786
     787  request_pre_emption(ctx, A_1);
     788  assert_cpu(1);
     789
     790  request_pre_emption(ctx, B_4);
     791  assert_cpu(0);
     792
     793  request_pre_emption(ctx, A_1);
     794  assert_cpu(1);
     795
     796  release(ctx);
     797  assert_cpu(0);
     798  sync_with_helper(ctx);
     799  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     800  assert_prio_by_scheduler(ctx, M, SCHED_B, PRIO_NONE);
     801  check_generations(ctx, B_5_0, NONE);
     802
     803  request(ctx, B_5_0, REQ_MTX_RELEASE);
     804  assert_prio_by_scheduler(ctx, B_5_0, SCHED_A, PRIO_NONE);
     805  assert_prio_by_scheduler(ctx, B_5_0, SCHED_B, 5);
     806  check_generations(ctx, B_5_0, NONE);
     807}
     808
     809static void test_omip_rescue(test_context *ctx)
     810{
     811  assert_cpu(0);
     812  obtain(ctx);
     813  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     814  assert_prio_by_scheduler(ctx, M, SCHED_B, PRIO_NONE);
     815
     816  clear_done(ctx);
     817  set_event_3(ctx, H_B, REQ_SET_DONE);
     818  set_event_2(ctx, B_5_0, REQ_SEND_EVENT_3 | REQ_MTX_OBTAIN);
     819  send_event(ctx, A_1, REQ_SEND_EVENT_2 | REQ_WAIT_FOR_DONE);
     820  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     821  assert_prio_by_scheduler(ctx, M, SCHED_B, 5);
     822  assert_cpu(1);
     823
     824  release(ctx);
     825  assert_cpu(0);
     826  sync_with_helper(ctx);
     827  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     828  assert_prio_by_scheduler(ctx, M, SCHED_B, PRIO_NONE);
     829  check_generations(ctx, B_5_0, NONE);
     830
     831  request(ctx, B_5_0, REQ_MTX_RELEASE);
     832  assert_prio_by_scheduler(ctx, B_5_0, SCHED_A, PRIO_NONE);
     833  assert_prio_by_scheduler(ctx, B_5_0, SCHED_B, 5);
     834  check_generations(ctx, B_5_0, NONE);
     835}
     836
     837static void test_omip_timeout(test_context *ctx)
     838{
     839  assert_cpu(0);
     840  obtain(ctx);
     841  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     842  assert_prio_by_scheduler(ctx, M, SCHED_B, PRIO_NONE);
     843
     844  clear_done(ctx);
     845  set_event_3(ctx, H_B, REQ_SET_DONE);
     846  set_event_2(ctx, B_5_0, REQ_SEND_EVENT_3 | REQ_MTX_OBTAIN_TIMEOUT);
     847  send_event(ctx, A_1, REQ_SEND_EVENT_2 | REQ_WAIT_FOR_DONE);
     848  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     849  assert_prio_by_scheduler(ctx, M, SCHED_B, 5);
     850  assert_cpu(1);
     851
     852  wait();
     853  assert_prio_by_scheduler(ctx, M, SCHED_A, 3);
     854  assert_prio_by_scheduler(ctx, M, SCHED_B, PRIO_NONE);
     855  check_generations(ctx, B_5_0, NONE);
     856  assert_cpu(0);
     857
     858  release(ctx);
     859}
     860
    675861static void test(void)
    676862{
     
    686872  test_nested_inheritance_two_scheduler_instances(ctx);
    687873  test_dequeue_order_two_scheduler_instances(ctx);
     874  test_omip_pre_emption(ctx);
     875  test_omip_rescue(ctx);
     876  test_omip_timeout(ctx);
    688877}
    689878
Note: See TracChangeset for help on using the changeset viewer.