From: Gowrishankar <gomuthuk@linux.vnet.ibm.com>
To: Linux Test Project <ltp-list@lists.sourceforge.net>
Cc: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
Subject: [LTP] [PATCH 6/6] realtime: synchronization fixes for high priority noise thread
Date: Thu, 27 May 2010 09:41:26 +0530 [thread overview]
Message-ID: <1274933486-4876-7-git-send-email-gomuthuk@linux.vnet.ibm.com> (raw)
In-Reply-To: <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
In a scenario where high priority noise thread is not scheduled after the
barrier but some other real-time thread, the test intention gets broken by
the test code, as priority inversion will never happen. We need to tightly
synchronize the threads so the noise thread always begins the test so that
it gets preempted by low prio thread through PI logic and is done with
conditional variables.
This change is applied on both the tests testpi-1 and testpi-2.
Signed-off-by: Gowrishankar<gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar<gowrishankar.m@in.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-1.c | 23 +++++++++++++++++++++--
testcases/realtime/func/pi-tests/testpi-2.c | 24 ++++++++++++++++++++++--
2 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index 3e05e56..5d18f29 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -30,8 +30,9 @@
*
*
* HISTORY
- * 2010-04-22 Code cleanup by Gowrishankar
- *
+ * 2010-04-22 Code cleanup and thread synchronization changes by using
+ * conditional variables,
+ * by Gowrishankar(gowrishankar.m@in.ibm.com).
*
*****************************************************************************/
@@ -74,6 +75,8 @@ int gettid(void)
typedef void *(*entrypoint_t)(void *);
pthread_mutex_t glob_mutex;
+static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
void *func_nonrt(void *arg)
{
@@ -88,6 +91,11 @@ void *func_nonrt(void *arg)
/* Wait for other RT threads to start up */
pthread_barrier_wait(&barrier);
+ /* Wait for the high priority noise thread to start and signal us */
+ pthread_mutex_lock(&cond_mutex);
+ pthread_cond_wait(&cond_var, &cond_mutex);
+ pthread_mutex_unlock(&cond_mutex);
+
for (i = 0; i < 10000; i++) {
if (i%100 == 0) {
printf("Thread %d loop %d pthread pol %d pri %d\n",\
@@ -137,6 +145,14 @@ void *func_noise(void *arg)
pthr->priority);
pthread_barrier_wait(&barrier);
+ /* Let others wait at conditional variable */
+ usleep(1000);
+
+ /* Noise thread begins the test */
+ pthread_mutex_lock(&cond_mutex);
+ pthread_cond_broadcast(&cond_var);
+ pthread_mutex_unlock(&cond_mutex);
+
for (i = 0; i < 10000; i++) {
if (i%100 == 0) {
printf("Noise Thread %d loop %d pthread pol %d "\
@@ -197,5 +213,8 @@ int main(int argc, char *argv[])
printf("Criteria:Low Priority Thread should Preempt Higher Priority "\
"Noise Thread\n");
+ pthread_mutex_destroy(&glob_mutex);
+ pthread_mutex_destroy(&cond_mutex);
+ pthread_cond_destroy(&cond_var);
return 0;
}
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index f0e86ea..55b391b 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -31,8 +31,9 @@
*
*
* HISTORY
- * 2010-04-22 Code cleanup by Gowrishankar
- *
+ * 2010-04-22 Code cleanup and thread synchronization changes by using
+ * conditional variables,
+ * by Gowrishankar(gowrishankar.m@in.ibm.com).
*
*****************************************************************************/
@@ -76,6 +77,8 @@ int gettid(void)
typedef void *(*entrypoint_t)(void *);
pthread_mutex_t glob_mutex;
+static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
void *func_lowrt(void *arg)
{
@@ -90,6 +93,11 @@ void *func_lowrt(void *arg)
/* Wait for other RT threads to start up */
pthread_barrier_wait(&barrier);
+ /* Wait for the high priority noise thread to start and signal us */
+ pthread_mutex_lock(&cond_mutex);
+ pthread_cond_wait(&cond_var, &cond_mutex);
+ pthread_mutex_unlock(&cond_mutex);
+
for (i = 0; i < 10000; i++) {
if (i%100 == 0) {
printf("Thread %d loop %d pthread pol %d pri %d\n",\
@@ -139,6 +147,14 @@ void *func_noise(void *arg)
pthr->priority);
pthread_barrier_wait(&barrier);
+ /* Let others wait at conditional variable */
+ usleep(1000);
+
+ /* Noise thread begins the test */
+ pthread_mutex_lock(&cond_mutex);
+ pthread_cond_broadcast(&cond_var);
+ pthread_mutex_unlock(&cond_mutex);
+
for (i = 0; i < 10000; i++) {
if (i%100 == 0) {
printf("Noise Thread %d loop %d pthread pol %d "\
@@ -197,5 +213,9 @@ int main(int argc, char *argv[])
printf("Done\n");
printf("Criteria: Low Priority Thread and High Priority Thread "\
"should prempt each other multiple times\n");
+
+ pthread_mutex_destroy(&glob_mutex);
+ pthread_mutex_destroy(&cond_mutex);
+ pthread_cond_destroy(&cond_var);
return 0;
}
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
prev parent reply other threads:[~2010-05-27 4:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
2010-05-27 4:03 ` [LTP] [PATCH 0/5] realtime: code cleanup on pi-tests to adapt C coding standard Gowrishankar
2010-05-28 7:32 ` Subrata Modak
2010-05-27 4:03 ` [LTP] [PATCH 1/5] realtime: code cleanup on pi-test 0 Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 2/5] realtime: code cleanup on pi-test 1 Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 3/5] realtime: code cleanup on pi-test 2 Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 4/5] realtime: code cleanup on pi-test 5 Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 5/5] realtime: code cleanup on pi-test 6 Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests Gowrishankar
2010-05-28 7:31 ` Subrata Modak
2010-05-27 4:11 ` [LTP] [PATCH 1/6] realtime: reuse init_pi_mutex from librttest Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 2/6] realtime: add test descriptions Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 3/6] realtime: threads need not set cpu affinity while main does Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 4/6] realtime: use busy_work_ms from librttest to burn cpu cycles Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 5/6] realtime: remove thread_stop which is not used anywhere Gowrishankar
2010-05-27 4:11 ` Gowrishankar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1274933486-4876-7-git-send-email-gomuthuk@linux.vnet.ibm.com \
--to=gomuthuk@linux.vnet.ibm.com \
--cc=gowrishankar.m@linux.vnet.ibm.com \
--cc=ltp-list@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox