All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4
@ 2010-07-02  6:25 Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4 Gowrishankar
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 UTC (permalink / raw)
  To: Linux Test Project

Following set of patches applies code cleanup and functional changes
in LTP realtime pi-test testpi-4. This test was not patched earlier
when other pi-tests were fixed, with the intension of removing it
from the suite due to similarity with testpi-1. But we decided to
keep this test due to dynamically created global mutex lock.

Order of applying patch is:

[PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4
[PATCH 2/7] realtime/testpi-4: reuse init_pi_mutex from librttest
[PATCH 3/7] realtime/testpi-4: add test description
[PATCH 4/7] realtime/testpi-4: threads need not set cpu affinity while main does
[PATCH 5/7] realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles
[PATCH 6/7] realtime/testpi-4: remove thread_stop which is not used anywhere
[PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread

Thanks,
Gowri


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 2/7] realtime/testpi-4: reuse init_pi_mutex from librttest Gowrishankar
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 UTC (permalink / raw)
  To: Linux Test Project; +Cc: gowrishankar

From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>

This patch cleans up the testpi-4 so as to follow the
C coding style standards.

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-4.c |  356 ++++++++++++++-------------
 1 files changed, 186 insertions(+), 170 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index 1756588..bde3ded 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.c
@@ -49,201 +49,217 @@ pthread_barrier_t barrier;
 
 void usage(void)
 {
-        rt_help();
-        printf("testpi-4 specific options:\n");
+	rt_help();
+	printf("testpi-4 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_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);
-  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);
+	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 started running with prio %d\n", 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 started running with prio %d\n",
+		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]);
-
-  glob_mutex = malloc(sizeof(pthread_mutex_t));
-  if (glob_mutex == NULL) {
-     printf("Malloc failed\n");
-     exit(errno);
-  }
-
-  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");
-
-  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]);
+
+	glob_mutex = malloc(sizeof(pthread_mutex_t));
+	if (glob_mutex == NULL) {
+		printf("Malloc failed\n");
+		exit(errno);
+	}
+
+	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");
+
+	return 0;
 }
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/7] realtime/testpi-4: reuse init_pi_mutex from librttest
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4 Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 3/7] realtime/testpi-4: add test description Gowrishankar
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 UTC (permalink / raw)
  To: Linux Test Project; +Cc: gowrishankar

From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>

testpi-4 is 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-4.c |   22 +++-------------------
 1 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index bde3ded..53b47a8 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.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);
@@ -233,23 +232,8 @@ int main(int argc, char *argv[])
 		exit(errno);
 	}
 
-	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);
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 3/7] realtime/testpi-4: add test description
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4 Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 2/7] realtime/testpi-4: reuse init_pi_mutex from librttest Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 4/7] realtime/testpi-4: threads need not set cpu affinity while main does Gowrishankar
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 UTC (permalink / raw)
  To: Linux Test Project; +Cc: gowrishankar

From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>

This patch adds the description to the test testpi-4.

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-4.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index 53b47a8..6a90771 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.c
@@ -20,8 +20,8 @@
  *      testpi-4.c
  *
  * DESCRIPTION
- *
- *
+ *     This testcase verifies that the SCHED_OTHER thread can preempt
+ *     the SCHED_RR thread via priority inheritance.
  *
  * USAGE:
  *      Use run_auto.sh script in current directory to build and run test.
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 4/7] realtime/testpi-4: threads need not set cpu affinity while main does
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
                   ` (2 preceding siblings ...)
  2010-07-02  6:25 ` [LTP] [PATCH 3/7] realtime/testpi-4: add test description Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 5/7] realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles Gowrishankar
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 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-4.c |   36 ++------------------------
 1 files changed, 3 insertions(+), 33 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index 6a90771..0960c91 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.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);
@@ -119,17 +109,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);
@@ -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 started running with prio %d\n",
 		pthr->priority);
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 5/7] realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
                   ` (3 preceding siblings ...)
  2010-07-02  6:25 ` [LTP] [PATCH 4/7] realtime/testpi-4: threads need not set cpu affinity while main does Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 6/7] realtime/testpi-4: remove thread_stop which is not used anywhere Gowrishankar
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 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: Darren Hart <dvhltc@us.ibm.com>
---
 testcases/realtime/func/pi-tests/testpi-4.c |   24 ++++++------------------
 1 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index 0960c91..5a39701 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.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);
