realtime/testpi-4: code cleanup and functional changes on testpi-4
cover realtime/testpi-4: code cleanup and functional changes on testpi-4
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 1/7 realtime/testpi-4: code cleanup on pi-test 4
From: gowrishankar <[email protected]>
This patch cleans up the testpi-4 so as to follow the C coding style standards.
--- testcases/realtime/func/pi-tests/testpi-4.c | 356 ++++++++++++++------------- 1 files changed, 186 insertions(+), 170 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +186 -170
@@ -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 1pthread_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 ; }
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 2/7 realtime/testpi-4: reuse init_pi_mutex from librttest
In reply to GowrishankarFrom: gowrishankar <[email protected]>
testpi-4 is initializing mutex step by step which can be done by reusing the init_pi_mutex() funtion available in librttest.
--- testcases/realtime/func/pi-tests/testpi-4.c | 22 +++------------------- 1 files changed, 3 insertions(+), 19 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +3 -19
@@ -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 );
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 3/7 realtime/testpi-4: add test description
In reply to GowrishankarFrom: gowrishankar <[email protected]>
This patch adds the description to the test testpi-4.
--- testcases/realtime/func/pi-tests/testpi-4.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +2 -2
@@ -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.
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 4/7 realtime/testpi-4: threads need not set cpu affinity while main does
In reply to GowrishankarFrom: gowrishankar <[email protected]>
Since main() sets the cpu affinity, it is not necessary for the spawned threads to do so, as the threads inherit the cpu affinity.
--- testcases/realtime/func/pi-tests/testpi-4.c | 36 ++------------------------ 1 files changed, 3 insertions(+), 33 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +3 -33
@@ -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);
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 5/7 realtime/testpi-4: use busy_work_ms from librttest to burn cpu cycles
In reply to GowrishankarFrom: gowrishankar <[email protected]>
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.
--- testcases/realtime/func/pi-tests/testpi-4.c | 24 ++++++------------------ 1 files changed, 6 insertions(+), 18 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +6 -18
@@ -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 ; }
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 6/7 realtime/testpi-4: remove thread_stop which is not used anywhere
In reply to GowrishankarFrom: gowrishankar <[email protected]>
testpi-4 defines THREAD_STOP which is not used anywhere in the program.
--- testcases/realtime/func/pi-tests/testpi-4.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +0 -3
@@ -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)
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 7/7 realtime/testpi-4: synchronization fixes for high priority noise thread
In reply to GowrishankarFrom: gowrishankar <[email protected]>
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.
--- testcases/realtime/func/pi-tests/testpi-4.c | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-)
testcases/realtime/func/pi-tests/testpi-4.c +23 -1
@@ -30,7 +30,9 @@* * * HISTORY -* +* 2010-06-29 Thread synchronization changes by using +* conditional variables by Gowrishankar. +* by Gowrishankar <[email protected]> * *****************************************************************************/
@@ -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 ; }
Signature · 11 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Subrata Modak
AppliedQuoted 8 lines · Gowrishankar
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:
Quoted 7 lines
[PATCH 1/7] realtime/testpi-4: code cleanup on pi-test 4
[PATCH 2/7] realtime/testpi-4: reuseinit_pi_mutexfrom 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: usebusy_work_msfrom librttest to burn cpu cycles [PATCH 6/7] realtime/testpi-4: removethread_stopwhich is not used anywhere [PATCH 7/7] realtime/testpi-4: synchronization fixes for high priority noise thread
Applied in order. Thanks.
Regards--
Subrata
Quoted 4 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list