Skip to content

Commit d17d1c9

Browse files
committed
Replace volatiles with atomic for SMP tests
Signed-off-by: Indan Zupancic <[email protected]>
1 parent 3583555 commit d17d1c9

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

apps/sel4test-tests/src/tests/multicore.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "../helpers.h"
1616

17-
static int counter_func(volatile seL4_Word *counter)
17+
static int counter_func(_Atomic seL4_Word *counter)
1818
{
1919
while (1) {
2020
(*counter)++;
@@ -25,7 +25,7 @@ static int counter_func(volatile seL4_Word *counter)
2525
int smp_test_tcb_resume(env_t env)
2626
{
2727
helper_thread_t t1;
28-
volatile seL4_Word counter;
28+
_Atomic seL4_Word counter;
2929
ZF_LOGD("smp_test_tcb_resume\n");
3030
create_helper_thread(env, &t1);
3131

@@ -85,7 +85,7 @@ DEFINE_TEST(MULTICORE0001, "Test suspending and resuming a thread on different c
8585
int smp_test_tcb_move(env_t env)
8686
{
8787
helper_thread_t t1;
88-
volatile seL4_Word counter;
88+
_Atomic seL4_Word counter;
8989
ZF_LOGD("smp_test_tcb_move\n");
9090
create_helper_thread(env, &t1);
9191

@@ -125,7 +125,7 @@ DEFINE_TEST(MULTICORE0002, "Test thread is runnable on all available cores (0 +
125125
int smp_test_tcb_delete(env_t env)
126126
{
127127
helper_thread_t t1;
128-
volatile seL4_Word counter;
128+
_Atomic seL4_Word counter;
129129
ZF_LOGD("smp_test_tcb_delete\n");
130130
create_helper_thread(env, &t1);
131131

@@ -185,7 +185,7 @@ faulter_func(volatile seL4_Word shared_mem)
185185
return 0;
186186
}
187187

188-
static int handler_func(seL4_CPtr fault_ep, volatile seL4_Word *pf)
188+
static int handler_func(seL4_CPtr fault_ep, _Atomic seL4_Word *pf)
189189
{
190190
seL4_MessageInfo_t tag;
191191
seL4_Word sender_badge = 0;
@@ -199,7 +199,7 @@ static int handler_func(seL4_CPtr fault_ep, volatile seL4_Word *pf)
199199
static int smp_test_tlb_instance(env_t env, bool inter_as)
200200
{
201201
int error;
202-
volatile seL4_Word tag;
202+
_Atomic seL4_Word tag;
203203
volatile seL4_Word shared_mem = 0;
204204
ZF_LOGD("smp_test_tlb\n");
205205

apps/sel4test-tests/src/tests/schedcontext.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,20 @@ test_revoke_sched_context_on_call_chain(env_t env)
732732
DEFINE_TEST(SCHED_CONTEXT_0013, "Test revoking a scheduling context on a call chain",
733733
test_revoke_sched_context_on_call_chain, config_set(CONFIG_KERNEL_MCS) &&config_set(CONFIG_HAVE_TIMER))
734734

735+
void sched_context_0014_helper_fn(_Atomic seL4_Word *counter)
736+
{
737+
while (1) {
738+
(*counter)++;
739+
}
740+
}
741+
735742
/* Try to recreate race situation of issue 633 */
736743
int test_smp_delete_sched_context(env_t env)
737744
{
738745
seL4_Error error;
739746
helper_thread_t helper;
740-
volatile int state = 0;
741-
int prev_state = state;
747+
_Atomic seL4_Word counter = 0;
748+
seL4_Word prev_counter = counter;
742749

743750
create_helper_thread(env, &helper);
744751
set_helper_priority(env, &helper, env->priority - 1);
@@ -747,10 +754,10 @@ int test_smp_delete_sched_context(env_t env)
747754
helper.thread.sched_context.cptr, MIN_BUDGET_US, 10 * US_IN_MS, 0, 0);
748755
test_eq(error, seL4_NoError);
749756

750-
start_helper(env, &helper, (helper_fn_t)sched_context_0005_helper_fn, (seL4_Word)&state, 0, 0, 0);
757+
start_helper(env, &helper, (helper_fn_t)sched_context_0014_helper_fn, (seL4_Word)&counter, 0, 0, 0);
751758

752759
/* Wait till helper runs */
753-
while (state == prev_state);
760+
while (counter == prev_counter);
754761

755762
vka_free_object(&env->vka, &helper.thread.sched_context);
756763

0 commit comments

Comments
 (0)