Skip to content

Commit

Permalink
SCHED0021: decrease chances of a race condition
Browse files Browse the repository at this point in the history
Decrease the chance that the monitor thread is preempted just when it
has released the preemption threads, but before it has yielded itself.
(If that happens, the preemption threads get two time slices.)

See also #42

Signed-off-by: Gerwin Klein <[email protected]>
  • Loading branch information
lsf37 committed Oct 27, 2023
1 parent 99a462e commit cbeda68
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/sel4test-tests/src/tests/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1598,19 +1598,25 @@ static int test_simple_preempt(struct env *env)

/* Set a timeout for the test.
* Each thread should be run for one tick */
uint64_t start = time_now(env);
uint64_t now = start;

/* Start executing other threads */
ZF_LOGD("Releasing Threads");
/* Release our time slice now to get a new one. That should ensure we are
* not interrupted due to bad luck by the preemptive scheduler right after
* setting test_simple_preempt_start to 1 and then voluntarily yielding
* (which gives the preemption threads 2 time slices instead of one). For
* the same reason we are also printing the ZF_LOGD() above already.
*/
seL4_Yield();
uint64_t start = time_now(env);
test_simple_preempt_start = 1;
/* Yield should cause all other threads to execute before returning
* to the current thread. */
seL4_Yield();
test_simple_preempt_start = 0;

/* Get the total time taken to synchronise */
now = time_now(env);
uint64_t now = time_now(env);
uint64_t duration = now - start;

for (size_t thread = 0; thread < PREEMPTION_THREADS; thread += 1) {
Expand Down

0 comments on commit cbeda68

Please sign in to comment.