diff options
author | Richard Braun <rbraun@sceen.net> | 2017-09-06 23:44:11 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-09-07 00:53:16 +0200 |
commit | 69d73fd289e6e4b2202968a515947d6af2e90fc0 (patch) | |
tree | f90b10c9c12a0f8c2289a9987545cf87578b9974 /test | |
parent | ae2a752261bc95a2227c74785f11d535070696f6 (diff) |
test/test_mutex_pi: make test threads sleep
Unlike the TODO description, this change only adds a sleep to make
processor time available to the system, because changing as described
by the TODO entry makes it much more difficult to produce the expected
results.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_mutex_pi.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/test/test_mutex_pi.c b/test/test_mutex_pi.c index cfadb59c..ef470488 100644 --- a/test/test_mutex_pi.c +++ b/test/test_mutex_pi.c @@ -59,9 +59,6 @@ * In order to artificially create priority inversions, all threads run on * separate processors, making this test require 5 processors. * - * TODO Use timers instead of busy-waiting so that binding to processors - * isn't required. - * * The test should output a couple of messages about thread priorities * being boosted, and then frequent updates from each thread to show * they're all making progress. Thread B suffers from contention the most @@ -90,6 +87,8 @@ #include <kern/turnstile.h> #include <test/test.h> +#define TEST_MIN_CPUS 5 + #define TEST_PRIO_A (THREAD_SCHED_RT_PRIO_MIN + 1) #define TEST_PRIO_B (TEST_PRIO_A + 1) #define TEST_PRIO_C (TEST_PRIO_B + 1) @@ -136,10 +135,17 @@ test_get_name(void) } static void -test_consume_cpu(void) +test_delay(void) { volatile unsigned int i; + /* + * Put the thread to sleep to make some CPU time available, and then + * busy-wait to avoid synchronizing all threads on the clock tick. + */ + + thread_delay(1, false); + for (i = 0; i < TEST_NR_CONSUME_CPU_LOOPS; i++); } @@ -233,13 +239,13 @@ test_a(void *arg) for (i = 1; /* no condition */; i++) { for (j = 0; j < TEST_NR_LOCK_LOOPS; j++) { mutex_lock(&test_mutex_1); - test_consume_cpu(); + test_delay(); test_for_priority_boosted(&highest_priority); mutex_unlock(&test_mutex_1); test_for_priority_deboosted(); - test_consume_cpu(); + test_delay(); } test_report_progress(i); @@ -254,12 +260,12 @@ test_b(void *arg) mutex_lock(&test_mutex_3); mutex_lock(&test_mutex_2); mutex_lock(&test_mutex_1); - test_consume_cpu(); + test_delay(); test_for_priority_boosted(arg); mutex_unlock(&test_mutex_1); - test_consume_cpu(); + test_delay(); mutex_unlock(&test_mutex_2); - test_consume_cpu(); + test_delay(); mutex_unlock(&test_mutex_3); /* @@ -301,7 +307,7 @@ test_manage_b(void *arg) error_check(error, "thread_create"); thread_join(thread_b); - test_consume_cpu(); + test_delay(); } printf("b:%u ", i); @@ -324,13 +330,13 @@ test_c(void *arg) for (i = 1; /* no condition */; i++) { for (j = 0; j < TEST_NR_LOCK_LOOPS; j++) { mutex_lock(&test_mutex_2); - test_consume_cpu(); + test_delay(); test_for_priority_boosted(&highest_priority); mutex_unlock(&test_mutex_2); test_for_priority_deboosted(); - test_consume_cpu(); + test_delay(); } test_report_progress(i); @@ -344,7 +350,7 @@ test_chprio_c(void *arg) thread_c = arg; - test_consume_cpu(); + test_delay(); for (;;) { thread_setscheduler(thread_c, THREAD_SCHED_POLICY_FIFO, @@ -369,13 +375,13 @@ test_d(void *arg) for (i = 1; /* no condition */; i++) { for (j = 0; j < TEST_NR_LOCK_LOOPS; j++) { mutex_lock(&test_mutex_3); - test_consume_cpu(); + test_delay(); test_for_priority_boosted(&highest_priority); mutex_unlock(&test_mutex_3); test_for_priority_deboosted(); - test_consume_cpu(); + test_delay(); } test_report_progress(i); @@ -397,13 +403,13 @@ test_e(void *arg) for (i = 1; /* no condition */; i++) { for (j = 0; j < TEST_NR_LOCK_LOOPS; j++) { mutex_lock(&test_mutex_3); - test_consume_cpu(); + test_delay(); test_for_priority_boosted(&highest_priority); mutex_unlock(&test_mutex_3); test_for_priority_deboosted(); - test_consume_cpu(); + test_delay(); } test_report_progress(i); @@ -418,6 +424,10 @@ test_setup(void) struct cpumap *cpumap; int error; + if (cpu_count() < TEST_MIN_CPUS) { + panic("test: at least %u processors are required", TEST_MIN_CPUS); + } + mutex_init(&test_mutex_1); mutex_init(&test_mutex_2); mutex_init(&test_mutex_3); |