On Wed, 27 Feb 2008 14:30:35 +0530 Chirag Jog <[EMAIL PROTECTED]> wrote:

> Hi Sebastien,
> 
>    Here is the patch redone.
> 
> Signed-Off-By: Chirag <[EMAIL PROTECTED]>
> 
> 
> 
> Using librttest support

  Nice, compile and run tested. Looks good.

  Just one remark (well two in fact), for your next submissions, it would be 
nice
to split long lines such as long printf(...) and check your patches for trailing
whitespace.

  Other than that:

  Acked-By: Sebastien Dugue <[EMAIL PROTECTED]>


> 
> 
> ---
> 
>  testcases/realtime/func/pi-tests/sbrk_mutex.c |   24 ---
>  testcases/realtime/func/pi-tests/testpi-1.c   |  199 
> ++++---------------------
>  testcases/realtime/func/pi-tests/testpi-2.c   |  200 
> ++++---------------------
>  testcases/realtime/func/pi-tests/testpi-4.c   |  193 +++---------------------
>  testcases/realtime/func/pi-tests/testpi-5.c   |   10 +
>  testcases/realtime/func/pi-tests/testpi-6.c   |    8 -
>  6 files changed, 92 insertions(+), 542 deletions(-)
> 
> diff --git a/testcases/realtime/func/pi-tests/sbrk_mutex.c 
> b/testcases/realtime/func/pi-tests/sbrk_mutex.c
> index 5d6aeb5..0b61f13 100644
> --- a/testcases/realtime/func/pi-tests/sbrk_mutex.c
> +++ b/testcases/realtime/func/pi-tests/sbrk_mutex.c
> @@ -55,7 +55,6 @@
>  #define DELAY 1000 /* how long to sleep in the worker thread in us */
>  
>  static pthread_mutex_t *mutexes[NUM_MUTEXES];
> -static pthread_t threads[NUM_THREADS];
>  
>  static int run_jvmsim=0;
>  
> @@ -101,7 +100,7 @@ void *worker_thread(void *arg)
>               usleep(DELAY);
>  
>               if (_dbg_lvl)
> -                     printf("thread %ld @ %d\n", (long)arg, i);
> +                 printf("thread %ld @ %d\n", (long)arg, i);
>       }
>       return NULL;
>  }
> @@ -149,28 +148,11 @@ int main(int argc, char* argv[])
>  
>       /* start children threads to walk the array, grabbing the locks */
>       for (t = 0; t < NUM_THREADS; t++) {
> -             pthread_attr_t attr;
> -             struct sched_param param;
> -
> -             param.sched_priority = sched_get_priority_min(SCHED_FIFO);
> -             pthread_attr_init(&attr);
> -             pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
> -             pthread_attr_setschedparam(&attr, &param);
> -             pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
> -
> -             if (pthread_create(&threads[t], &attr, worker_thread, 
> (void*)t)) {
> -                     perror("pthread_create failed");
> +             create_fifo_thread(worker_thread, (void*)t, 
> sched_get_priority_min(SCHED_FIFO));
>               }
> -
> -             pthread_attr_destroy(&attr);
> -     }
> -
>       /* wait for the children to complete */
>       printf("joining threads\n");
> -     for (t = 0; t < NUM_THREADS; t++) {
> -             pthread_join(threads[t], NULL);
> -     }
> -
> +     join_threads();
>       /* destroy all the mutexes */
>       for (m = 0; m < NUM_MUTEXES; m++) {
>               if (mutexes[m]) {
> diff --git a/testcases/realtime/func/pi-tests/testpi-1.c 
> b/testcases/realtime/func/pi-tests/testpi-1.c
> index 0c0b62a..4b627e3 100644
> --- a/testcases/realtime/func/pi-tests/testpi-1.c
> +++ b/testcases/realtime/func/pi-tests/testpi-1.c
> @@ -88,35 +88,13 @@ typedef void* (*entrypoint_t)(void*);
>  
>  pthread_mutex_t glob_mutex;
>  
> -/*typedef struct thread {
> -  int priority;
> -  int policy;
> -  entrypoint_t func;
> -  pthread_attr_t attr;
> -  pthread_t handle;
> -  pthread_mutex_t mutex;
> -  pthread_cond_t cond;
> -  int flags;
> -  int count;
> -} Thread;*/
> -
> -typedef struct thread Thread;
> -
> -Thread arg1, arg2, arg3, arg4, arg5;
> -
> -int strartThread(Thread* thr);
> -void stopThread(Thread* thr);
> -void joinThread(Thread* thr);
> -
>  void* func_nonrt(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> -//  unsigned long mask = 1;
> +  struct thread* pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
> -  CPU_SET(0,&mask);
> +  CPU_SET(0, &mask);
>  
>    rc = sched_setaffinity(0, sizeof(mask), &mask);
>    if (rc < 0) {
> @@ -125,22 +103,15 @@ void* func_nonrt(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -  printf("Thread running %d\n", pthr->priority);
> -
> +  printf("Thread %d started running with priority %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_mutex_lock(&glob_mutex);
> -  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", 
> pthr->priority,
> -        policy, schedp.sched_priority);
> -
> +  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) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i,  
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -148,10 +119,6 @@ void* func_nonrt(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    pthread_mutex_unlock(&glob_mutex);
>    return NULL;
> @@ -159,12 +126,11 @@ void* func_nonrt(void* arg)
>  
>  void* func_rt(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
> -  CPU_SET(0,&mask);
> +  CPU_SET(0, &mask);
>  
>    rc = sched_setaffinity(0, sizeof(mask), &mask);
>    if (rc < 0) {
> @@ -173,15 +139,10 @@ void* func_rt(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -
> +  printf("Thread %d started running with prio %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_barrier_wait(&barrier);
> -
> -  printf("Thread running %d\n", pthr->priority);
>    pthread_mutex_lock(&glob_mutex);
> -  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", 
> pthr->priority,
> -        policy, schedp.sched_priority);
> +  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
> @@ -190,10 +151,7 @@ void* func_rt(void* arg)
>     */
>    for (i=0;i<1000;i++) {
>      if (i%100 == 0) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -201,10 +159,6 @@ void* func_rt(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    pthread_mutex_unlock(&glob_mutex);
>    return NULL;
> @@ -212,9 +166,8 @@ void* func_rt(void* arg)
>  
>  void* func_noise(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -226,19 +179,12 @@ void* func_noise(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Noise Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -
> +  printf("Noise Thread %d started running with prio %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_barrier_wait(&barrier);
>  
> -  printf("Noise Thread running %d\n", pthr->priority);
> -
>    for (i=0;i<10000;i++) {
>      if (i%100 == 0) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -246,83 +192,10 @@ void* func_noise(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping Noise thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    return NULL;
>  }
>  
> -int startThread(Thread* thrd)
> -{
> -  struct sched_param schedp;
> -  pthread_condattr_t condattr;
> -  int retc, policy, inherit;
> -
> -  printf("Start thread priority %d\n", thrd->priority);
> -  if (pthread_attr_init(&(thrd->attr)) != 0) {
> -    printf("Attr init failed");
> -    exit(2);
> -  }
> -  thrd->flags = 0;
> -  memset(&schedp, 0, sizeof(schedp));
> -  schedp.sched_priority = thrd->priority;
> -  policy = thrd->policy;
> -
> -  if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
> -    printf("Can't set policy %d\n", policy);
> -  }
> -  if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
> -    printf("Can't get policy\n");
> -  } else {
> -    printf("Policy in attribs is %d\n", policy);
> -  }
> -  if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
> -    printf("Can't set params");
> -  }
> -  if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
> -    printf("Can't get params");
> -  } else {
> -    printf("Priority in attribs is %d\n", schedp.sched_priority);
> -  }
> -  if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) != 
> 0) {
> -    printf("Can't set inheritsched\n");
> -  }
> -  if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
> -    printf("Can't get inheritsched\n");
> -  } else {
> -    printf("inherit sched in attribs is %d\n", inherit);
> -  }
> -  if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
> -    printf("Failed to init mutex: %d\n", retc);
> -  }
> -  if (pthread_condattr_init(&condattr) != 0) {
> -    printf("Failed to init condattr\n");
> -  }
> -  if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
> -    printf("Failed to init cond\n");
> -  }
> -  retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
> -  printf("Create returns %d\n\n", retc);
> -  return retc;
> -}
> -
> -void stopThread(Thread* thr)
> -{
> -  thr->flags += THREAD_STOP;
> -  joinThread(thr);
> -}
> -
> -void joinThread(Thread* thr)
> -{
> -  void* ret = NULL;
> -  if (pthread_join(thr->pthread, &ret) != 0) {
> -    printf("Join failed\n");
> -  }
> -  printf("Join gave %p\n", ret);
> -}
> -
>  /*
>   * Test pthread creation at different thread priorities.
>   */
> @@ -333,16 +206,16 @@ int main(int argc, char* argv[]) {
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
>    setup();
> -
> +  
>    rt_init("jh",parse_args,argc,argv);
>  
>    if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
>      printf("pthread_barrier_init failed: %s\n", strerror(retc));
>      exit(retc);
>    }
> - 
> +
>    if (run_jvmsim) {
> -     printf("jvmsim enabled\n");
> +     printf("jvmsim enabled\n");
>       jvmsim_init();  // Start the JVM simulation
>    } else {
>       printf("jvmsim disabled\n");
> @@ -354,13 +227,6 @@ int main(int argc, char* argv[]) {
>       exit(-1);
>    }
>    retc = sched_getaffinity(0, sizeof(mask), &mask);
> -
> -  arg1.policy = SCHED_OTHER; arg1.priority = 0;  arg1.func = func_nonrt;
> -  arg2.policy = SCHED_RR;    arg2.priority = 20; arg2.func = func_rt;
> -  arg3.policy = SCHED_RR;    arg3.priority = 30; arg3.func = func_rt;
> -  arg4.policy = SCHED_RR;    arg4.priority = 40; arg4.func = func_rt;
> -  arg5.policy = SCHED_RR;    arg5.priority = 40; arg5.func = func_noise;
> -
>    for (i=0;i<argc;i++) {
>      if (strcmp(argv[i],"nopi") == 0) nopi = 1;
>    }
> @@ -370,7 +236,7 @@ int main(int argc, char* argv[]) {
>    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");
>      }
> @@ -384,23 +250,14 @@ int main(int argc, char* argv[]) {
>      }
>    }
>  
> -  startThread(&arg1);
> -  startThread(&arg2);
> -  startThread(&arg3);
> -  startThread(&arg4);
> -  startThread(&arg5);
> -
> -  sleep(10);
> +  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("Stopping threads\n");
> -  stopThread(&arg1);
> -  stopThread(&arg2);
> -  stopThread(&arg3);
> -  stopThread(&arg4);
> -  stopThread(&arg5);
> -  
> -  printf("Thread counts %d %d %d %d %d\n",arg1.id, arg2.id,
> -      arg3.id, arg4.id, arg5.id);
> +  printf("Joining threads\n");
> +  join_threads();
>    printf("Done\n");
>    printf("Criteria:Low Priority Thread should Preempt Higher Priority Noise 
> Thread\n");
>  
> diff --git a/testcases/realtime/func/pi-tests/testpi-2.c 
> b/testcases/realtime/func/pi-tests/testpi-2.c
> index 9c60e68..45aaab5 100644
> --- a/testcases/realtime/func/pi-tests/testpi-2.c
> +++ b/testcases/realtime/func/pi-tests/testpi-2.c
> @@ -87,31 +87,10 @@ typedef void* (*entrypoint_t)(void*);
>  
>  pthread_mutex_t glob_mutex;
>  
> -/*typedef struct thread {
> -  int priority;
> -  int policy;
> -  entrypoint_t func;
> -  pthread_attr_t attr;
> -  pthread_t handle;
> -  pthread_mutex_t mutex;
> -  pthread_cond_t cond;
> -  int flags;
> -  int count;
> -} Thread;*/
> -
> -typedef struct thread Thread;
> -
> -Thread arg1, arg2, arg3, arg4, arg5;
> -
> -int strartThread(Thread* thr);
> -void stopThread(Thread* thr);
> -void joinThread(Thread* thr);
> -
>  void* func_lowrt(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg ;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -123,22 +102,15 @@ void* func_lowrt(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -  printf("Thread running %d\n", pthr->priority);
> -
> +  printf("Thread %d started running with priority %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_mutex_lock(&glob_mutex);
> -  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", 
> pthr->priority,
> -        policy, schedp.sched_priority);
> +  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) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -146,10 +118,6 @@ void* func_lowrt(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    pthread_mutex_unlock(&glob_mutex);
>    return NULL;
> @@ -157,9 +125,8 @@ void* func_lowrt(void* arg)
>  
>  void* func_rt(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -171,16 +138,10 @@ void* func_rt(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -
> -  /* Let the lower prio RT task grab the lock */
> +  printf("Thread %d started running with prio %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_barrier_wait(&barrier);
> -
> -  printf("Thread running %d\n", pthr->priority);
>    pthread_mutex_lock(&glob_mutex);
> -  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", 
> pthr->priority,
> -        policy, schedp.sched_priority);
> +  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
> @@ -189,10 +150,7 @@ void* func_rt(void* arg)
>     */
>    for (i=0;i<1000;i++) {
>      if (i%100 == 0) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -200,10 +158,6 @@ void* func_rt(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    pthread_mutex_unlock(&glob_mutex);
>    return NULL;
> @@ -211,9 +165,8 @@ void* func_rt(void* arg)
>  
>  void* func_noise(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -225,19 +178,12 @@ void* func_noise(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Noise Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -
> +  printf("Noise Thread %d started running with prio %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_barrier_wait(&barrier);
>  
> -  printf("Noise Thread running %d\n", pthr->priority);
> -
>    for (i=0;i<10000;i++) {
>      if (i%100 == 0) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -245,83 +191,10 @@ void* func_noise(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping Noise thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    return NULL;
>  }
>  
> -int startThread(Thread* thrd)
> -{
> -  struct sched_param schedp;
> -  pthread_condattr_t condattr;
> -  int retc, policy, inherit;
> -
> -  printf("Start thread priority %d\n", thrd->priority);
> -  if (pthread_attr_init(&(thrd->attr)) != 0) {
> -    printf("Attr init failed");
> -    exit(2);
> -  }
> -  thrd->flags = 0;
> -  memset(&schedp, 0, sizeof(schedp));
> -  schedp.sched_priority = thrd->priority;
> -  policy = thrd->policy;
> -
> -  if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
> -    printf("Can't set policy %d\n", policy);
> -  }
> -  if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
> -    printf("Can't get policy\n");
> -  } else {
> -    printf("Policy in attribs is %d\n", policy);
> -  }
> -  if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
> -    printf("Can't set params");
> -  }
> -  if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
> -    printf("Can't get params");
> -  } else {
> -    printf("Priority in attribs is %d\n", schedp.sched_priority);
> -  }
> -  if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) != 
> 0) {
> -    printf("Can't set inheritsched\n");
> -  }
> -  if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
> -    printf("Can't get inheritsched\n");
> -  } else {
> -    printf("inherit sched in attribs is %d\n", inherit);
> -  }
> -  if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
> -    printf("Failed to init mutex: %d\n", retc);
> -  }
> -  if (pthread_condattr_init(&condattr) != 0) {
> -    printf("Failed to init condattr\n");
> -  }
> -  if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
> -    printf("Failed to init cond\n");
> -  }
> -  retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
> -  printf("Create returns %d\n\n", retc);
> -  return retc;
> -}
> -
> -void stopThread(Thread* thr)
> -{
> -  thr->flags += THREAD_STOP;
> -  joinThread(thr);
> -}
> -
> -void joinThread(Thread* thr)
> -{
> -  void* ret = NULL;
> -  if (pthread_join(thr->pthread, &ret) != 0) {
> -    printf("Join failed\n");
> -  }
> -  printf("Join gave %p\n", ret);
> -}
> -
>  /*
>   * Test pthread creation at different thread priorities.
>   */
> @@ -334,6 +207,11 @@ int main(int argc, char* argv[]) {
>    setup();
>    rt_init("jh",parse_args,argc,argv);
>  
> +  if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
> +    printf("pthread_barrier_init failed: %s\n", strerror(retc));
> +    exit(retc);
> +  }
> +
>    if (run_jvmsim) {
>       printf("jvmsim enabled\n");
>       jvmsim_init();  // Start the JVM simulation
> @@ -341,8 +219,6 @@ int main(int argc, char* argv[]) {
>       printf("jvmsim disabled\n");
>    }
>  
> -  printf("Start %s\n",argv[0]);
> -
>    retc = sched_setaffinity(0, sizeof(mask), &mask);
>    if (retc < 0) {
>       printf("Main Thread: Can't set affinity: %d %s\n", retc, 
> strerror(retc));
> @@ -350,18 +226,12 @@ int main(int argc, char* argv[]) {
>    }
>    retc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  arg1.policy = SCHED_RR;    arg1.priority = 10; arg1.func = func_lowrt;
> -  arg2.policy = SCHED_RR;    arg2.priority = 20; arg2.func = func_rt;
> -  arg3.policy = SCHED_FIFO;  arg3.priority = 30; arg3.func = func_rt;
> -  arg4.policy = SCHED_FIFO;  arg4.priority = 40; arg4.func = func_rt;
> -  arg5.policy = SCHED_RR;    arg5.priority = 40; arg5.func = func_noise;
> -
>    for (i=0;i<argc;i++) {
>      if (strcmp(argv[i],"nopi") == 0) nopi = 1;
> -    if (strcmp(argv[i],"SCHED_RR") == 0) arg5.policy = SCHED_RR;
> -    if (strcmp(argv[i],"SCHED_FIFO") == 0) arg5.policy = SCHED_FIFO;
>    }
>  
> +  printf("Start %s\n",argv[0]);
> +
>    if (!nopi) {
>      if (pthread_mutexattr_init(&mutexattr) != 0) {
>        printf("Failed to init mutexattr\n");
> @@ -379,28 +249,14 @@ int main(int argc, char* argv[]) {
>      }
>    }
>  
> -  if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
> -    printf("pthread_barrier_init failed: %s\n", strerror(retc));
> -    exit(retc);
> -  }
> -
> -  startThread(&arg1);
> -  startThread(&arg2);
> -  startThread(&arg3);
> -  startThread(&arg4);
> -  startThread(&arg5);
> -
> -  sleep(10);
> -
> -  printf("Stopping threads\n");
> -  stopThread(&arg1);
> -  stopThread(&arg2);
> -  stopThread(&arg3);
> -  stopThread(&arg4);
> -  stopThread(&arg5);
> +  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("Thread counts %d %d %d %d %d\n",arg1.id, arg2.id,
> -      arg3.id, arg4.id, arg5.id);
> +  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;
> diff --git a/testcases/realtime/func/pi-tests/testpi-4.c 
> b/testcases/realtime/func/pi-tests/testpi-4.c
> index f805e61..32d6614 100644
> --- a/testcases/realtime/func/pi-tests/testpi-4.c
> +++ b/testcases/realtime/func/pi-tests/testpi-4.c
> @@ -88,31 +88,10 @@ typedef void* (*entrypoint_t)(void*);
>  
>  pthread_mutex_t *glob_mutex;
>  
> -/*typedef struct thread {
> -  int priority;
> -  int policy;
> -  entrypoint_t func;
> -  pthread_attr_t attr;
> -  pthread_t handle;
> -  pthread_mutex_t mutex;
> -  pthread_cond_t cond;
> -  int flags;
> -  int count;
> -} Thread;*/
> -
> -typedef struct thread Thread;
> -
> -Thread arg1, arg2, arg3, arg4, arg5;
> -
> -int strartThread(Thread* thr);
> -void stopThread(Thread* thr);
> -void joinThread(Thread* thr);
> -
>  void* func_nonrt(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;       
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -124,21 +103,14 @@ void* func_nonrt(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -  printf("Thread running %d\n", pthr->priority);
> -
> +  printf("Thread %d started running with priority %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_mutex_lock(glob_mutex);
> -  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", 
> pthr->priority,
> -        policy, schedp.sched_priority);
> +  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) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -146,10 +118,6 @@ void* func_nonrt(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    pthread_mutex_unlock(glob_mutex);
>    return NULL;
> @@ -157,9 +125,8 @@ void* func_nonrt(void* arg)
>  
>  void* func_rt(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -171,14 +138,10 @@ void* func_rt(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> +  printf("Thread %d started running with prio %d on CPU %ld\n", tid, 
> pthr->priority, (long)mask.__bits);
>    pthread_barrier_wait(&barrier);
> -
> -  printf("Thread running %d\n", pthr->priority);
>    pthread_mutex_lock(glob_mutex);
> -  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", 
> pthr->priority,
> -        policy, schedp.sched_priority);
> +  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
> @@ -187,10 +150,7 @@ void* func_rt(void* arg)
>     */
>    for (i=0;i<1000;i++) {
>      if (i%100 == 0) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -198,10 +158,6 @@ void* func_rt(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    pthread_mutex_unlock(glob_mutex);
>    return NULL;
> @@ -209,9 +165,8 @@ void* func_rt(void* arg)
>  
>  void* func_noise(void* arg)
>  {
> -  Thread* pthr = (Thread*)arg;
> -  int rc, i, j, policy, tid = gettid();
> -  struct sched_param schedp;
> +  struct thread*  pthr = (struct thread* )arg;
> +  int rc, i, j, tid = gettid();
>    cpu_set_t mask;
>    CPU_ZERO(&mask);
>    CPU_SET(0, &mask);
> @@ -223,19 +178,12 @@ void* func_noise(void* arg)
>    }
>    rc = sched_getaffinity(0, sizeof(mask), &mask);
>  
> -  printf("Noise Thread started %d on CPU %ld\n", pthr->priority, 
> (long)mask.__bits);
> -  pthread_getschedparam(pthr->pthread, &policy, &schedp);
> -
> +  printf("Noise Thread started running with prio %d on CPU %ld\n", 
> pthr->priority, (long)mask.__bits);
>    pthread_barrier_wait(&barrier);
>  
> -  printf("Noise Thread running %d\n", pthr->priority);
> -
>    for (i=0;i<10000;i++) {
>      if (i%100 == 0) {
> -      sched_getparam(tid, &schedp);
> -      policy = sched_getscheduler(tid);
> -      printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, 
> pthr->priority, i,
> -        policy, schedp.sched_priority);
> +      printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, 
> pthr->policy, pthr->priority);
>        fflush(NULL);
>      }
>      pthr->id++;
> @@ -243,83 +191,10 @@ void* func_noise(void* arg)
>        pthread_mutex_lock(&(pthr->mutex));
>        pthread_mutex_unlock(&(pthr->mutex));
>      }
> -    if ((pthr->flags & THREAD_STOP) != 0 ) {
> -      printf("Stopping Noise thread %d\n", pthr->priority);
> -      break;
> -    }
>    }
>    return NULL;
>  }
>  
> -int startThread(Thread* thrd)
> -{
> -  struct sched_param schedp;
> -  pthread_condattr_t condattr;
> -  int retc, policy, inherit;
> -
> -  printf("Start thread priority %d\n", thrd->priority);
> -  if (pthread_attr_init(&(thrd->attr)) != 0) {
> -    printf("Attr init failed");
> -    exit(2);
> -  }
> -  thrd->flags = 0;
> -  memset(&schedp, 0, sizeof(schedp));
> -  schedp.sched_priority = thrd->priority;
> -  policy = thrd->policy;
> -
> -  if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
> -    printf("Can't set policy %d\n", policy);
> -  }
> -  if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
> -    printf("Can't get policy\n");
> -  } else {
> -    printf("Policy in attribs is %d\n", policy);
> -  }
> -  if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
> -    printf("Can't set params");
> -  }
> -  if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
> -    printf("Can't get params");
> -  } else {
> -    printf("Priority in attribs is %d\n", schedp.sched_priority);
> -  }
> -  if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) != 
> 0) {
> -    printf("Can't set inheritsched\n");
> -  }
> -  if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
> -    printf("Can't get inheritsched\n");
> -  } else {
> -    printf("inherit sched in attribs is %d\n", inherit);
> -  }
> -  if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
> -    printf("Failed to init mutex: %d\n", retc);
> -  }
> -  if (pthread_condattr_init(&condattr) != 0) {
> -    printf("Failed to init condattr\n");
> -  }
> -  if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
> -    printf("Failed to init cond\n");
> -  }
> -  retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
> -  printf("Create returns %d\n\n", retc);
> -  return retc;
> -}
> -
> -void stopThread(Thread* thr)
> -{
> -  thr->flags += THREAD_STOP;
> -  joinThread(thr);
> -}
> -
> -void joinThread(Thread* thr)
> -{
> -  void* ret = NULL;
> -  if (pthread_join(thr->pthread, &ret) != 0) {
> -    printf("Join failed\n");
> -  }
> -  printf("Join gave %p\n", ret);
> -}
> -
>  /*
>   * Test pthread creation at different thread priorities.
>   */
> @@ -333,6 +208,11 @@ int main(int argc, char* argv[]) {
>  
>    rt_init("jh",parse_args,argc,argv);
>  
> +  if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
> +    printf("pthread_barrier_init failed: %s\n", strerror(retc));
> +    exit(retc);
> +  }
> +
>    if (run_jvmsim) {
>       printf("jvmsim enabled\n");
>       jvmsim_init();  // Start the JVM simulation
> @@ -346,13 +226,6 @@ int main(int argc, char* argv[]) {
>       exit(-1);
>    }
>    retc = sched_getaffinity(0, sizeof(mask), &mask);
> -
> -  arg1.policy = SCHED_OTHER; arg1.priority = 0;  arg1.func = func_nonrt;
> -  arg2.policy = SCHED_RR;    arg2.priority = 20; arg2.func = func_rt;
> -  arg3.policy = SCHED_RR;    arg3.priority = 30; arg3.func = func_rt;
> -  arg4.policy = SCHED_RR;    arg4.priority = 40; arg4.func = func_rt;
> -  arg5.policy = SCHED_RR;    arg5.priority = 40; arg5.func = func_noise;
> -
>    for (i=0;i<argc;i++) {
>      if (strcmp(argv[i],"nopi") == 0) nopi = 1;
>    }
> @@ -382,28 +255,14 @@ int main(int argc, char* argv[]) {
>      }
>    }
>  
> -  if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
> -    printf("pthread_barrier_init failed: %s\n", strerror(retc));
> -    exit(retc);
> -  }
> -
> -  startThread(&arg1);
> -  startThread(&arg2);
> -  startThread(&arg3);
> -  startThread(&arg4);
> -  startThread(&arg5);
> -
> -  sleep(10);
> -
> -  printf("Stopping threads\n");
> -  stopThread(&arg1);
> -  stopThread(&arg2);
> -  stopThread(&arg3);
> -  stopThread(&arg4);
> -  stopThread(&arg5);
> +  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("Thread counts %d %d %d %d %d\n",arg1.id, arg2.id,
> -      arg3.id, arg4.id, arg5.id);
> +  printf("Joining threads\n");
> +  join_threads();
>    printf("Done\n");
>  
>    return 0;
> diff --git a/testcases/realtime/func/pi-tests/testpi-5.c 
> b/testcases/realtime/func/pi-tests/testpi-5.c
> index 4b62a96..c76704f 100644
> --- a/testcases/realtime/func/pi-tests/testpi-5.c
> +++ b/testcases/realtime/func/pi-tests/testpi-5.c
> @@ -41,7 +41,7 @@
>  #include <pthread.h>
>  #include <string.h>
>  #include <unistd.h>
> -
> +#include <librttest.h>
>  pthread_mutex_t  child_mutex;
>  
>  void* child_thread (void* arg)
> @@ -68,7 +68,6 @@ void* child_thread (void* arg)
>  
>  int do_test(int argc, char ** argv)
>  {
> -    pthread_t thread;
>      pthread_mutexattr_t mutexattr;
>      int retc, protocol;
>  
> @@ -87,10 +86,9 @@ int do_test(int argc, char ** argv)
>        printf("Failed to init mutex: %d\n", retc);
>      }
>  
> -    pthread_create (&thread, NULL, child_thread, NULL);
> -
> -    pthread_join(thread, NULL);
> -
> +    create_other_thread(child_thread, NULL);
> +    join_threads();
> +    
>      return 0;
>  }
>  
> diff --git a/testcases/realtime/func/pi-tests/testpi-6.c 
> b/testcases/realtime/func/pi-tests/testpi-6.c
> index c835932..ab92f77 100644
> --- a/testcases/realtime/func/pi-tests/testpi-6.c
> +++ b/testcases/realtime/func/pi-tests/testpi-6.c
> @@ -41,7 +41,7 @@
>  #include <pthread.h>
>  #include <string.h>
>  #include <unistd.h>
> -
> +#include <librttest.h>
>  pthread_mutex_t  child_mutex;
>  
>  void* child_thread (void* arg)
> @@ -68,7 +68,6 @@ void* child_thread (void* arg)
>  
>  int do_test(int argc, char **argv)
>  {
> -    pthread_t thread;
>      pthread_mutexattr_t mutexattr;
>      int retc, robust;
>  
> @@ -87,9 +86,8 @@ int do_test(int argc, char **argv)
>        printf("Failed to init mutex: %d\n", retc);
>      }
>  
> -    pthread_create (&thread, NULL, child_thread, NULL);
> -
> -    pthread_join(thread, NULL);
> +    create_other_thread(child_thread, NULL);
> +    join_threads();
>  
>      return 0;
>  }
> 
> 
> -- 
> Cheers,
> Chirag Jog
> 
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to