Changeset 8c7eb00 in rtems


Ignore:
Timestamp:
Mar 17, 2015, 9:32:20 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
ac8339a
Parents:
8e10f62
git-author:
Sebastian Huber <sebastian.huber@…> (03/17/15 09:32:20)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/17/15 09:32:57)
Message:

testsupport: Add worker setup handler

Add rtems_test_parallel_get_task_id().

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/testsupport/test.h

    r8e10f62 r8c7eb00  
    126126  SMP_barrier_Control barrier;
    127127  size_t worker_count;
     128  rtems_id worker_ids[32];
    128129  rtems_id stop_worker_timer_id;
    129   rtems_id master_id;
    130130} rtems_test_parallel_context;
     131
     132/**
     133 * @brief Worker task setup handler.
     134 *
     135 * Called during rtems_test_parallel() to optionally setup a worker task before
     136 * it is started.
     137 *
     138 * @param[in] ctx The parallel context.
     139 * @param[in] worker_index The worker index.
     140 * @param[in] worker_id The worker task identifier.
     141 */
     142typedef void (*rtems_test_parallel_worker_setup)(
     143  rtems_test_parallel_context *ctx,
     144  size_t worker_index,
     145  rtems_id worker_id
     146);
    131147
    132148/**
     
    212228 */
    213229static inline bool rtems_test_parallel_stop_job(
    214   rtems_test_parallel_context *ctx
     230  const rtems_test_parallel_context *ctx
    215231)
    216232{
     
    234250
    235251/**
     252 * @brief Returns the task identifier for a worker.
     253 *
     254 * @param[in] ctx The parallel context.
     255 * @param[in] worker_index The worker index.
     256 *
     257 * @return The task identifier of the worker.
     258 */
     259static inline rtems_id rtems_test_parallel_get_task_id(
     260  const rtems_test_parallel_context *ctx,
     261  size_t worker_index
     262)
     263{
     264  return ctx->worker_ids[worker_index];
     265}
     266
     267/**
    236268 * @brief Runs a bunch of jobs in parallel on all processors of the system.
    237269 *
     270 * The worker tasks inherit the priority of the executing task.
     271 *
    238272 * There are SMP barriers before and after the job body.
    239273 *
    240274 * @param[in] ctx The parallel context.
    241  * @param[in] non_master_worker_priority The task priority for non-master
    242  *   workers.
     275 * @param[in] worker_setup Optional handler to setup a worker task before it is
     276 *   started.
    243277 * @param[in] jobs The table of jobs.
    244278 * @param[in] job_count The count of jobs in the job table.
     
    246280void rtems_test_parallel(
    247281  rtems_test_parallel_context *ctx,
    248   rtems_task_priority non_master_worker_priority,
     282  rtems_test_parallel_worker_setup worker_setup,
    249283  const rtems_test_parallel_job *jobs,
    250284  size_t job_count
  • cpukit/libmisc/testsupport/testparallel.c

    r8e10f62 r8c7eb00  
    101101  rtems_status_code sc;
    102102
    103   sc = rtems_event_transient_send(warg.ctx->master_id);
     103  sc = rtems_event_transient_send(warg.ctx->worker_ids[0]);
    104104  _Assert(sc == RTEMS_SUCCESSFUL);
    105105  (void) sc;
     
    107107  run_tests(warg.ctx, warg.jobs, warg.job_count, warg.worker_index);
    108108
    109   rtems_task_delete(RTEMS_SELF);
     109  rtems_task_suspend(RTEMS_SELF);
    110110}
    111111
    112112void rtems_test_parallel(
    113113  rtems_test_parallel_context *ctx,
    114   rtems_task_priority non_master_worker_priority,
     114  rtems_test_parallel_worker_setup worker_setup,
    115115  const rtems_test_parallel_job *jobs,
    116116  size_t job_count
     
    119119  rtems_status_code sc;
    120120  size_t worker_index;
     121  rtems_task_priority worker_priority;
    121122
    122123  _Atomic_Init_ulong(&ctx->stop, 0);
    123124  _SMP_barrier_Control_initialize(&ctx->barrier);
    124125  ctx->worker_count = rtems_get_processor_count();
    125   ctx->master_id = rtems_task_self();
     126  ctx->worker_ids[0] = rtems_task_self();
     127
     128  if (RTEMS_ARRAY_SIZE(ctx->worker_ids) < ctx->worker_count) {
     129    rtems_fatal_error_occurred(0xdeadbeef);
     130  }
     131
     132  sc = rtems_task_set_priority(
     133    RTEMS_SELF,
     134    RTEMS_CURRENT_PRIORITY,
     135    &worker_priority
     136  );
     137  if (sc != RTEMS_SUCCESSFUL) {
     138    rtems_fatal_error_occurred(0xdeadbeef);
     139  }
    126140
    127141  sc = rtems_timer_create(
     
    130144  );
    131145  if (sc != RTEMS_SUCCESSFUL) {
    132     rtems_fatal_error_occurred(sc);
     146    rtems_fatal_error_occurred(0xdeadbeef);
    133147  }
    134148
     
    144158    sc = rtems_task_create(
    145159      rtems_build_name('W', 'O', 'R', 'K'),
    146       non_master_worker_priority,
     160      worker_priority,
    147161      RTEMS_MINIMUM_STACK_SIZE,
    148162      RTEMS_DEFAULT_MODES,
     
    151165    );
    152166    if (sc != RTEMS_SUCCESSFUL) {
    153       rtems_fatal_error_occurred(sc);
     167      rtems_fatal_error_occurred(0xdeadbeef);
     168    }
     169
     170    ctx->worker_ids[worker_index] = worker_id;
     171
     172    if (worker_setup != NULL) {
     173      (*worker_setup)(ctx, worker_index, worker_id);
    154174    }
    155175
     
    163183  run_tests(ctx, jobs, job_count, 0);
    164184
     185  for (worker_index = 1; worker_index < ctx->worker_count; ++worker_index) {
     186    sc = rtems_task_delete(ctx->worker_ids[worker_index]);
     187    _Assert(sc == RTEMS_SUCCESSFUL);
     188  }
     189
    165190  sc = rtems_timer_delete(ctx->stop_worker_timer_id);
    166191  _Assert(sc == RTEMS_SUCCESSFUL);
  • testsuites/smptests/smpatomic01/init.c

    r8e10f62 r8c7eb00  
    419419  }, {
    420420    .init = test_atomic_flag_init,
    421     .body =test_atomic_flag_body,
    422     .fini =test_atomic_flag_fini
     421    .body = test_atomic_flag_body,
     422    .fini = test_atomic_flag_fini
    423423  }, {
    424424    .init = test_atomic_sub_init,
    425     .body =test_atomic_sub_body,
    426     .fini =test_atomic_sub_fini
     425    .body = test_atomic_sub_body,
     426    .fini = test_atomic_sub_fini
    427427  }, {
    428428    .init = test_atomic_compare_exchange_init,
    429     .body =test_atomic_compare_exchange_body,
    430     .fini =test_atomic_compare_exchange_fini
     429    .body = test_atomic_compare_exchange_body,
     430    .fini = test_atomic_compare_exchange_fini
    431431  }, {
    432432    .init = test_atomic_or_and_init,
    433     .body =test_atomic_or_and_body,
    434     .fini =test_atomic_or_and_fini
     433    .body = test_atomic_or_and_body,
     434    .fini = test_atomic_or_and_fini
    435435  }, {
    436436    .init = test_atomic_fence_init,
    437     .body =test_atomic_fence_body,
    438     .fini =test_atomic_fence_fini
     437    .body = test_atomic_fence_body,
     438    .fini = test_atomic_fence_fini
    439439  },
    440440};
    441441
     442static void setup_worker(
     443  rtems_test_parallel_context *base,
     444  size_t worker_index,
     445  rtems_id worker_id
     446)
     447{
     448  rtems_status_code sc;
     449  rtems_task_priority prio;
     450
     451  sc = rtems_task_set_priority(worker_id, WORKER_PRIORITY, &prio);
     452  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     453}
     454
    442455static void Init(rtems_task_argument arg)
    443456{
     
    448461  rtems_test_parallel(
    449462    &ctx->base,
    450     WORKER_PRIORITY,
     463    setup_worker,
    451464    &test_jobs[0],
    452465    RTEMS_ARRAY_SIZE(test_jobs)
  • testsuites/tmtests/tmfine01/init.c

    r8e10f62 r8c7eb00  
    439439  rtems_test_parallel(
    440440    &ctx->base,
    441     1,
     441    NULL,
    442442    &test_jobs[0],
    443443    RTEMS_ARRAY_SIZE(test_jobs)
Note: See TracChangeset for help on using the changeset viewer.