@@ -96,11 +96,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;
@@ -109,7 +105,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);
@@ -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 started running with prio %d\n",
 		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;
 }
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 6/7] realtime/testpi-4: remove thread_stop which is not used anywhere
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
                   ` (4 preceding siblings ...)
  2010-07-02  6:25 ` [LTP] [PATCH 5/7] realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-02  6:25 ` [LTP] [PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread Gowrishankar
  2010-07-03 18:00 ` [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Subrata Modak
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 UTC (permalink / raw)
  To: Linux Test Project; +Cc: gowrishankar

From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>

testpi-4 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: Darren Hart <dvhltc@us.ibm.com>
---
 testcases/realtime/func/pi-tests/testpi-4.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index 5a39701..3bd5d77 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.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)
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
                   ` (5 preceding siblings ...)
  2010-07-02  6:25 ` [LTP] [PATCH 6/7] realtime/testpi-4: remove thread_stop which is not used anywhere Gowrishankar
@ 2010-07-02  6:25 ` Gowrishankar
  2010-07-03 18:00 ` [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Subrata Modak
  7 siblings, 0 replies; 9+ messages in thread
From: Gowrishankar @ 2010-07-02  6:25 UTC (permalink / raw)
  To: Linux Test Project; +Cc: gowrishankar

From: gowrishankar <gowrishankar.m@linux.vnet.ibm.com>

In a scenario where a thread other than high priority noise thread is
scheduled after the barrier, a priority inversion will not occur, defeating
the purpose of test. We need to tightly synchronize the threads so that the
noise thread always begins the test and gets preempted by the low prio thread
through the PI logic.

This change is applied on testpi-4.
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-4.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c
index 3bd5d77..63f8430 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.c
@@ -30,7 +30,9 @@
  *
  *
  * HISTORY
- *
+ *      2010-06-29 Thread synchronization changes by using
+ *                 conditional variables by Gowrishankar.
+ *                 by Gowrishankar <gowrishankar.m@in.ibm.com>
  *
  *****************************************************************************/
 
@@ -74,6 +76,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)
 {
@@ -85,8 +89,15 @@ void *func_nonrt(void *arg)
 	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);
 
+	/* 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 +148,14 @@ void *func_noise(void *arg)
 		pthr->priority);
 	pthread_barrier_wait(&barrier);
 
+	/* Give the other threads time to wait on the condition 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 "\
@@ -200,5 +219,8 @@ int main(int argc, char *argv[])
 	join_threads();
 	printf("Done\n");
 
+	pthread_mutex_destroy(glob_mutex);
+	pthread_mutex_destroy(&cond_mutex);
+	pthread_cond_destroy(&cond_var);
 	return 0;
 }
-- 
1.7.1


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4
  2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
                   ` (6 preceding siblings ...)
  2010-07-02  6:25 ` [LTP] [PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread Gowrishankar
@ 2010-07-03 18:00 ` Subrata Modak
  7 siblings, 0 replies; 9+ messages in thread
From: Subrata Modak @ 2010-07-03 18:00 UTC (permalink / raw)
  To: Gowrishankar; +Cc: Linux Test Project

On Fri, 2010-07-02 at 11:55 +0530, Gowrishankar wrote: 
> Following set of patches applies code cleanup and functional changes
> in LTP realtime pi-test testpi-4. This test was not patched earlier
> when other pi-tests were fixed, with the intension of removing it
> from the suite due to similarity with testpi-1. But we decided to
> keep this test due to dynamically created global mutex lock.
> 
> Order of applying patch is:
> 
> [PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4
> [PATCH 2/7] realtime/testpi-4: reuse init_pi_mutex from librttest
> [PATCH 3/7] realtime/testpi-4: add test description
> [PATCH 4/7] realtime/testpi-4: threads need not set cpu affinity while main does
> [PATCH 5/7] realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles
> [PATCH 6/7] realtime/testpi-4: remove thread_stop which is not used anywhere
> [PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread

Applied in order. Thanks.

Regards--
Subrata

> 
> Thanks,
> Gowri
> 


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-07-03 18:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-02  6:25 [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4 Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 2/7] realtime/testpi-4: reuse init_pi_mutex from librttest Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 3/7] realtime/testpi-4: add test description Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 4/7] realtime/testpi-4: threads need not set cpu affinity while main does Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 5/7] realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 6/7] realtime/testpi-4: remove thread_stop which is not used anywhere Gowrishankar
2010-07-02  6:25 ` [LTP] [PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread Gowrishankar
2010-07-03 18:00 ` [LTP] [PATCH 0/7] realtime/testpi-4: code cleanup and functional changes on testpi-4 Subrata Modak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.