forked from Imagelibrary/rtems
smptests/smpmrsp01: Use busy waits
Use busy waits instead of sleeps to avoid unnecessary switches to the idle thread.
This commit is contained in:
@@ -78,11 +78,26 @@ static test_context test_instance = {
|
|||||||
.switch_lock = SMP_LOCK_INITIALIZER("test instance switch lock")
|
.switch_lock = SMP_LOCK_INITIALIZER("test instance switch lock")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void busy_wait(void)
|
||||||
|
{
|
||||||
|
rtems_interval later = rtems_clock_tick_later(2);
|
||||||
|
|
||||||
|
while (rtems_clock_tick_before(later)) {
|
||||||
|
/* Wait */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void barrier(test_context *ctx, SMP_barrier_State *bs)
|
static void barrier(test_context *ctx, SMP_barrier_State *bs)
|
||||||
{
|
{
|
||||||
_SMP_barrier_Wait(&ctx->barrier, bs, 2);
|
_SMP_barrier_Wait(&ctx->barrier, bs, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void barrier_and_delay(test_context *ctx, SMP_barrier_State *bs)
|
||||||
|
{
|
||||||
|
barrier(ctx, bs);
|
||||||
|
busy_wait();
|
||||||
|
}
|
||||||
|
|
||||||
static rtems_task_priority get_prio(rtems_id task_id)
|
static rtems_task_priority get_prio(rtems_id task_id)
|
||||||
{
|
{
|
||||||
rtems_status_code sc;
|
rtems_status_code sc;
|
||||||
@@ -347,19 +362,13 @@ static void test_mrsp_obtain_and_release(test_context *ctx)
|
|||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||||
|
|
||||||
/* Obtain with timeout (A) */
|
/* Obtain with timeout (A) */
|
||||||
barrier(ctx, &barrier_state);
|
barrier_and_delay(ctx, &barrier_state);
|
||||||
|
|
||||||
sc = rtems_task_wake_after(2);
|
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
|
||||||
|
|
||||||
assert_prio(ctx->worker_ids[0], 2);
|
assert_prio(ctx->worker_ids[0], 2);
|
||||||
assert_executing_worker(ctx);
|
assert_executing_worker(ctx);
|
||||||
|
|
||||||
/* Obtain with priority change and timeout (B) */
|
/* Obtain with priority change and timeout (B) */
|
||||||
barrier(ctx, &barrier_state);
|
barrier_and_delay(ctx, &barrier_state);
|
||||||
|
|
||||||
sc = rtems_task_wake_after(2);
|
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
|
||||||
|
|
||||||
assert_prio(ctx->worker_ids[0], 2);
|
assert_prio(ctx->worker_ids[0], 2);
|
||||||
change_prio(ctx->worker_ids[0], 1);
|
change_prio(ctx->worker_ids[0], 1);
|
||||||
@@ -372,10 +381,7 @@ static void test_mrsp_obtain_and_release(test_context *ctx)
|
|||||||
change_prio(ctx->worker_ids[0], 3);
|
change_prio(ctx->worker_ids[0], 3);
|
||||||
|
|
||||||
/* Obtain without timeout (D) */
|
/* Obtain without timeout (D) */
|
||||||
barrier(ctx, &barrier_state);
|
barrier_and_delay(ctx, &barrier_state);
|
||||||
|
|
||||||
sc = rtems_task_wake_after(2);
|
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
|
||||||
|
|
||||||
assert_prio(ctx->worker_ids[0], 2);
|
assert_prio(ctx->worker_ids[0], 2);
|
||||||
assert_executing_worker(ctx);
|
assert_executing_worker(ctx);
|
||||||
@@ -835,16 +841,12 @@ static void various_block_unblock(test_context *ctx)
|
|||||||
SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
|
SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
|
||||||
|
|
||||||
/* Worker obtain (F) */
|
/* Worker obtain (F) */
|
||||||
barrier(ctx, &barrier_state);
|
barrier_and_delay(ctx, &barrier_state);
|
||||||
|
|
||||||
sc = rtems_task_wake_after(2);
|
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
|
||||||
|
|
||||||
sc = rtems_task_suspend(ctx->worker_ids[0]);
|
sc = rtems_task_suspend(ctx->worker_ids[0]);
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||||
|
|
||||||
sc = rtems_task_wake_after(2);
|
busy_wait();
|
||||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
|
||||||
|
|
||||||
sc = rtems_task_start(
|
sc = rtems_task_start(
|
||||||
ctx->high_task_id[1],
|
ctx->high_task_id[1],
|
||||||
|
|||||||
Reference in New Issue
Block a user