From: Rishi k. K R. <ris...@li...> - 2010-04-22 06:07:44
|
The branch, master, has been updated via 5162b710bfc574107d915093c08b198f0a15727e (commit) from d0605c4e9525bd5ecdd0ba28ba27b8b237d1cfc8 (commit) - Log ----------------------------------------------------------------- commit 5162b710bfc574107d915093c08b198f0a15727e Author: Rishikesh K Rajak <ris...@li...> Date: Thu Apr 22 11:36:48 2010 +0530 prio-wake: avoid glibc to kernel sleep race In the unlocked broadcast scenario, there exists a race between when the running_threads variable reaches rt_threads and when the last worker_thread blocks in the kernel after a cond_wait(). It is possible for a thread to miss the broadcast if it fails to sleep before the broadcast is issued. The previous code did not guarantee a small window of time to allow the threads to get to sleep. It also used an unreasonably large sleep time which unnecessarily extended the length of the test run time. This patch ensures some time is given to the threads to get to sleep and at the same time uses a much shorter (1000x) sleep period which results in a 50-100x reduction in test run time. Lastly, two unecessary loops waiting for the threads to complete were removed, relying on pthread_join() instead to wait for the threads to complete. Signed-off-by: Darren Hart <dv...@us...> Acked-by: Will Schmidt <wil...@vn...> ----------------------------------------------------------------------- Summary of changes: testcases/realtime/func/prio-wake/prio-wake.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/testcases/realtime/func/prio-wake/prio-wake.c b/testcases/realtime/func/prio-wake/prio-wake.c index 74007f6..1703451 100644 --- a/testcases/realtime/func/prio-wake/prio-wake.c +++ b/testcases/realtime/func/prio-wake/prio-wake.c @@ -108,7 +108,11 @@ void *master_thread(void* arg) /* make sure children are started */ while (running_threads < rt_threads) - sleep(1); + usleep(1000); + /* give the worker threads a chance to get to sleep in the kernel + * in the unlocked broadcast case. */ + usleep(1000); + start = rt_gettime() - beginrun; @@ -120,8 +124,6 @@ void *master_thread(void* arg) if (locked_broadcast) rc = pthread_mutex_unlock(&mutex); - while (running_threads > 0) - sleep(1); return NULL; } @@ -157,9 +159,6 @@ void *worker_thread(void* arg) rc = pthread_mutex_unlock(&mutex); - /* wait for all threads to quit */ - while (running_threads > 0) - sleep(1); return NULL; } hooks/post-receive -- ltp |