Ignore:
Timestamp:
Mar 5, 2015, 8:06:44 AM (6 years ago)
Author:
Alexander Krutwig <alexander.krutwig@…>
Branches:
4.11, 5, master
Children:
5b5d2fd4
Parents:
51acbdc
git-author:
Alexander Krutwig <alexander.krutwig@…> (03/05/15 08:06:44)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/05/15 08:12:14)
Message:

tests: Refactor parallel test execution

File:
1 edited

Legend:

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

    r51acbdc r7f577d3  
    1818#include <rtems.h>
    1919#include <rtems/bspIo.h>
     20#include <rtems/score/atomic.h>
     21#include <rtems/score/smpbarrier.h>
    2022
    2123#ifdef __cplusplus
     
    117119}
    118120
     121/**
     122 * @brief Internal context for parallel job execution.
     123 */
     124typedef struct {
     125  Atomic_Ulong stop;
     126  SMP_barrier_Control barrier;
     127  size_t worker_count;
     128  rtems_id stop_worker_timer_id;
     129  rtems_id master_id;
     130} rtems_test_parallel_context;
     131
     132/**
     133 * @brief Basic parallel job description.
     134 */
     135typedef struct {
     136  /**
     137   * @brief Job initialization handler.
     138   *
     139   * This handler executes only in the context of the master worker before the
     140   * job body handler.
     141   *
     142   * @param[in] ctx The parallel context.
     143   * @param[in] arg The user specified argument.
     144   *
     145   * @return The desired job body execution time in clock ticks.  See
     146   *   rtems_test_parallel_stop_job().
     147   */
     148  rtems_interval (*init)(
     149    rtems_test_parallel_context *ctx,
     150    void *arg
     151  );
     152
     153  /**
     154   * @brief Job body handler.
     155   *
     156   * @param[in] ctx The parallel context.
     157   * @param[in] arg The user specified argument.
     158   * @param[in] worker_index The worker index.  It ranges from 0 to the
     159   *   processor count minus one.
     160   */
     161  void (*body)(
     162    rtems_test_parallel_context *ctx,
     163    void *arg,
     164    size_t worker_index
     165  );
     166
     167  /**
     168   * @brief Job finalization handler.
     169   *
     170   * This handler executes only in the context of the master worker after the
     171   * job body handler.
     172   *
     173   * @param[in] ctx The parallel context.
     174   * @param[in] arg The user specified argument.
     175   */
     176  void (*fini)(
     177    rtems_test_parallel_context *ctx,
     178    void *arg
     179  );
     180
     181  void *arg;
     182} rtems_test_parallel_job;
     183
     184/**
     185 * @brief Indicates if a job body should stop its work loop.
     186 *
     187 * @param[in] ctx The parallel context.
     188 *
     189 * @retval true The job body should stop its work loop and return to the caller.
     190 * @retval false Otherwise.
     191 */
     192static inline bool rtems_test_parallel_stop_job(
     193  rtems_test_parallel_context *ctx
     194)
     195{
     196  return _Atomic_Load_ulong(&ctx->stop, ATOMIC_ORDER_RELAXED) != 0;
     197}
     198
     199/**
     200 * @brief Indicates if a worker is the master worker.
     201 *
     202 * The master worker is the thread that called rtems_test_parallel().
     203 *
     204 * @param[in] worker_index The worker index.
     205 *
     206 * @retval true This is the master worker.
     207 * @retval false Otherwise.
     208 */
     209static inline bool rtems_test_parallel_is_master_worker(size_t worker_index)
     210{
     211  return worker_index == 0;
     212}
     213
     214/**
     215 * @brief Runs a bunch of jobs in parallel on all processors of the system.
     216 *
     217 * There are SMP barriers before and after the job body.
     218 *
     219 * @param[in] ctx The parallel context.
     220 * @param[in] non_master_worker_priority The task priority for non-master
     221 *   workers.
     222 * @param[in] jobs The table of jobs.
     223 * @param[in] job_count The count of jobs in the job table.
     224 */
     225void rtems_test_parallel(
     226  rtems_test_parallel_context *ctx,
     227  rtems_task_priority non_master_worker_priority,
     228  const rtems_test_parallel_job *jobs,
     229  size_t job_count
     230);
     231
    119232/** @} */
    120233
Note: See TracChangeset for help on using the changeset viewer.