* [LTP] [PATCH 0/5] realtime: code cleanup on pi-tests to adapt C coding standard
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
@ 2010-05-27 4:03 ` 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
` (11 subsequent siblings)
12 siblings, 1 reply; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:03 UTC (permalink / raw)
To: Linux Test Project
Following bulk of patches applies the coding style in pi-tests to follow
the C coding standard. All are tested and they go in order:
[PATCH 1/5] realtime: code cleanup on pi-test 0
[PATCH 2/5] realtime: code cleanup on pi-test 1
[PATCH 3/5] realtime: code cleanup on pi-test 2
[PATCH 4/5] realtime: code cleanup on pi-test 5
[PATCH 5/5] realtime: code cleanup on pi-test 6
Thanks,
Gowri
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/5] realtime: code cleanup on pi-test 0
[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-27 4:03 ` Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 2/5] realtime: code cleanup on pi-test 1 Gowrishankar
` (10 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:03 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
This patch cleans up the test so as to follow C coding style standards.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-0.c | 67 ++++++++++++++------------
1 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-0.c b/testcases/realtime/func/pi-tests/testpi-0.c
index 3c56588..cf0a24d 100644
--- a/testcases/realtime/func/pi-tests/testpi-0.c
+++ b/testcases/realtime/func/pi-tests/testpi-0.c
@@ -30,6 +30,7 @@
*
*
* HISTORY
+ * 2010-04-22 Code cleanup by Gowrishankar (gowrishankar.m@in.ibm.com)
*
*
*****************************************************************************/
@@ -45,53 +46,57 @@
void usage(void)
{
- rt_help();
- printf("testpi-0 specific options:\n");
- printf("testpi-0 doesn't require any commandline options\n");
+ rt_help();
+ printf("testpi-0 specific options:\n");
+ printf("testpi-0 doesn't require any commandline options\n");
}
int parse_args(int c, char *v)
{
- int handled = 1;
- switch (c) {
- case 'h':
- usage();
- exit(0);
- default:
- handled = 0;
- break;
- }
- return handled;
+ int handled = 1;
+ switch (c) {
+ case 'h':
+ usage();
+ exit(0);
+ default:
+ handled = 0;
+ break;
+ }
+ return handled;
}
/*
* Test pthread creation at different thread priorities.
*/
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
- char *pathbuf; size_t n;
+ char *pathbuf; size_t n;
- rt_init("h",parse_args,argc,argv);
+ rt_init("h", parse_args, argc, argv);
- n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t)0);
- if ((pathbuf = malloc(n)) == NULL) abort();
- confstr(_CS_GNU_LIBC_VERSION, pathbuf, n);
+ n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t)0);
+ pathbuf = malloc(n);
+ if (!pathbuf)
+ abort();
+ confstr(_CS_GNU_LIBC_VERSION, pathbuf, n);
- printf("LIBC_VERSION: %s\n", pathbuf);
- free(pathbuf);
+ printf("LIBC_VERSION: %s\n", pathbuf);
+ free(pathbuf);
- n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t)0);
- if ((pathbuf = malloc(n)) == NULL) abort();
- confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
+ n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t)0);
+ pathbuf = malloc(n);
+ if (!pathbuf)
+ abort();
+ confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
- printf("LIBPTHREAD_VERSION: %s\n", pathbuf);
- free(pathbuf);
+ printf("LIBPTHREAD_VERSION: %s\n", pathbuf);
+ free(pathbuf);
- if (sysconf(_SC_THREAD_PRIO_INHERIT) == -1) {
- printf("No Prio inheritance support\n");
- }
- printf("Prio inheritance support present\n");
+ if (sysconf(_SC_THREAD_PRIO_INHERIT) == -1)
+ printf("No Prio inheritance support\n");
- return 0;
+ printf("Prio inheritance support present\n");
+
+ return 0;
}
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/5] realtime: code cleanup on pi-test 1
[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-27 4:03 ` [LTP] [PATCH 1/5] realtime: code cleanup on pi-test 0 Gowrishankar
@ 2010-05-27 4:03 ` Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 3/5] realtime: code cleanup on pi-test 2 Gowrishankar
` (9 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:03 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
This patch cleans up the test so as to follow C coding style standards.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-1.c | 348 ++++++++++++++-------------
1 files changed, 183 insertions(+), 165 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index dc6081b..b503c0c 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -30,6 +30,7 @@
*
*
* HISTORY
+ * 2010-04-22 Code cleanup by Gowrishankar
*
*
*****************************************************************************/
@@ -48,23 +49,22 @@ pthread_barrier_t barrier;
void usage(void)
{
- rt_help();
- printf("testpi-1 specific options:\n");
+ rt_help();
+ printf("testpi-1 specific options:\n");
}
int parse_args(int c, char *v)
{
-
- int handled = 1;
- switch (c) {
- case 'h':
- usage();
- exit(0);
- default:
- handled = 0;
- break;
- }
- return handled;
+ int handled = 1;
+ switch (c) {
+ case 'h':
+ usage();
+ exit(0);
+ default:
+ handled = 0;
+ break;
+ }
+ return handled;
}
int gettid(void)
@@ -72,173 +72,191 @@ int gettid(void)
return syscall(__NR_gettid);
}
-typedef void* (*entrypoint_t)(void*);
+typedef void *(*entrypoint_t)(void *);
#define THREAD_STOP 1
pthread_mutex_t glob_mutex;
-void* func_nonrt(void* arg)
+void *func_nonrt(void *arg)
{
- struct thread* pthr = (struct thread* )arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
- exit(-1);
- }
-
- printf("Thread %d started running with priority %d\n", tid, pthr->priority);
- pthread_mutex_lock(&glob_mutex);
- printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
- /* Wait for other RT threads to start up */
- pthread_barrier_wait(&barrier);
-
- for (i=0;i<10000;i++) {
- if (i%100 == 0) {
- printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
- fflush(NULL);
- }
- pthr->id++;
- for (j=0;j<5000;j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
- }
- pthread_mutex_unlock(&glob_mutex);
- return NULL;
+ struct thread *pthr = (struct thread *)arg;
+ int rc, i, j, tid = gettid();
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+
+ rc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (rc < 0) {
+ printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+ strerror(rc));
+ exit(-1);
+ }
+
+ printf("Thread %d started running with priority %d\n", tid,\
+ pthr->priority);
+ pthread_mutex_lock(&glob_mutex);
+ printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",\
+ tid, pthr->policy, pthr->priority);
+ /* Wait for other RT threads to start up */
+ pthread_barrier_wait(&barrier);
+
+ for (i = 0; i < 10000; i++) {
+ if (i%100 == 0) {
+ printf("Thread %d loop %d pthread pol %d pri %d\n",\
+ tid, i, pthr->policy, pthr->priority);
+ fflush(NULL);
+ }
+ pthr->id++;
+ for (j = 0; j < 5000; j++) {
+ pthread_mutex_lock(&(pthr->mutex));
+ pthread_mutex_unlock(&(pthr->mutex));
+ }
+ }
+ pthread_mutex_unlock(&glob_mutex);
+ return NULL;
}
-void* func_rt(void* arg)
+void *func_rt(void *arg)
{
- struct thread* pthr = (struct thread* )arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
- exit(-1);
- }
-
- printf("Thread %d started running with prio %d\n", tid, pthr->priority);
- pthread_barrier_wait(&barrier);
- pthread_mutex_lock(&glob_mutex);
- printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
-
- /* we just use the mutex as something to slow things down */
- /* say who we are and then do nothing for a while. The aim
- * of this is to show that high priority threads make more
- * progress than lower priority threads..
- */
- for (i=0;i<1000;i++) {
- if (i%100 == 0) {
- printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
- fflush(NULL);
- }
- pthr->id++;
- for (j=0;j<5000;j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
- }
- pthread_mutex_unlock(&glob_mutex);
- return NULL;
+ struct thread *pthr = (struct thread *)arg;
+ int rc, i, j, tid = gettid();
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+
+ rc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (rc < 0) {
+ printf("Thread %d: Can't set affinity: %d %s\n", tid,\
+ rc, strerror(rc));
+ exit(-1);
+ }
+
+ printf("Thread %d started running with prio %d\n", tid, pthr->priority);
+ pthread_barrier_wait(&barrier);
+ pthread_mutex_lock(&glob_mutex);
+ printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
+ tid, pthr->policy, pthr->priority);
+
+ /* We just use the mutex as something to slow things down,
+ * say who we are and then do nothing for a while. The aim
+ * of this is to show that high priority threads make more
+ * progress than lower priority threads..
+ */
+ for (i = 0; i < 1000; i++) {
+ if (i%100 == 0) {
+ printf("Thread %d loop %d pthread pol %d pri %d\n",\
+ tid, i, pthr->policy, pthr->priority);
+ fflush(NULL);
+ }
+ pthr->id++;
+ for (j = 0; j < 5000; j++) {
+ pthread_mutex_lock(&(pthr->mutex));
+ pthread_mutex_unlock(&(pthr->mutex));
+ }
+ }
+ pthread_mutex_unlock(&glob_mutex);
+ return NULL;
}
-void* func_noise(void* arg)
+void *func_noise(void *arg)
{
- struct thread* pthr = (struct thread* )arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
- exit(-1);
- }
-
- printf("Noise Thread %d started running with prio %d\n", tid, pthr->priority);
- pthread_barrier_wait(&barrier);
-
- for (i=0;i<10000;i++) {
- if (i%100 == 0) {
- printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
- fflush(NULL);
- }
- pthr->id++;
- for (j=0;j<5000;j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
- }
- return NULL;
+ struct thread *pthr = (struct thread *)arg;
+ int rc, i, j, tid = gettid();
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+
+ rc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (rc < 0) {
+ printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+ strerror(rc));
+ exit(-1);
+ }
+
+ printf("Noise Thread %d started running with prio %d\n", tid,
+ pthr->priority);
+ pthread_barrier_wait(&barrier);
+
+ for (i = 0; i < 10000; i++) {
+ if (i%100 == 0) {
+ printf("Noise Thread %d loop %d pthread pol %d "\
+ "pri %d\n", tid, i, pthr->policy,\
+ pthr->priority);
+ fflush(NULL);
+ }
+ pthr->id++;
+ for (j = 0; j < 5000; j++) {
+ pthread_mutex_lock(&(pthr->mutex));
+ pthread_mutex_unlock(&(pthr->mutex));
+ }
+ }
+ return NULL;
}
/*
* Test pthread creation at different thread priorities.
*/
-int main(int argc, char* argv[]) {
- pthread_mutexattr_t mutexattr;
- int i, retc, protocol, nopi = 0;
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
- setup();
-
- rt_init("h",parse_args,argc,argv);
-
- if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
- printf("pthread_barrier_init failed: %s\n", strerror(retc));
- exit(retc);
- }
-
- retc = sched_setaffinity(0, sizeof(mask), &mask);
- if (retc < 0) {
- printf("Main Thread: Can't set affinity: %d %s\n", retc, strerror(retc));
- exit(-1);
- }
- for (i=0;i<argc;i++) {
- if (strcmp(argv[i],"nopi") == 0) nopi = 1;
- }
-
- printf("Start %s\n",argv[0]);
-
- if (!nopi) {
- if (pthread_mutexattr_init(&mutexattr) != 0) {
- printf("Failed to init mutexattr\n");
- }
- if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
- printf("Can't set protocol prio inherit\n");
- }
- if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
- printf("Can't get mutexattr protocol\n");
- } else {
- printf("protocol in mutexattr is %d\n", protocol);
- }
- if ((retc = pthread_mutex_init(&glob_mutex, &mutexattr)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
- }
-
- create_other_thread(func_nonrt,NULL);
- create_rr_thread(func_rt, NULL, 20);
- create_rr_thread(func_rt, NULL, 30);
- create_rr_thread(func_rt, NULL, 40);
- create_rr_thread(func_noise, NULL, 40);
-
- printf("Joining threads\n");
- join_threads();
- printf("Done\n");
- printf("Criteria:Low Priority Thread should Preempt Higher Priority Noise Thread\n");
-
- return 0;
+int main(int argc, char *argv[])
+{
+ pthread_mutexattr_t mutexattr;
+ int i, retc, protocol, nopi = 0;
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+ setup();
+
+ rt_init("h", parse_args, argc, argv);
+
+ retc = pthread_barrier_init(&barrier, NULL, 5);
+ if (retc) {
+ printf("pthread_barrier_init failed: %s\n", strerror(retc));
+ exit(retc);
+ }
+
+ retc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (retc < 0) {
+ printf("Main Thread: Can't set affinity: %d %s\n", retc,\
+ strerror(retc));
+ exit(-1);
+ }
+
+ for (i = 0; i < argc; i++) {
+ if (strcmp(argv[i], "nopi") == 0)
+ nopi = 1;
+ }
+
+ printf("Start %s\n", argv[0]);
+
+ if (!nopi) {
+ if (pthread_mutexattr_init(&mutexattr) != 0)
+ printf("Failed to init mutexattr\n");
+
+ if (pthread_mutexattr_setprotocol(&mutexattr,\
+ PTHREAD_PRIO_INHERIT) != 0)
+ printf("Can't set protocol prio inherit\n");
+
+ if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
+ printf("Can't get mutexattr protocol\n");
+ else
+ printf("protocol in mutexattr is %d\n", protocol);
+
+ retc = pthread_mutex_init(&glob_mutex, &mutexattr);
+ if (retc != 0)
+ printf("Failed to init mutex: %d\n", retc);
+ }
+
+ create_other_thread(func_nonrt, NULL);
+ create_rr_thread(func_rt, NULL, 20);
+ create_rr_thread(func_rt, NULL, 30);
+ create_rr_thread(func_rt, NULL, 40);
+ create_rr_thread(func_noise, NULL, 40);
+
+ printf("Joining threads\n");
+ join_threads();
+ printf("Done\n");
+ printf("Criteria:Low Priority Thread should Preempt Higher Priority "\
+ "Noise Thread\n");
+
+ return 0;
}
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 3/5] realtime: code cleanup on pi-test 2
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (2 preceding siblings ...)
2010-05-27 4:03 ` [LTP] [PATCH 2/5] realtime: code cleanup on pi-test 1 Gowrishankar
@ 2010-05-27 4:03 ` Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 4/5] realtime: code cleanup on pi-test 5 Gowrishankar
` (8 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:03 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
This patch cleans up the test so as to follow C coding style standards.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-2.c | 346 ++++++++++++++-------------
1 files changed, 182 insertions(+), 164 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index f824c94..8e29e16 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -30,6 +30,7 @@
*
*
* HISTORY
+ * 2010-04-22 Code cleanup by Gowrishankar
*
*
*****************************************************************************/
@@ -48,196 +49,213 @@ pthread_barrier_t barrier;
void usage(void)
{
- rt_help();
- printf("testpi-2 specific options:\n");
+ rt_help();
+ printf("testpi-2 specific options:\n");
}
int parse_args(int c, char *v)
{
- int handled = 1;
- switch (c) {
- case 'h':
- usage();
- exit(0);
- default:
- handled = 0;
- break;
- }
- return handled;
+ int handled = 1;
+ switch (c) {
+ case 'h':
+ usage();
+ exit(0);
+ default:
+ handled = 0;
+ break;
+ }
+ return handled;
}
int gettid(void)
{
- return syscall(__NR_gettid);
+ return syscall(__NR_gettid);
}
-typedef void* (*entrypoint_t)(void*);
+typedef void *(*entrypoint_t)(void *);
#define THREAD_STOP 1
pthread_mutex_t glob_mutex;
-void* func_lowrt(void* arg)
+void *func_lowrt(void *arg)
{
- struct thread* pthr = (struct thread* )arg ;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
- exit(-1);
- }
-
- printf("Thread %d started running with priority %d\n", tid, pthr->priority);
- pthread_mutex_lock(&glob_mutex);
- printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
- /* Wait for other RT threads to start up */
- pthread_barrier_wait(&barrier);
-
- for (i=0;i<10000;i++) {
- if (i%100 == 0) {
- printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
- fflush(NULL);
- }
- pthr->id++;
- for (j=0;j<5000;j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
- }
- pthread_mutex_unlock(&glob_mutex);
- return NULL;
+ struct thread *pthr = (struct thread *)arg;
+ int rc, i, j, tid = gettid();
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+
+ rc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (rc < 0) {
+ printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+ strerror(rc));
+ exit(-1);
+ }
+
+ printf("Thread %d started running with priority %d\n", tid,\
+ pthr->priority);
+ pthread_mutex_lock(&glob_mutex);
+ printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",\
+ tid, pthr->policy, pthr->priority);
+ /* Wait for other RT threads to start up */
+ pthread_barrier_wait(&barrier);
+
+ for (i = 0; i < 10000; i++) {
+ if (i%100 == 0) {
+ printf("Thread %d loop %d pthread pol %d pri %d\n",\
+ tid, i, pthr->policy, pthr->priority);
+ fflush(NULL);
+ }
+ pthr->id++;
+ for (j = 0; j < 5000; j++) {
+ pthread_mutex_lock(&(pthr->mutex));
+ pthread_mutex_unlock(&(pthr->mutex));
+ }
+ }
+ pthread_mutex_unlock(&glob_mutex);
+ return NULL;
}
-void* func_rt(void* arg)
+void *func_rt(void *arg)
{
- struct thread* pthr = (struct thread* )arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
- exit(-1);
- }
-
- printf("Thread %d started running with prio %d\n", tid, pthr->priority);
- pthread_barrier_wait(&barrier);
- pthread_mutex_lock(&glob_mutex);
- printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
-
- /* we just use the mutex as something to slow things down */
- /* say who we are and then do nothing for a while. The aim
- * of this is to show that high priority threads make more
- * progress than lower priority threads..
- */
- for (i=0;i<1000;i++) {
- if (i%100 == 0) {
- printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
- fflush(NULL);
- }
- pthr->id++;
- for (j=0;j<5000;j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
- }
- pthread_mutex_unlock(&glob_mutex);
- return NULL;
+ struct thread *pthr = (struct thread *)arg;
+ int rc, i, j, tid = gettid();
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+
+ rc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (rc < 0) {
+ printf("Thread %d: Can't set affinity: %d %s\n", tid,\
+ rc, strerror(rc));
+ exit(-1);
+ }
+
+ printf("Thread %d started running with prio %d\n", tid, pthr->priority);
+ pthread_barrier_wait(&barrier);
+ pthread_mutex_lock(&glob_mutex);
+ printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",\
+ tid, pthr->policy, pthr->priority);
+
+ /* We just use the mutex as something to slow things down,
+ * say who we are and then do nothing for a while. The aim
+ * of this is to show that high priority threads make more
+ * progress than lower priority threads..
+ */
+ for (i = 0; i < 1000; i++) {
+ if (i%100 == 0) {
+ printf("Thread %d loop %d pthread pol %d pri %d\n",\
+ tid, i, pthr->policy, pthr->priority);
+ fflush(NULL);
+ }
+ pthr->id++;
+ for (j = 0; j < 5000; j++) {
+ pthread_mutex_lock(&(pthr->mutex));
+ pthread_mutex_unlock(&(pthr->mutex));
+ }
+ }
+ pthread_mutex_unlock(&glob_mutex);
+ return NULL;
}
-void* func_noise(void* arg)
+void *func_noise(void *arg)
{
- struct thread* pthr = (struct thread* )arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
- exit(-1);
- }
-
- printf("Noise Thread %d started running with prio %d\n", tid, pthr->priority);
- pthread_barrier_wait(&barrier);
-
- for (i=0;i<10000;i++) {
- if (i%100 == 0) {
- printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
- fflush(NULL);
- }
- pthr->id++;
- for (j=0;j<5000;j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
- }
- return NULL;
+ struct thread *pthr = (struct thread *)arg;
+ int rc, i, j, tid = gettid();
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+
+ rc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (rc < 0) {
+ printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+ strerror(rc));
+ exit(-1);
+ }
+
+ printf("Noise Thread %d started running with prio %d\n", tid,\
+ pthr->priority);
+ pthread_barrier_wait(&barrier);
+
+ for (i = 0; i < 10000; i++) {
+ if (i%100 == 0) {
+ printf("Noise Thread %d loop %d pthread pol %d "\
+ "pri %d\n", tid, i, pthr->policy,\
+ pthr->priority);
+ fflush(NULL);
+ }
+ pthr->id++;
+ for (j = 0; j < 5000; j++) {
+ pthread_mutex_lock(&(pthr->mutex));
+ pthread_mutex_unlock(&(pthr->mutex));
+ }
+ }
+ return NULL;
}
/*
* Test pthread creation at different thread priorities.
*/
-int main(int argc, char* argv[]) {
- pthread_mutexattr_t mutexattr;
- int i, retc, protocol, nopi = 0;
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
- setup();
- rt_init("h",parse_args,argc,argv);
-
- if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
- printf("pthread_barrier_init failed: %s\n", strerror(retc));
- exit(retc);
- }
-
- retc = sched_setaffinity(0, sizeof(mask), &mask);
- if (retc < 0) {
- printf("Main Thread: Can't set affinity: %d %s\n", retc, strerror(retc));
- exit(-1);
- }
-
- for (i=0;i<argc;i++) {
- if (strcmp(argv[i],"nopi") == 0) nopi = 1;
- }
-
- printf("Start %s\n",argv[0]);
-
- if (!nopi) {
- if (pthread_mutexattr_init(&mutexattr) != 0) {
- printf("Failed to init mutexattr\n");
- };
- if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
- printf("Can't set protocol prio inherit\n");
- }
- if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
- printf("Can't get mutexattr protocol\n");
- } else {
- printf("protocol in mutexattr is %d\n", protocol);
- }
- if ((retc = pthread_mutex_init(&glob_mutex, &mutexattr)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
- }
-
- create_rr_thread(func_lowrt, NULL, 10);
- create_rr_thread(func_rt, NULL, 20);
- create_fifo_thread(func_rt, NULL, 30);
- create_fifo_thread(func_rt, NULL, 40);
- create_rr_thread(func_noise, NULL, 40);
-
- printf("Joining threads\n");
- join_threads();
- printf("Done\n");
- printf("Criteria: Low Priority Thread and High Priority Thread should prempt each other multiple times\n");
- return 0;
+int main(int argc, char *argv[])
+{
+ pthread_mutexattr_t mutexattr;
+ int i, retc, protocol, nopi = 0;
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(0, &mask);
+ setup();
+ rt_init("h", parse_args, argc, argv);
+
+ retc = pthread_barrier_init(&barrier, NULL, 5);
+ if (retc) {
+ printf("pthread_barrier_init failed: %s\n", strerror(retc));
+ exit(retc);
+ }
+
+ retc = sched_setaffinity(0, sizeof(mask), &mask);
+ if (retc < 0) {
+ printf("Main Thread: Can't set affinity: %d %s\n", retc,\
+ strerror(retc));
+ exit(-1);
+ }
+
+ for (i = 0; i < argc; i++) {
+ if (strcmp(argv[i], "nopi") == 0)
+ nopi = 1;
+ }
+
+ printf("Start %s\n", argv[0]);
+
+ if (!nopi) {
+ if (pthread_mutexattr_init(&mutexattr) != 0)
+ printf("Failed to init mutexattr\n");
+
+ if (pthread_mutexattr_setprotocol(&mutexattr,\
+ PTHREAD_PRIO_INHERIT) != 0)
+ printf("Can't set protocol prio inherit\n");
+
+ if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
+ printf("Can't get mutexattr protocol\n");
+ else
+ printf("protocol in mutexattr is %d\n", protocol);
+
+ retc = pthread_mutex_init(&glob_mutex, &mutexattr);
+ if (retc != 0)
+ printf("Failed to init mutex: %d\n", retc);
+ }
+
+ create_rr_thread(func_lowrt, NULL, 10);
+ create_rr_thread(func_rt, NULL, 20);
+ create_fifo_thread(func_rt, NULL, 30);
+ create_fifo_thread(func_rt, NULL, 40);
+ create_rr_thread(func_noise, NULL, 40);
+
+ printf("Joining threads\n");
+ join_threads();
+ printf("Done\n");
+ printf("Criteria: Low Priority Thread and High Priority Thread "\
+ "should prempt each other multiple times\n");
+ return 0;
}
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/5] realtime: code cleanup on pi-test 5
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (3 preceding siblings ...)
2010-05-27 4:03 ` [LTP] [PATCH 3/5] realtime: code cleanup on pi-test 2 Gowrishankar
@ 2010-05-27 4:03 ` Gowrishankar
2010-05-27 4:03 ` [LTP] [PATCH 5/5] realtime: code cleanup on pi-test 6 Gowrishankar
` (7 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:03 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
This patch cleans up the test so as to follow C coding style standards.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-5.c | 76 ++++++++++++++-------------
1 files changed, 39 insertions(+), 37 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-5.c b/testcases/realtime/func/pi-tests/testpi-5.c
index faf3d8d..b3ea6ef 100644
--- a/testcases/realtime/func/pi-tests/testpi-5.c
+++ b/testcases/realtime/func/pi-tests/testpi-5.c
@@ -30,6 +30,7 @@
*
*
* HISTORY
+ * 2010-04-22 Code cleanup by Gowrishankar
*
*
*****************************************************************************/
@@ -39,54 +40,55 @@
#include <string.h>
#include <unistd.h>
#include <librttest.h>
-pthread_mutex_t child_mutex;
+pthread_mutex_t child_mutex;
-void* child_thread (void* arg)
+void *child_thread(void *arg)
{
- int ret;
+ int ret;
- ret = pthread_mutex_lock(&child_mutex);
- if (ret != 0)
- printf("child thread: Failed to lock child_mutex: %d\n", ret);
- else
- printf("child_thread: got lock\n");
+ ret = pthread_mutex_lock(&child_mutex);
+ if (ret != 0)
+ printf("child thread: Failed to lock child_mutex: %d\n", ret);
+ else
+ printf("child_thread: got lock\n");
- sleep(2);
+ sleep(2);
- printf("child_thread: Trying to get lock 2nd time\n");
- ret = pthread_mutex_lock(&child_mutex);
- if (ret != 0)
- printf("child thread: Failed to lock child_mutex: %d\n", ret);
- else
- printf("child_thread: got lock 2nd time !!\n");
+ printf("child_thread: Trying to get lock 2nd time\n");
+ ret = pthread_mutex_lock(&child_mutex);
+ if (ret != 0)
+ printf("child thread: Failed to lock child_mutex: %d\n", ret);
+ else
+ printf("child_thread: got lock 2nd time !!\n");
- return NULL;
+ return NULL;
}
-int do_test(int argc, char ** argv)
+int do_test(int argc, char **argv)
{
- pthread_mutexattr_t mutexattr;
- int retc, protocol;
+ pthread_mutexattr_t mutexattr;
+ int retc, protocol;
- if (pthread_mutexattr_init(&mutexattr) != 0) {
- printf("Failed to init mutexattr\n");
- };
- if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
- printf("Can't set protocol prio inherit\n");
- }
- if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
- printf("Can't get mutexattr protocol\n");
- } else {
- printf("protocol in mutexattr is %d\n", protocol);
- }
- if ((retc = pthread_mutex_init(&child_mutex, &mutexattr)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
+ if (pthread_mutexattr_init(&mutexattr) != 0)
+ printf("Failed to init mutexattr\n");
- create_other_thread(child_thread, NULL);
- join_threads();
-
- return 0;
+ if (pthread_mutexattr_setprotocol(&mutexattr,\
+ PTHREAD_PRIO_INHERIT) != 0)
+ printf("Can't set protocol prio inherit\n");
+
+ if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
+ printf("Can't get mutexattr protocol\n");
+ else
+ printf("protocol in mutexattr is %d\n", protocol);
+
+ retc = pthread_mutex_init(&child_mutex, &mutexattr);
+ if (retc != 0)
+ printf("Failed to init mutex: %d\n", retc);
+
+ create_other_thread(child_thread, NULL);
+ join_threads();
+
+ return 0;
}
#include "test-skeleton.c"
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 5/5] realtime: code cleanup on pi-test 6
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (4 preceding siblings ...)
2010-05-27 4:03 ` [LTP] [PATCH 4/5] realtime: code cleanup on pi-test 5 Gowrishankar
@ 2010-05-27 4:03 ` Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests Gowrishankar
` (6 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:03 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
This patch cleans up the test so as to follow C coding style standards.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-6.c | 72 ++++++++++++++-------------
1 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-6.c b/testcases/realtime/func/pi-tests/testpi-6.c
index 560f45f..523ba13 100644
--- a/testcases/realtime/func/pi-tests/testpi-6.c
+++ b/testcases/realtime/func/pi-tests/testpi-6.c
@@ -30,6 +30,7 @@
*
*
* HISTORY
+ * 2010-04-22 Code cleanup by Gowrishankar
*
*
*****************************************************************************/
@@ -39,54 +40,55 @@
#include <string.h>
#include <unistd.h>
#include <librttest.h>
-pthread_mutex_t child_mutex;
+pthread_mutex_t child_mutex;
-void* child_thread (void* arg)
+void *child_thread(void *arg)
{
- int ret;
+ int ret;
- ret = pthread_mutex_lock(&child_mutex);
- if (ret != 0)
- printf("child thread: Failed to lock child_mutex: %d\n", ret);
- else
- printf("child_thread: got lock\n");
+ ret = pthread_mutex_lock(&child_mutex);
+ if (ret != 0)
+ printf("child thread: Failed to lock child_mutex: %d\n", ret);
+ else
+ printf("child_thread: got lock\n");
- sleep(2);
+ sleep(2);
- printf("child_thread: Trying to get lock 2nd time\n");
- ret = pthread_mutex_lock(&child_mutex);
- if (ret != 0)
- printf("child thread: Failed to lock child_mutex: %d\n", ret);
- else
- printf("child_thread: got lock 2nd time !!\n");
+ printf("child_thread: Trying to get lock 2nd time\n");
+ ret = pthread_mutex_lock(&child_mutex);
+ if (ret != 0)
+ printf("child thread: Failed to lock child_mutex: %d\n", ret);
+ else
+ printf("child_thread: got lock 2nd time !!\n");
- return NULL;
+ return NULL;
}
int do_test(int argc, char **argv)
{
- pthread_mutexattr_t mutexattr;
- int retc, robust;
+ pthread_mutexattr_t mutexattr;
+ int retc, robust;
- if (pthread_mutexattr_init(&mutexattr) != 0) {
- printf("Failed to init mutexattr\n");
- };
- if (pthread_mutexattr_setrobust_np(&mutexattr, PTHREAD_MUTEX_ROBUST_NP) != 0) {
- printf("Can't set robust mutex\n");
- }
- if (pthread_mutexattr_getrobust_np(&mutexattr, &robust) != 0) {
- printf("Can't get mutexattr protocol\n");
- } else {
- printf("robust in mutexattr is %d\n", robust);
- }
- if ((retc = pthread_mutex_init(&child_mutex, &mutexattr)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
+ if (pthread_mutexattr_init(&mutexattr) != 0)
+ printf("Failed to init mutexattr\n");
- create_other_thread(child_thread, NULL);
- join_threads();
+ if (pthread_mutexattr_setrobust_np(&mutexattr,\
+ PTHREAD_MUTEX_ROBUST_NP) != 0)
+ printf("Can't set robust mutex\n");
- return 0;
+ if (pthread_mutexattr_getrobust_np(&mutexattr, &robust) != 0)
+ printf("Can't get mutexattr protocol\n");
+ else
+ printf("robust in mutexattr is %d\n", robust);
+
+ retc = pthread_mutex_init(&child_mutex, &mutexattr);
+ if (retc != 0)
+ printf("Failed to init mutex: %d\n", retc);
+
+ create_other_thread(child_thread, NULL);
+ join_threads();
+
+ return 0;
}
#include "test-skeleton.c"
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (5 preceding siblings ...)
2010-05-27 4:03 ` [LTP] [PATCH 5/5] realtime: code cleanup on pi-test 6 Gowrishankar
@ 2010-05-27 4:11 ` 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
` (5 subsequent siblings)
12 siblings, 1 reply; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project
Following set of patches applies functional changes in pi-tests
for better reliability in recent kernels and their order is:
[PATCH 1/6] realtime: reuse init_pi_mutex from librttest
[PATCH 2/6] realtime: add test descriptions
[PATCH 3/6] realtime: threads need not set cpu affinity while main does
[PATCH 4/6] realtime: use busy_work_ms from librttest to burn cpu cycles
[PATCH 5/6] realtime: remove thread_stop which is not used anywhere
[PATCH 6/6] realtime: synchronization fixes for high priority noise thread
All need to be applied in their order on top or code clean up patch series
sent previously.
Thanks,
Gowri
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/6] realtime: reuse init_pi_mutex from librttest
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (6 preceding siblings ...)
2010-05-27 4:11 ` [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests Gowrishankar
@ 2010-05-27 4:11 ` Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 2/6] realtime: add test descriptions Gowrishankar
` (4 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
testpi-1 and testpi-2 are initializing mutex step by step which can be done
by reusing the init_pi_mutex() funtion available in librttest.
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 | 22 +++-------------------
testcases/realtime/func/pi-tests/testpi-2.c | 22 +++-------------------
2 files changed, 6 insertions(+), 38 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index b503c0c..dc3c30b 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -199,8 +199,7 @@ void *func_noise(void *arg)
*/
int main(int argc, char *argv[])
{
- pthread_mutexattr_t mutexattr;
- int i, retc, protocol, nopi = 0;
+ int i, retc, nopi = 0;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
@@ -228,23 +227,8 @@ int main(int argc, char *argv[])
printf("Start %s\n", argv[0]);
- if (!nopi) {
- if (pthread_mutexattr_init(&mutexattr) != 0)
- printf("Failed to init mutexattr\n");
-
- if (pthread_mutexattr_setprotocol(&mutexattr,\
- PTHREAD_PRIO_INHERIT) != 0)
- printf("Can't set protocol prio inherit\n");
-
- if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
- printf("Can't get mutexattr protocol\n");
- else
- printf("protocol in mutexattr is %d\n", protocol);
-
- retc = pthread_mutex_init(&glob_mutex, &mutexattr);
- if (retc != 0)
- printf("Failed to init mutex: %d\n", retc);
- }
+ if (!nopi)
+ init_pi_mutex(&glob_mutex);
create_other_thread(func_nonrt, NULL);
create_rr_thread(func_rt, NULL, 20);
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index 8e29e16..4220aba 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -200,8 +200,7 @@ void *func_noise(void *arg)
*/
int main(int argc, char *argv[])
{
- pthread_mutexattr_t mutexattr;
- int i, retc, protocol, nopi = 0;
+ int i, retc, nopi = 0;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
@@ -228,23 +227,8 @@ int main(int argc, char *argv[])
printf("Start %s\n", argv[0]);
- if (!nopi) {
- if (pthread_mutexattr_init(&mutexattr) != 0)
- printf("Failed to init mutexattr\n");
-
- if (pthread_mutexattr_setprotocol(&mutexattr,\
- PTHREAD_PRIO_INHERIT) != 0)
- printf("Can't set protocol prio inherit\n");
-
- if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
- printf("Can't get mutexattr protocol\n");
- else
- printf("protocol in mutexattr is %d\n", protocol);
-
- retc = pthread_mutex_init(&glob_mutex, &mutexattr);
- if (retc != 0)
- printf("Failed to init mutex: %d\n", retc);
- }
+ if (!nopi)
+ init_pi_mutex(&glob_mutex);
create_rr_thread(func_lowrt, NULL, 10);
create_rr_thread(func_rt, NULL, 20);
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/6] realtime: add test descriptions
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (7 preceding siblings ...)
2010-05-27 4:11 ` [LTP] [PATCH 1/6] realtime: reuse init_pi_mutex from librttest Gowrishankar
@ 2010-05-27 4:11 ` Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 3/6] realtime: threads need not set cpu affinity while main does Gowrishankar
` (3 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
This patch adds the descriptions for the tests 1,2,5,6.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-1.c | 4 ++--
testcases/realtime/func/pi-tests/testpi-2.c | 5 +++--
testcases/realtime/func/pi-tests/testpi-5.c | 4 ++--
testcases/realtime/func/pi-tests/testpi-6.c | 4 ++--
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index dc3c30b..35df387 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -20,8 +20,8 @@
* testpi-1.c
*
* DESCRIPTION
- *
- *
+ * This testcase verifies if the low priority SCHED_OTHER thread can preempt
+ * the high priority SCHED_RR thread via priority inheritance.
*
* USAGE:
* Use run_auto.sh script in current directory to build and run test.
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index 4220aba..00f632b 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -20,8 +20,9 @@
* testpi-2.c
*
* DESCRIPTION
- *
- *
+ * This testcase verifies if the low priority SCHED_RR thread can preempt
+ * the high priority SCHED_RR thread multiple times via priority
+ * inheritance.
*
* USAGE:
* Use run_auto.sh script in current directory to build and run test.
diff --git a/testcases/realtime/func/pi-tests/testpi-5.c b/testcases/realtime/func/pi-tests/testpi-5.c
index b3ea6ef..1330dfd 100644
--- a/testcases/realtime/func/pi-tests/testpi-5.c
+++ b/testcases/realtime/func/pi-tests/testpi-5.c
@@ -20,8 +20,8 @@
* testpi-5.c
*
* DESCRIPTION
- *
- *
+ * This testcase verifies if a thread can lock the priority inheritance
+ * mutex multiple times.
*
* USAGE:
* Use run_auto.sh script in current directory to build and run test.
diff --git a/testcases/realtime/func/pi-tests/testpi-6.c b/testcases/realtime/func/pi-tests/testpi-6.c
index 523ba13..19c06ea 100644
--- a/testcases/realtime/func/pi-tests/testpi-6.c
+++ b/testcases/realtime/func/pi-tests/testpi-6.c
@@ -20,8 +20,8 @@
* testpi-6.c
*
* DESCRIPTION
- *
- *
+ * This testcase verifies if a thread can lock the robust mutex multiple
+ * times.
*
* USAGE:
* Use run_auto.sh script in current directory to build and run test.
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 3/6] realtime: threads need not set cpu affinity while main does
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (8 preceding siblings ...)
2010-05-27 4:11 ` [LTP] [PATCH 2/6] realtime: add test descriptions Gowrishankar
@ 2010-05-27 4:11 ` Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 4/6] realtime: use busy_work_ms from librttest to burn cpu cycles Gowrishankar
` (2 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
Since main() sets the cpu affinity, it is not necessary for the
spawned threads to do so, as the threads inherit the cpu affinity.
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 | 36 ++------------------------
testcases/realtime/func/pi-tests/testpi-2.c | 36 ++------------------------
2 files changed, 6 insertions(+), 66 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index 35df387..25541d7 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -81,17 +81,7 @@ pthread_mutex_t glob_mutex;
void *func_nonrt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
- strerror(rc));
- exit(-1);
- }
+ int i, j, tid = gettid();
printf("Thread %d started running with priority %d\n", tid,\
pthr->priority);
@@ -120,17 +110,7 @@ void *func_nonrt(void *arg)
void *func_rt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid,\
- rc, strerror(rc));
- exit(-1);
- }
+ int i, j, tid = gettid();
printf("Thread %d started running with prio %d\n", tid, pthr->priority);
pthread_barrier_wait(&barrier);
@@ -162,17 +142,7 @@ void *func_rt(void *arg)
void *func_noise(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
- strerror(rc));
- exit(-1);
- }
+ int i, j, tid = gettid();
printf("Noise Thread %d started running with prio %d\n", tid,
pthr->priority);
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index 00f632b..eb00129 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -83,17 +83,7 @@ pthread_mutex_t glob_mutex;
void *func_lowrt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
- strerror(rc));
- exit(-1);
- }
+ int i, j, tid = gettid();
printf("Thread %d started running with priority %d\n", tid,\
pthr->priority);
@@ -122,17 +112,7 @@ void *func_lowrt(void *arg)
void *func_rt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid,\
- rc, strerror(rc));
- exit(-1);
- }
+ int i, j, tid = gettid();
printf("Thread %d started running with prio %d\n", tid, pthr->priority);
pthread_barrier_wait(&barrier);
@@ -164,17 +144,7 @@ void *func_rt(void *arg)
void *func_noise(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int rc, i, j, tid = gettid();
- cpu_set_t mask;
- CPU_ZERO(&mask);
- CPU_SET(0, &mask);
-
- rc = sched_setaffinity(0, sizeof(mask), &mask);
- if (rc < 0) {
- printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
- strerror(rc));
- exit(-1);
- }
+ int i, j, tid = gettid();
printf("Noise Thread %d started running with prio %d\n", tid,\
pthr->priority);
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/6] realtime: use busy_work_ms from librttest to burn cpu cycles
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (9 preceding siblings ...)
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 ` 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 ` [LTP] [PATCH 6/6] realtime: synchronization fixes for high priority noise thread Gowrishankar
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
Instead of lock/unlock of mutex to burn cpu cycles, we can use busy_work_ms
from librttest which is more explicit (burn cycles, not provide some
synchronization).
Also this patch removes the id increment since it is not used.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-1.c | 24 ++++++------------------
testcases/realtime/func/pi-tests/testpi-2.c | 24 ++++++------------------
2 files changed, 12 insertions(+), 36 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index 25541d7..71b01ec 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -81,7 +81,7 @@ pthread_mutex_t glob_mutex;
void *func_nonrt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int i, j, tid = gettid();
+ int i, tid = gettid();
printf("Thread %d started running with priority %d\n", tid,\
pthr->priority);
@@ -97,11 +97,7 @@ void *func_nonrt(void *arg)
tid, i, pthr->policy, pthr->priority);
fflush(NULL);
}
- pthr->id++;
- for (j = 0; j < 5000; j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
+ busy_work_ms(1);
}
pthread_mutex_unlock(&glob_mutex);
return NULL;
@@ -110,7 +106,7 @@ void *func_nonrt(void *arg)
void *func_rt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int i, j, tid = gettid();
+ int i, tid = gettid();
printf("Thread %d started running with prio %d\n", tid, pthr->priority);
pthread_barrier_wait(&barrier);
@@ -129,11 +125,7 @@ void *func_rt(void *arg)
tid, i, pthr->policy, pthr->priority);
fflush(NULL);
}
- pthr->id++;
- for (j = 0; j < 5000; j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
+ busy_work_ms(1);
}
pthread_mutex_unlock(&glob_mutex);
return NULL;
@@ -142,7 +134,7 @@ void *func_rt(void *arg)
void *func_noise(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int i, j, tid = gettid();
+ int i, tid = gettid();
printf("Noise Thread %d started running with prio %d\n", tid,
pthr->priority);
@@ -155,11 +147,7 @@ void *func_noise(void *arg)
pthr->priority);
fflush(NULL);
}
- pthr->id++;
- for (j = 0; j < 5000; j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
+ busy_work_ms(1);
}
return NULL;
}
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index eb00129..68dde44 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -83,7 +83,7 @@ pthread_mutex_t glob_mutex;
void *func_lowrt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int i, j, tid = gettid();
+ int i, tid = gettid();
printf("Thread %d started running with priority %d\n", tid,\
pthr->priority);
@@ -99,11 +99,7 @@ void *func_lowrt(void *arg)
tid, i, pthr->policy, pthr->priority);
fflush(NULL);
}
- pthr->id++;
- for (j = 0; j < 5000; j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
+ busy_work_ms(1);
}
pthread_mutex_unlock(&glob_mutex);
return NULL;
@@ -112,7 +108,7 @@ void *func_lowrt(void *arg)
void *func_rt(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int i, j, tid = gettid();
+ int i, tid = gettid();
printf("Thread %d started running with prio %d\n", tid, pthr->priority);
pthread_barrier_wait(&barrier);
@@ -131,11 +127,7 @@ void *func_rt(void *arg)
tid, i, pthr->policy, pthr->priority);
fflush(NULL);
}
- pthr->id++;
- for (j = 0; j < 5000; j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
+ busy_work_ms(1);
}
pthread_mutex_unlock(&glob_mutex);
return NULL;
@@ -144,7 +136,7 @@ void *func_rt(void *arg)
void *func_noise(void *arg)
{
struct thread *pthr = (struct thread *)arg;
- int i, j, tid = gettid();
+ int i, tid = gettid();
printf("Noise Thread %d started running with prio %d\n", tid,\
pthr->priority);
@@ -157,11 +149,7 @@ void *func_noise(void *arg)
pthr->priority);
fflush(NULL);
}
- pthr->id++;
- for (j = 0; j < 5000; j++) {
- pthread_mutex_lock(&(pthr->mutex));
- pthread_mutex_unlock(&(pthr->mutex));
- }
+ busy_work_ms(1);
}
return NULL;
}
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 5/6] realtime: remove thread_stop which is not used anywhere
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (10 preceding siblings ...)
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 ` Gowrishankar
2010-05-27 4:11 ` [LTP] [PATCH 6/6] realtime: synchronization fixes for high priority noise thread Gowrishankar
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
Tests testpi-1 and testpi-2 defines THREAD_STOP which is not used anywhere in
the program.
Signed-off-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Tested-by: Gowrishankar <gowrishankar.m@in.ibm.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
---
testcases/realtime/func/pi-tests/testpi-1.c | 3 ---
testcases/realtime/func/pi-tests/testpi-2.c | 3 ---
2 files changed, 0 insertions(+), 6 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c
index 71b01ec..3e05e56 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -73,9 +73,6 @@ int gettid(void)
}
typedef void *(*entrypoint_t)(void *);
-
-#define THREAD_STOP 1
-
pthread_mutex_t glob_mutex;
void *func_nonrt(void *arg)
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c
index 68dde44..f0e86ea 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -75,9 +75,6 @@ int gettid(void)
}
typedef void *(*entrypoint_t)(void *);
-
-#define THREAD_STOP 1
-
pthread_mutex_t glob_mutex;
void *func_lowrt(void *arg)
--
1.7.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 6/6] realtime: synchronization fixes for high priority noise thread
[not found] <Gowrishankar <gomuthuk@linux.vnet.ibm.com>
` (11 preceding siblings ...)
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
12 siblings, 0 replies; 15+ messages in thread
From: Gowrishankar @ 2010-05-27 4:11 UTC (permalink / raw)
To: Linux Test Project; +Cc: gowrishankar
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
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests
2010-05-27 4:11 ` [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests Gowrishankar
@ 2010-05-28 7:31 ` Subrata Modak
0 siblings, 0 replies; 15+ messages in thread
From: Subrata Modak @ 2010-05-28 7:31 UTC (permalink / raw)
To: Gowrishankar; +Cc: Linux Test Project
On Thu, 2010-05-27 at 09:41 +0530, Gowrishankar wrote:
> Following set of patches applies functional changes in pi-tests
> for better reliability in recent kernels and their order is:
>
> [PATCH 1/6] realtime: reuse init_pi_mutex from librttest
> [PATCH 2/6] realtime: add test descriptions
> [PATCH 3/6] realtime: threads need not set cpu affinity while main does
> [PATCH 4/6] realtime: use busy_work_ms from librttest to burn cpu cycles
> [PATCH 5/6] realtime: remove thread_stop which is not used anywhere
> [PATCH 6/6] realtime: synchronization fixes for high priority noise thread
>
> All need to be applied in their order on top or code clean up patch series
> sent previously.
Thanks.
Regards--
Subrata
>
> Thanks,
> Gowri
>
>
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 0/5] realtime: code cleanup on pi-tests to adapt C coding standard
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
0 siblings, 0 replies; 15+ messages in thread
From: Subrata Modak @ 2010-05-28 7:32 UTC (permalink / raw)
To: Gowrishankar; +Cc: Linux Test Project
On Thu, 2010-05-27 at 09:33 +0530, Gowrishankar wrote:
> Following bulk of patches applies the coding style in pi-tests to follow
> the C coding standard. All are tested and they go in order:
>
> [PATCH 1/5] realtime: code cleanup on pi-test 0
> [PATCH 2/5] realtime: code cleanup on pi-test 1
> [PATCH 3/5] realtime: code cleanup on pi-test 2
> [PATCH 4/5] realtime: code cleanup on pi-test 5
> [PATCH 5/5] realtime: code cleanup on pi-test 6
Thanks. All checked in for this series.
Regards--
Subrata
>
> Thanks,
> Gowri
>
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2010-05-29 18:23 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 ` [LTP] [PATCH 6/6] realtime: synchronization fixes for high priority noise thread Gowrishankar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox