Skip to contentSkip to conversation

realtime: code cleanup on pi-tests to adapt C coding standard

PATCH In review Gowrishankar 2 participants 15 messages May 27, 2010 – May 29, 2010 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): Gowrishankar <[email protected]

#1 lore raw

cover realtime: code cleanup on pi-tests to adapt C coding standard

Following bulk of patches applies the coding style in pi-tests to follow the C coding standard. All are tested and they go in order:

[PATCH 1/5] realtime: code cleanup on pi-test 0 [PATCH 2/5] realtime: code cleanup on pi-test 1 [PATCH 3/5] realtime: code cleanup on pi-test 2 [PATCH 4/5] realtime: code cleanup on pi-test 5 [PATCH 5/5] realtime: code cleanup on pi-test 6

Thanks,
Gowri

------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
Quoted 8 lines · Gowrishankar

Following bulk of patches applies the coding style in pi-tests to follow the C coding standard. All are tested and they go in order:

[PATCH 1/5] realtime: code cleanup on pi-test 0 [PATCH 2/5] realtime: code cleanup on pi-test 1 [PATCH 3/5] realtime: code cleanup on pi-test 2 [PATCH 4/5] realtime: code cleanup on pi-test 5 [PATCH 5/5] realtime: code cleanup on pi-test 6

Thanks. All checked in for this series.

Regards--
Subrata

Quoted 4 lines

Thanks,
Gowri

------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

PATCH 1/5 realtime: code cleanup on pi-test 0

In reply to a message not in the archive

From: gowrishankar <[email protected]>

This patch cleans up the test so as to follow C coding style standards.

---
 testcases/realtime/func/pi-tests/testpi-0.c |   67 ++++++++++++++------------
 1 files changed, 36 insertions(+), 31 deletions(-)
testcases/realtime/func/pi-tests/testpi-0.c +36 -31
index 3c56588..cf0a24d 100644
@@ -30,6 +30,7 @@
  *
  *
  * HISTORY
+ *      2010-04-22 Code cleanup by Gowrishankar ([email protected])
  *
  *
  *****************************************************************************/
@@ -45,53 +46,57 @@
 
 void usage(void)
 {
-        rt_help();
-        printf("testpi-0 specific options:\n");
-        printf("testpi-0 doesn't require any commandline options\n");
+	rt_help();
+	printf("testpi-0 specific options:\n");
+	printf("testpi-0 doesn't require any commandline options\n");
 }
 
 int parse_args(int c, char *v)
 {
 
-        int handled = 1;
-        switch (c) {
-                case 'h':
-                        usage();
-                        exit(0);
-                default:
-                        handled = 0;
-                        break;
-        }
-        return handled;
+	int handled = 1;
+	switch (c) {
+	case 'h':
+		usage();
+		exit(0);
+	default:
+		handled = 0;
+		break;
+	}
+	return handled;
 }
 
 /*
  * Test pthread creation at different thread priorities.
  */
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
 {
-  char *pathbuf; size_t n;
+	char *pathbuf; size_t n;
 
-  rt_init("h",parse_args,argc,argv);
+	rt_init("h", parse_args, argc, argv);
 
-  n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t)0);
-  if ((pathbuf = malloc(n)) == NULL) abort();
-  confstr(_CS_GNU_LIBC_VERSION, pathbuf, n);
+	n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t)0);
+	pathbuf = malloc(n);
+	if (!pathbuf)
+		abort();
+	confstr(_CS_GNU_LIBC_VERSION, pathbuf, n);
 
-  printf("LIBC_VERSION: %s\n", pathbuf);
-  free(pathbuf);
+	printf("LIBC_VERSION: %s\n", pathbuf);
+	free(pathbuf);
 
-  n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t)0);
-  if ((pathbuf = malloc(n)) == NULL) abort();
-  confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
+	n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t)0);
+	pathbuf = malloc(n);
+	if (!pathbuf)
+		abort();
+	confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
 
-  printf("LIBPTHREAD_VERSION: %s\n", pathbuf);
-  free(pathbuf);
+	printf("LIBPTHREAD_VERSION: %s\n", pathbuf);
+	free(pathbuf);
 
-  if (sysconf(_SC_THREAD_PRIO_INHERIT) == -1) {
-	printf("No Prio inheritance support\n");
-  }
-  printf("Prio inheritance support present\n");
+	if (sysconf(_SC_THREAD_PRIO_INHERIT) == -1)
+		printf("No Prio inheritance support\n");
 
-  return 0;
+	printf("Prio inheritance support present\n");
+
+	return 0;
 }
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#4 lore raw

PATCH 2/5 realtime: code cleanup on pi-test 1

In reply to a message not in the archive

From: gowrishankar <[email protected]>

This patch cleans up the test so as to follow C coding style standards.

---
 testcases/realtime/func/pi-tests/testpi-1.c |  348 ++++++++++++++-------------
 1 files changed, 183 insertions(+), 165 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +183 -165
index dc6081b..b503c0c 100644
@@ -30,6 +30,7 @@
  *
  *
  * HISTORY
+ *      2010-04-22 Code cleanup by Gowrishankar
  *
  *
  *****************************************************************************/
@@ -48,23 +49,22 @@ pthread_barrier_t barrier;
 
 void usage(void)
 {
-        rt_help();
-        printf("testpi-1 specific options:\n");
+	rt_help();
+	printf("testpi-1 specific options:\n");
 }
 
 int parse_args(int c, char *v)
 {
-
-        int handled = 1;
-        switch (c) {
-                case 'h':
-                        usage();
-                        exit(0);
-                default:
-                        handled = 0;
-                        break;
-        }
-        return handled;
+	int handled = 1;
+	switch (c) {
+	case 'h':
+		usage();
+		exit(0);
+	default:
+		handled = 0;
+		break;
+	}
+	return handled;
 }
 
 int gettid(void)
@@ -72,173 +72,191 @@ int gettid(void)
 	return syscall(__NR_gettid);
 }
 
-typedef void* (*entrypoint_t)(void*);
+typedef void *(*entrypoint_t)(void *);
 
 #define THREAD_STOP    1
 
 pthread_mutex_t glob_mutex;
 
-void* func_nonrt(void* arg)
+void *func_nonrt(void *arg)
 {
-  struct thread* pthr = (struct thread* )arg;
-  int rc, i, j, tid = gettid();
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-
-  rc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (rc < 0) {
-     printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
-     exit(-1);
-  }
-
-  printf("Thread %d started running with priority %d\n", tid, pthr->priority);
-  pthread_mutex_lock(&glob_mutex);
-  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
-  /* Wait for other RT threads to start up */
-  pthread_barrier_wait(&barrier);
-
-  for (i=0;i<10000;i++) {
-    if (i%100 == 0) {
-      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i,  pthr->policy, pthr->priority);
-      fflush(NULL);
-    }
-    pthr->id++;
-    for (j=0;j<5000;j++) {
-      pthread_mutex_lock(&(pthr->mutex));
-      pthread_mutex_unlock(&(pthr->mutex));
-    }
-  }
-  pthread_mutex_unlock(&glob_mutex);
-  return NULL;
+	struct thread *pthr = (struct thread *)arg;
+	int rc, i, j, tid = gettid();
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+
+	rc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (rc < 0) {
+		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+			strerror(rc));
+		exit(-1);
+	}
+
+	printf("Thread %d started running with priority %d\n", tid,\
+		pthr->priority);
+	pthread_mutex_lock(&glob_mutex);
+	printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",\
+		tid, pthr->policy, pthr->priority);
+	/* Wait for other RT threads to start up */
+	pthread_barrier_wait(&barrier);
+
+	for (i = 0; i < 10000; i++) {
+		if (i%100 == 0) {
+			printf("Thread %d loop %d pthread pol %d pri %d\n",\
+				tid, i,  pthr->policy, pthr->priority);
+			fflush(NULL);
+		}
+		pthr->id++;
+		for (j = 0; j < 5000; j++) {
+			pthread_mutex_lock(&(pthr->mutex));
+			pthread_mutex_unlock(&(pthr->mutex));
+		}
+	}
+	pthread_mutex_unlock(&glob_mutex);
+	return NULL;
 }
 
-void* func_rt(void* arg)
+void *func_rt(void *arg)
 {
-  struct thread*  pthr = (struct thread* )arg;
-  int rc, i, j, tid = gettid();
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-
-  rc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (rc < 0) {
-     printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
-     exit(-1);
-  }
-
-  printf("Thread %d started running with prio %d\n", tid, pthr->priority);
-  pthread_barrier_wait(&barrier);
-  pthread_mutex_lock(&glob_mutex);
-  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
-
-  /* we just use the mutex as something to slow things down */
-  /* say who we are and then do nothing for a while.  The aim
-   * of this is to show that high priority threads make more
-   * progress than lower priority threads..
-   */
-  for (i=0;i<1000;i++) {
-    if (i%100 == 0) {
-      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
-      fflush(NULL);
-    }
-    pthr->id++;
-    for (j=0;j<5000;j++) {
-      pthread_mutex_lock(&(pthr->mutex));
-      pthread_mutex_unlock(&(pthr->mutex));
-    }
-  }
-  pthread_mutex_unlock(&glob_mutex);
-  return NULL;
+	struct thread *pthr = (struct thread *)arg;
+	int rc, i, j, tid = gettid();
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+
+	rc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (rc < 0) {
+		printf("Thread %d: Can't set affinity: %d %s\n", tid,\
+			rc, strerror(rc));
+		exit(-1);
+	}
+
+	printf("Thread %d started running with prio %d\n", tid, pthr->priority);
+	pthread_barrier_wait(&barrier);
+	pthread_mutex_lock(&glob_mutex);
+	printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
+		tid, pthr->policy, pthr->priority);
+
+	/* We just use the mutex as something to slow things down,
+	 * say who we are and then do nothing for a while.  The aim
+	 * of this is to show that high priority threads make more
+	 * progress than lower priority threads..
+	 */
+	for (i = 0; i < 1000; i++) {
+		if (i%100 == 0) {
+			printf("Thread %d loop %d pthread pol %d pri %d\n",\
+				tid, i, pthr->policy, pthr->priority);
+			fflush(NULL);
+		}
+		pthr->id++;
+		for (j = 0; j < 5000; j++) {
+			pthread_mutex_lock(&(pthr->mutex));
+			pthread_mutex_unlock(&(pthr->mutex));
+		}
+	}
+	pthread_mutex_unlock(&glob_mutex);
+	return NULL;
 }
 
-void* func_noise(void* arg)
+void *func_noise(void *arg)
 {
-  struct thread*  pthr = (struct thread* )arg;
-  int rc, i, j, tid = gettid();
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-
-  rc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (rc < 0) {
-     printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
-     exit(-1);
-  }
-
-  printf("Noise Thread %d started running with prio %d\n", tid, pthr->priority);
-  pthread_barrier_wait(&barrier);
-
-  for (i=0;i<10000;i++) {
-    if (i%100 == 0) {
-      printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
-      fflush(NULL);
-    }
-    pthr->id++;
-    for (j=0;j<5000;j++) {
-      pthread_mutex_lock(&(pthr->mutex));
-      pthread_mutex_unlock(&(pthr->mutex));
-    }
-  }
-  return NULL;
+	struct thread *pthr = (struct thread *)arg;
+	int rc, i, j, tid = gettid();
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+
+	rc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (rc < 0) {
+		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+			strerror(rc));
+		exit(-1);
+	}
+
+	printf("Noise Thread %d started running with prio %d\n", tid,
+		pthr->priority);
+	pthread_barrier_wait(&barrier);
+
+	for (i = 0; i < 10000; i++) {
+		if (i%100 == 0) {
+			printf("Noise Thread %d loop %d pthread pol %d "\
+				"pri %d\n", tid, i, pthr->policy,\
+				pthr->priority);
+			fflush(NULL);
+		}
+		pthr->id++;
+		for (j = 0; j < 5000; j++) {
+			pthread_mutex_lock(&(pthr->mutex));
+			pthread_mutex_unlock(&(pthr->mutex));
+		}
+	}
+	return NULL;
 }
 
 /*
  * Test pthread creation at different thread priorities.
  */
-int main(int argc, char* argv[]) {
-  pthread_mutexattr_t mutexattr;
-  int i, retc, protocol, nopi = 0;
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-  setup();
-  
-  rt_init("h",parse_args,argc,argv);
-
-  if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
-    printf("pthread_barrier_init failed: %s\n", strerror(retc));
-    exit(retc);
-  }
-
-  retc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (retc < 0) {
-     printf("Main Thread: Can't set affinity: %d %s\n", retc, strerror(retc));
-     exit(-1);
-  }
-  for (i=0;i<argc;i++) {
-    if (strcmp(argv[i],"nopi") == 0) nopi = 1;
-  }
-
-  printf("Start %s\n",argv[0]);
-
-  if (!nopi) {
-    if (pthread_mutexattr_init(&mutexattr) != 0) {
-      printf("Failed to init mutexattr\n");
-    }
-    if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
-      printf("Can't set protocol prio inherit\n");
-    }
-    if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
-      printf("Can't get mutexattr protocol\n");
-    } else {
-      printf("protocol in mutexattr is %d\n", protocol);
-    }
-    if ((retc = pthread_mutex_init(&glob_mutex, &mutexattr)) != 0) {
-      printf("Failed to init mutex: %d\n", retc);
-    }
-  }
-
-  create_other_thread(func_nonrt,NULL); 
-  create_rr_thread(func_rt, NULL, 20); 
-  create_rr_thread(func_rt, NULL, 30); 
-  create_rr_thread(func_rt, NULL, 40); 
-  create_rr_thread(func_noise, NULL, 40); 
-
-  printf("Joining threads\n");
-  join_threads();
-  printf("Done\n");
-  printf("Criteria:Low Priority Thread should Preempt Higher Priority Noise Thread\n");
-
-  return 0;
+int main(int argc, char *argv[])
+{
+	pthread_mutexattr_t mutexattr;
+	int i, retc, protocol, nopi = 0;
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+	setup();
+
+	rt_init("h", parse_args, argc, argv);
+
+	retc = pthread_barrier_init(&barrier, NULL, 5);
+	if (retc) {
+		printf("pthread_barrier_init failed: %s\n", strerror(retc));
+		exit(retc);
+	}
+
+	retc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (retc < 0) {
+		printf("Main Thread: Can't set affinity: %d %s\n", retc,\
+			strerror(retc));
+		exit(-1);
+	}
+
+	for (i = 0; i < argc; i++) {
+		if (strcmp(argv[i], "nopi") == 0)
+			nopi = 1;
+	}
+
+	printf("Start %s\n", argv[0]);
+
+	if (!nopi) {
+		if (pthread_mutexattr_init(&mutexattr) != 0)
+			printf("Failed to init mutexattr\n");
+
+		if (pthread_mutexattr_setprotocol(&mutexattr,\
+			 PTHREAD_PRIO_INHERIT) != 0)
+			printf("Can't set protocol prio inherit\n");
+
+		if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
+			printf("Can't get mutexattr protocol\n");
+		else
+			printf("protocol in mutexattr is %d\n", protocol);
+
+		retc = pthread_mutex_init(&glob_mutex, &mutexattr);
+		if (retc != 0)
+			printf("Failed to init mutex: %d\n", retc);
+	}
+
+	create_other_thread(func_nonrt, NULL);
+	create_rr_thread(func_rt, NULL, 20);
+	create_rr_thread(func_rt, NULL, 30);
+	create_rr_thread(func_rt, NULL, 40);
+	create_rr_thread(func_noise, NULL, 40);
+
+	printf("Joining threads\n");
+	join_threads();
+	printf("Done\n");
+	printf("Criteria:Low Priority Thread should Preempt Higher Priority "\
+		"Noise Thread\n");
+
+	return 0;
 }
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw

PATCH 3/5 realtime: code cleanup on pi-test 2

In reply to a message not in the archive

From: gowrishankar <[email protected]>

This patch cleans up the test so as to follow C coding style standards.

---
 testcases/realtime/func/pi-tests/testpi-2.c |  346 ++++++++++++++-------------
 1 files changed, 182 insertions(+), 164 deletions(-)
testcases/realtime/func/pi-tests/testpi-2.c +182 -164
index f824c94..8e29e16 100644
@@ -30,6 +30,7 @@
  *
  *
  * HISTORY
+ *      2010-04-22 Code cleanup by Gowrishankar
  *
  *
  *****************************************************************************/
@@ -48,196 +49,213 @@ pthread_barrier_t barrier;
 
 void usage(void)
 {
-        rt_help();
-        printf("testpi-2 specific options:\n");
+	rt_help();
+	printf("testpi-2 specific options:\n");
 }
 
 int parse_args(int c, char *v)
 {
 
-        int handled = 1;
-        switch (c) {
-                case 'h':
-                        usage();
-                        exit(0);
-                default:
-                        handled = 0;
-                        break;
-        }
-        return handled;
+	int handled = 1;
+	switch (c) {
+	case 'h':
+		usage();
+		exit(0);
+	default:
+		handled = 0;
+		break;
+	}
+	return handled;
 }
 
 int gettid(void)
 {
-        return syscall(__NR_gettid);
+	return syscall(__NR_gettid);
 }
 
-typedef void* (*entrypoint_t)(void*);
+typedef void *(*entrypoint_t)(void *);
 
 #define THREAD_STOP    1
 
 pthread_mutex_t glob_mutex;
 
-void* func_lowrt(void* arg)
+void *func_lowrt(void *arg)
 {
-  struct thread*  pthr = (struct thread* )arg ;
-  int rc, i, j, tid = gettid();
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-
-  rc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (rc < 0) {
-     printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
-     exit(-1);
-  }
-
-  printf("Thread %d started running with priority %d\n", tid, pthr->priority);
-  pthread_mutex_lock(&glob_mutex);
-  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
-  /* Wait for other RT threads to start up */
-  pthread_barrier_wait(&barrier);
-
-  for (i=0;i<10000;i++) {
-    if (i%100 == 0) {
-      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
-      fflush(NULL);
-    }
-    pthr->id++;
-    for (j=0;j<5000;j++) {
-      pthread_mutex_lock(&(pthr->mutex));
-      pthread_mutex_unlock(&(pthr->mutex));
-    }
-  }
-  pthread_mutex_unlock(&glob_mutex);
-  return NULL;
+	struct thread *pthr = (struct thread *)arg;
+	int rc, i, j, tid = gettid();
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+
+	rc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (rc < 0) {
+		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+			strerror(rc));
+		exit(-1);
+	}
+
+	printf("Thread %d started running with priority %d\n", tid,\
+		pthr->priority);
+	pthread_mutex_lock(&glob_mutex);
+	printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",\
+		tid, pthr->policy, pthr->priority);
+	/* Wait for other RT threads to start up */
+	pthread_barrier_wait(&barrier);
+
+	for (i = 0; i < 10000; i++) {
+		if (i%100 == 0) {
+			printf("Thread %d loop %d pthread pol %d pri %d\n",\
+				tid, i, pthr->policy, pthr->priority);
+			fflush(NULL);
+		}
+		pthr->id++;
+		for (j = 0; j < 5000; j++) {
+			pthread_mutex_lock(&(pthr->mutex));
+			pthread_mutex_unlock(&(pthr->mutex));
+		}
+	}
+	pthread_mutex_unlock(&glob_mutex);
+	return NULL;
 }
 
-void* func_rt(void* arg)
+void *func_rt(void *arg)
 {
-  struct thread*  pthr = (struct thread* )arg;
-  int rc, i, j, tid = gettid();
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-
-  rc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (rc < 0) {
-     printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
-     exit(-1);
-  }
-
-  printf("Thread %d started running with prio %d\n", tid, pthr->priority);
-  pthread_barrier_wait(&barrier);
-  pthread_mutex_lock(&glob_mutex);
-  printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority);
-
-  /* we just use the mutex as something to slow things down */
-  /* say who we are and then do nothing for a while.  The aim
-   * of this is to show that high priority threads make more
-   * progress than lower priority threads..
-   */
-  for (i=0;i<1000;i++) {
-    if (i%100 == 0) {
-      printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
-      fflush(NULL);
-    }
-    pthr->id++;
-    for (j=0;j<5000;j++) {
-      pthread_mutex_lock(&(pthr->mutex));
-      pthread_mutex_unlock(&(pthr->mutex));
-    }
-  }
-  pthread_mutex_unlock(&glob_mutex);
-  return NULL;
+	struct thread *pthr = (struct thread *)arg;
+	int rc, i, j, tid = gettid();
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+
+	rc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (rc < 0) {
+		printf("Thread %d: Can't set affinity: %d %s\n", tid,\
+			rc, strerror(rc));
+		exit(-1);
+	}
+
+	printf("Thread %d started running with prio %d\n", tid, pthr->priority);
+	pthread_barrier_wait(&barrier);
+	pthread_mutex_lock(&glob_mutex);
+	printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",\
+		tid, pthr->policy, pthr->priority);
+
+	/* We just use the mutex as something to slow things down,
+	 * say who we are and then do nothing for a while.  The aim
+	 * of this is to show that high priority threads make more
+	 * progress than lower priority threads..
+	 */
+	for (i = 0; i < 1000; i++) {
+		if (i%100 == 0) {
+			printf("Thread %d loop %d pthread pol %d pri %d\n",\
+				tid, i, pthr->policy, pthr->priority);
+			fflush(NULL);
+		}
+		pthr->id++;
+		for (j = 0; j < 5000; j++) {
+			pthread_mutex_lock(&(pthr->mutex));
+			pthread_mutex_unlock(&(pthr->mutex));
+		}
+	}
+	pthread_mutex_unlock(&glob_mutex);
+	return NULL;
 }
 
-void* func_noise(void* arg)
+void *func_noise(void *arg)
 {
-  struct thread*  pthr = (struct thread* )arg;
-  int rc, i, j, tid = gettid();
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-
-  rc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (rc < 0) {
-     printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
-     exit(-1);
-  }
-
-  printf("Noise Thread %d started running with prio %d\n", tid, pthr->priority);
-  pthread_barrier_wait(&barrier);
-
-  for (i=0;i<10000;i++) {
-    if (i%100 == 0) {
-      printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority);
-      fflush(NULL);
-    }
-    pthr->id++;
-    for (j=0;j<5000;j++) {
-      pthread_mutex_lock(&(pthr->mutex));
-      pthread_mutex_unlock(&(pthr->mutex));
-    }
-  }
-  return NULL;
+	struct thread *pthr = (struct thread *)arg;
+	int rc, i, j, tid = gettid();
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+
+	rc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (rc < 0) {
+		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
+			strerror(rc));
+		exit(-1);
+	}
+
+	printf("Noise Thread %d started running with prio %d\n", tid,\
+		pthr->priority);
+	pthread_barrier_wait(&barrier);
+
+	for (i = 0; i < 10000; i++) {
+		if (i%100 == 0) {
+			printf("Noise Thread %d loop %d pthread pol %d "\
+				"pri %d\n", tid, i, pthr->policy,\
+				pthr->priority);
+			fflush(NULL);
+		}
+		pthr->id++;
+		for (j = 0; j < 5000; j++) {
+			pthread_mutex_lock(&(pthr->mutex));
+			pthread_mutex_unlock(&(pthr->mutex));
+		}
+	}
+	return NULL;
 }
 
 /*
  * Test pthread creation at different thread priorities.
  */
-int main(int argc, char* argv[]) {
-  pthread_mutexattr_t mutexattr;
-  int i, retc, protocol, nopi = 0;
-  cpu_set_t mask;
-  CPU_ZERO(&mask);
-  CPU_SET(0, &mask);
-  setup();
-  rt_init("h",parse_args,argc,argv);
-
-  if ((retc = pthread_barrier_init(&barrier, NULL, 5))) {
-    printf("pthread_barrier_init failed: %s\n", strerror(retc));
-    exit(retc);
-  }
-
-  retc = sched_setaffinity(0, sizeof(mask), &mask);
-  if (retc < 0) {
-     printf("Main Thread: Can't set affinity: %d %s\n", retc, strerror(retc));
-     exit(-1);
-  }
-
-  for (i=0;i<argc;i++) {
-    if (strcmp(argv[i],"nopi") == 0) nopi = 1;
-  }
-
-  printf("Start %s\n",argv[0]);
-
-  if (!nopi) {
-    if (pthread_mutexattr_init(&mutexattr) != 0) {
-      printf("Failed to init mutexattr\n");
-    };
-    if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
-      printf("Can't set protocol prio inherit\n");
-    }
-    if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
-      printf("Can't get mutexattr protocol\n");
-    } else {
-      printf("protocol in mutexattr is %d\n", protocol);
-    }
-    if ((retc = pthread_mutex_init(&glob_mutex, &mutexattr)) != 0) {
-      printf("Failed to init mutex: %d\n", retc);
-    }
-  }
-
-  create_rr_thread(func_lowrt, NULL, 10);
-  create_rr_thread(func_rt, NULL, 20);
-  create_fifo_thread(func_rt, NULL, 30);
-  create_fifo_thread(func_rt, NULL, 40);
-  create_rr_thread(func_noise, NULL, 40);
-
-  printf("Joining threads\n");
-  join_threads();
-  printf("Done\n");
-  printf("Criteria: Low Priority Thread and High Priority Thread should prempt each other multiple times\n");
-  return 0;
+int main(int argc, char *argv[])
+{
+	pthread_mutexattr_t mutexattr;
+	int i, retc, protocol, nopi = 0;
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+	CPU_SET(0, &mask);
+	setup();
+	rt_init("h", parse_args, argc, argv);
+
+	retc = pthread_barrier_init(&barrier, NULL, 5);
+	if (retc) {
+		printf("pthread_barrier_init failed: %s\n", strerror(retc));
+		exit(retc);
+	}
+
+	retc = sched_setaffinity(0, sizeof(mask), &mask);
+	if (retc < 0) {
+		printf("Main Thread: Can't set affinity: %d %s\n", retc,\
+			strerror(retc));
+		exit(-1);
+	}
+
+	for (i = 0; i < argc; i++) {
+		if (strcmp(argv[i], "nopi") == 0)
+			nopi = 1;
+	}
+
+	printf("Start %s\n", argv[0]);
+
+	if (!nopi) {
+		if (pthread_mutexattr_init(&mutexattr) != 0)
+			printf("Failed to init mutexattr\n");
+
+		if (pthread_mutexattr_setprotocol(&mutexattr,\
+			PTHREAD_PRIO_INHERIT) != 0)
+			printf("Can't set protocol prio inherit\n");
+
+		if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
+			printf("Can't get mutexattr protocol\n");
+		else
+			printf("protocol in mutexattr is %d\n", protocol);
+
+		retc = pthread_mutex_init(&glob_mutex, &mutexattr);
+		if (retc != 0)
+			printf("Failed to init mutex: %d\n", retc);
+	}
+
+	create_rr_thread(func_lowrt, NULL, 10);
+	create_rr_thread(func_rt, NULL, 20);
+	create_fifo_thread(func_rt, NULL, 30);
+	create_fifo_thread(func_rt, NULL, 40);
+	create_rr_thread(func_noise, NULL, 40);
+
+	printf("Joining threads\n");
+	join_threads();
+	printf("Done\n");
+	printf("Criteria: Low Priority Thread and High Priority Thread "\
+		"should prempt each other multiple times\n");
+	return 0;
 }
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#6 lore raw

PATCH 4/5 realtime: code cleanup on pi-test 5

In reply to a message not in the archive

From: gowrishankar <[email protected]>

This patch cleans up the test so as to follow C coding style standards.

---
 testcases/realtime/func/pi-tests/testpi-5.c |   76 ++++++++++++++-------------
 1 files changed, 39 insertions(+), 37 deletions(-)
testcases/realtime/func/pi-tests/testpi-5.c +39 -37
index faf3d8d..b3ea6ef 100644
@@ -30,6 +30,7 @@
  *
  *
  * HISTORY
+ *      2010-04-22 Code cleanup by Gowrishankar
  *
  *
  *****************************************************************************/
@@ -39,54 +40,55 @@
 #include <string.h>
 #include <unistd.h>
 #include <librttest.h>
-pthread_mutex_t  child_mutex;
+pthread_mutex_t child_mutex;
 
-void* child_thread (void* arg)
+void *child_thread(void *arg)
 {
-    int ret;
+	int ret;
 
-    ret = pthread_mutex_lock(&child_mutex);
-    if (ret != 0)
-	printf("child thread: Failed to lock child_mutex: %d\n", ret);
-    else
-	printf("child_thread: got lock\n");
+	ret = pthread_mutex_lock(&child_mutex);
+	if (ret != 0)
+		printf("child thread: Failed to lock child_mutex: %d\n", ret);
+	else
+		printf("child_thread: got lock\n");
 
-    sleep(2);
+	sleep(2);
 
-    printf("child_thread: Trying to get lock 2nd time\n");
-    ret = pthread_mutex_lock(&child_mutex);
-    if (ret != 0)
-	printf("child thread: Failed to lock child_mutex: %d\n", ret);
-    else
-	printf("child_thread: got lock 2nd time !!\n");
+	printf("child_thread: Trying to get lock 2nd time\n");
+	ret = pthread_mutex_lock(&child_mutex);
+	if (ret != 0)
+		printf("child thread: Failed to lock child_mutex: %d\n", ret);
+	else
+		printf("child_thread: got lock 2nd time !!\n");
 
-    return NULL;
+	return NULL;
 }
 
-int do_test(int argc, char ** argv)
+int do_test(int argc, char **argv)
 {
-    pthread_mutexattr_t mutexattr;
-    int retc, protocol;
+	pthread_mutexattr_t mutexattr;
+	int retc, protocol;
 
-    if (pthread_mutexattr_init(&mutexattr) != 0) {
-      printf("Failed to init mutexattr\n");
-    };
-    if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
-      printf("Can't set protocol prio inherit\n");
-    }
-    if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
-      printf("Can't get mutexattr protocol\n");
-    } else {
-      printf("protocol in mutexattr is %d\n", protocol);
-    }
-    if ((retc = pthread_mutex_init(&child_mutex, &mutexattr)) != 0) {
-      printf("Failed to init mutex: %d\n", retc);
-    }
+	if (pthread_mutexattr_init(&mutexattr) != 0)
+		printf("Failed to init mutexattr\n");
 
-    create_other_thread(child_thread, NULL);
-    join_threads();
-    
-    return 0;
+	if (pthread_mutexattr_setprotocol(&mutexattr,\
+		PTHREAD_PRIO_INHERIT) != 0)
+		printf("Can't set protocol prio inherit\n");
+
+	if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
+		printf("Can't get mutexattr protocol\n");
+	else
+		printf("protocol in mutexattr is %d\n", protocol);
+
+	retc = pthread_mutex_init(&child_mutex, &mutexattr);
+	if (retc != 0)
+		printf("Failed to init mutex: %d\n", retc);
+
+	create_other_thread(child_thread, NULL);
+	join_threads();
+
+	return 0;
 }
 
 #include "test-skeleton.c"
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#7 lore raw

PATCH 5/5 realtime: code cleanup on pi-test 6

In reply to a message not in the archive

From: gowrishankar <[email protected]>

This patch cleans up the test so as to follow C coding style standards.

---
 testcases/realtime/func/pi-tests/testpi-6.c |   72 ++++++++++++++-------------
 1 files changed, 37 insertions(+), 35 deletions(-)
testcases/realtime/func/pi-tests/testpi-6.c +37 -35
index 560f45f..523ba13 100644
@@ -30,6 +30,7 @@
  *
  *
  * HISTORY
+ *      2010-04-22 Code cleanup by Gowrishankar
  *
  *
  *****************************************************************************/
@@ -39,54 +40,55 @@
 #include <string.h>
 #include <unistd.h>
 #include <librttest.h>
-pthread_mutex_t  child_mutex;
+pthread_mutex_t child_mutex;
 
-void* child_thread (void* arg)
+void *child_thread(void *arg)
 {
-    int ret;
+	int ret;
 
-    ret = pthread_mutex_lock(&child_mutex);
-    if (ret != 0)
-	printf("child thread: Failed to lock child_mutex: %d\n", ret);
-    else
-	printf("child_thread: got lock\n");
+	ret = pthread_mutex_lock(&child_mutex);
+	if (ret != 0)
+		printf("child thread: Failed to lock child_mutex: %d\n", ret);
+	else
+		printf("child_thread: got lock\n");
 
-    sleep(2);
+	sleep(2);
 
-    printf("child_thread: Trying to get lock 2nd time\n");
-    ret = pthread_mutex_lock(&child_mutex);
-    if (ret != 0)
-	printf("child thread: Failed to lock child_mutex: %d\n", ret);
-    else
-	printf("child_thread: got lock 2nd time !!\n");
+	printf("child_thread: Trying to get lock 2nd time\n");
+	ret = pthread_mutex_lock(&child_mutex);
+	if (ret != 0)
+		printf("child thread: Failed to lock child_mutex: %d\n", ret);
+	else
+		printf("child_thread: got lock 2nd time !!\n");
 
-    return NULL;
+	return NULL;
 }
 
 int do_test(int argc, char **argv)
 {
-    pthread_mutexattr_t mutexattr;
-    int retc, robust;
+	pthread_mutexattr_t mutexattr;
+	int retc, robust;
 
-    if (pthread_mutexattr_init(&mutexattr) != 0) {
-      printf("Failed to init mutexattr\n");
-    };
-    if (pthread_mutexattr_setrobust_np(&mutexattr, PTHREAD_MUTEX_ROBUST_NP) != 0) {
-      printf("Can't set robust mutex\n");
-    }
-    if (pthread_mutexattr_getrobust_np(&mutexattr, &robust) != 0) {
-      printf("Can't get mutexattr protocol\n");
-    } else {
-      printf("robust in mutexattr is %d\n", robust);
-    }
-    if ((retc = pthread_mutex_init(&child_mutex, &mutexattr)) != 0) {
-      printf("Failed to init mutex: %d\n", retc);
-    }
+	if (pthread_mutexattr_init(&mutexattr) != 0)
+		printf("Failed to init mutexattr\n");
 
-    create_other_thread(child_thread, NULL);
-    join_threads();
+	if (pthread_mutexattr_setrobust_np(&mutexattr,\
+		PTHREAD_MUTEX_ROBUST_NP) != 0)
+		printf("Can't set robust mutex\n");
 
-    return 0;
+	if (pthread_mutexattr_getrobust_np(&mutexattr, &robust) != 0)
+		printf("Can't get mutexattr protocol\n");
+	else
+		printf("robust in mutexattr is %d\n", robust);
+
+	retc = pthread_mutex_init(&child_mutex, &mutexattr);
+	if (retc != 0)
+		printf("Failed to init mutex: %d\n", retc);
+
+	create_other_thread(child_thread, NULL);
+	join_threads();
+
+	return 0;
 }
 
 #include "test-skeleton.c"
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#8 lore raw

cover realtime: functional changes improved in pi-tests

In reply to a message not in the archive

Following set of patches applies functional changes in pi-tests for better reliability in recent kernels and their order is:

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

All need to be applied in their order on top or code clean up patch series sent previously.

Thanks,
Gowri

------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#9 lore raw

Re: [LTP] [PATCH 0/5] realtime: functional changes improved in pi-tests

Quoted 10 lines · Gowrishankar

Following set of patches applies functional changes in pi-tests for better reliability in recent kernels and their order is:

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

Quoted 2 lines

All need to be applied in their order on top or code clean up patch series sent previously.

Thanks.

Regards--
Subrata

Quoted 5 lines

Thanks,
Gowri

------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#10 lore raw

PATCH 1/6 realtime: reuse init_pi_mutex from librttest

In reply to a message not in the archive

From: gowrishankar <[email protected]>

testpi-1 and testpi-2 are initializing mutex step by step which can be done by reusing the init_pi_mutex() funtion available in librttest.

---
 testcases/realtime/func/pi-tests/testpi-1.c |   22 +++-------------------
 testcases/realtime/func/pi-tests/testpi-2.c |   22 +++-------------------
 2 files changed, 6 insertions(+), 38 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +3 -19
index b503c0c..dc3c30b 100644
@@ -199,8 +199,7 @@ void *func_noise(void *arg)
  */
 int main(int argc, char *argv[])
 {
-	pthread_mutexattr_t mutexattr;
-	int i, retc, protocol, nopi = 0;
+	int i, retc, nopi = 0;
 	cpu_set_t mask;
 	CPU_ZERO(&mask);
 	CPU_SET(0, &mask);
@@ -228,23 +227,8 @@ int main(int argc, char *argv[])
 
 	printf("Start %s\n", argv[0]);
 
-	if (!nopi) {
-		if (pthread_mutexattr_init(&mutexattr) != 0)
-			printf("Failed to init mutexattr\n");
-
-		if (pthread_mutexattr_setprotocol(&mutexattr,\
-			 PTHREAD_PRIO_INHERIT) != 0)
-			printf("Can't set protocol prio inherit\n");
-
-		if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
-			printf("Can't get mutexattr protocol\n");
-		else
-			printf("protocol in mutexattr is %d\n", protocol);
-
-		retc = pthread_mutex_init(&glob_mutex, &mutexattr);
-		if (retc != 0)
-			printf("Failed to init mutex: %d\n", retc);
-	}
+	if (!nopi)
+		init_pi_mutex(&glob_mutex);
 
 	create_other_thread(func_nonrt, NULL);
 	create_rr_thread(func_rt, NULL, 20);
testcases/realtime/func/pi-tests/testpi-2.c +3 -19
index 8e29e16..4220aba 100644
@@ -200,8 +200,7 @@ void *func_noise(void *arg)
  */
 int main(int argc, char *argv[])
 {
-	pthread_mutexattr_t mutexattr;
-	int i, retc, protocol, nopi = 0;
+	int i, retc, nopi = 0;
 	cpu_set_t mask;
 	CPU_ZERO(&mask);
 	CPU_SET(0, &mask);
@@ -228,23 +227,8 @@ int main(int argc, char *argv[])
 
 	printf("Start %s\n", argv[0]);
 
-	if (!nopi) {
-		if (pthread_mutexattr_init(&mutexattr) != 0)
-			printf("Failed to init mutexattr\n");
-
-		if (pthread_mutexattr_setprotocol(&mutexattr,\
-			PTHREAD_PRIO_INHERIT) != 0)
-			printf("Can't set protocol prio inherit\n");
-
-		if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
-			printf("Can't get mutexattr protocol\n");
-		else
-			printf("protocol in mutexattr is %d\n", protocol);
-
-		retc = pthread_mutex_init(&glob_mutex, &mutexattr);
-		if (retc != 0)
-			printf("Failed to init mutex: %d\n", retc);
-	}
+	if (!nopi)
+		init_pi_mutex(&glob_mutex);
 
 	create_rr_thread(func_lowrt, NULL, 10);
 	create_rr_thread(func_rt, NULL, 20);
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#11 lore raw

PATCH 2/6 realtime: add test descriptions

In reply to a message not in the archive

From: gowrishankar <[email protected]>

This patch adds the descriptions for the tests 1,2,5,6.

---
 testcases/realtime/func/pi-tests/testpi-1.c |    4 ++--
 testcases/realtime/func/pi-tests/testpi-2.c |    5 +++--
 testcases/realtime/func/pi-tests/testpi-5.c |    4 ++--
 testcases/realtime/func/pi-tests/testpi-6.c |    4 ++--
 4 files changed, 9 insertions(+), 8 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +2 -2
index dc3c30b..35df387 100644
@@ -20,8 +20,8 @@
  *      testpi-1.c
  *
  * DESCRIPTION
- *
- *
+ *     This testcase verifies if the low priority SCHED_OTHER thread can preempt
+ *     the high priority SCHED_RR thread via priority inheritance.
  *
  * USAGE:
  *      Use run_auto.sh script in current directory to build and run test.
testcases/realtime/func/pi-tests/testpi-2.c +3 -2
index 4220aba..00f632b 100644
@@ -20,8 +20,9 @@
  *      testpi-2.c
  *
  * DESCRIPTION
- *
- *
+ *      This testcase verifies if the low priority SCHED_RR thread can preempt
+ *      the high priority SCHED_RR thread multiple times via priority
+ *      inheritance.
  *
  * USAGE:
  *      Use run_auto.sh script in current directory to build and run test.
testcases/realtime/func/pi-tests/testpi-5.c +2 -2
index b3ea6ef..1330dfd 100644
@@ -20,8 +20,8 @@
  *      testpi-5.c
  *
  * DESCRIPTION
- *
- *
+ *      This testcase verifies if a thread can lock the priority inheritance
+ *      mutex multiple times.
  *
  * USAGE:
  *      Use run_auto.sh script in current directory to build and run test.
testcases/realtime/func/pi-tests/testpi-6.c +2 -2
index 523ba13..19c06ea 100644
@@ -20,8 +20,8 @@
  *      testpi-6.c
  *
  * DESCRIPTION
- *
- *
+ *      This testcase verifies if a thread can lock the robust mutex multiple
+ *      times.
  *
  * USAGE:
  *      Use run_auto.sh script in current directory to build and run test.
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#12 lore raw

PATCH 3/6 realtime: threads need not set cpu affinity while main does

In reply to a message not in the archive

From: 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-1.c |   36 ++------------------------
 testcases/realtime/func/pi-tests/testpi-2.c |   36 ++------------------------
 2 files changed, 6 insertions(+), 66 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +3 -33
index 35df387..25541d7 100644
@@ -81,17 +81,7 @@ pthread_mutex_t glob_mutex;
 void *func_nonrt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int rc, i, j, tid = gettid();
-	cpu_set_t mask;
-	CPU_ZERO(&mask);
-	CPU_SET(0, &mask);
-
-	rc = sched_setaffinity(0, sizeof(mask), &mask);
-	if (rc < 0) {
-		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
-			strerror(rc));
-		exit(-1);
-	}
+	int i, j, tid = gettid();
 
 	printf("Thread %d started running with priority %d\n", tid,\
 		pthr->priority);
@@ -120,17 +110,7 @@ void *func_nonrt(void *arg)
 void *func_rt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int rc, i, j, tid = gettid();
-	cpu_set_t mask;
-	CPU_ZERO(&mask);
-	CPU_SET(0, &mask);
-
-	rc = sched_setaffinity(0, sizeof(mask), &mask);
-	if (rc < 0) {
-		printf("Thread %d: Can't set affinity: %d %s\n", tid,\
-			rc, strerror(rc));
-		exit(-1);
-	}
+	int i, j, tid = gettid();
 
 	printf("Thread %d started running with prio %d\n", tid, pthr->priority);
 	pthread_barrier_wait(&barrier);
@@ -162,17 +142,7 @@ void *func_rt(void *arg)
 void *func_noise(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int rc, i, j, tid = gettid();
-	cpu_set_t mask;
-	CPU_ZERO(&mask);
-	CPU_SET(0, &mask);
-
-	rc = sched_setaffinity(0, sizeof(mask), &mask);
-	if (rc < 0) {
-		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
-			strerror(rc));
-		exit(-1);
-	}
+	int i, j, tid = gettid();
 
 	printf("Noise Thread %d started running with prio %d\n", tid,
 		pthr->priority);
testcases/realtime/func/pi-tests/testpi-2.c +3 -33
index 00f632b..eb00129 100644
@@ -83,17 +83,7 @@ pthread_mutex_t glob_mutex;
 void *func_lowrt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int rc, i, j, tid = gettid();
-	cpu_set_t mask;
-	CPU_ZERO(&mask);
-	CPU_SET(0, &mask);
-
-	rc = sched_setaffinity(0, sizeof(mask), &mask);
-	if (rc < 0) {
-		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
-			strerror(rc));
-		exit(-1);
-	}
+	int i, j, tid = gettid();
 
 	printf("Thread %d started running with priority %d\n", tid,\
 		pthr->priority);
@@ -122,17 +112,7 @@ void *func_lowrt(void *arg)
 void *func_rt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int rc, i, j, tid = gettid();
-	cpu_set_t mask;
-	CPU_ZERO(&mask);
-	CPU_SET(0, &mask);
-
-	rc = sched_setaffinity(0, sizeof(mask), &mask);
-	if (rc < 0) {
-		printf("Thread %d: Can't set affinity: %d %s\n", tid,\
-			rc, strerror(rc));
-		exit(-1);
-	}
+	int i, j, tid = gettid();
 
 	printf("Thread %d started running with prio %d\n", tid, pthr->priority);
 	pthread_barrier_wait(&barrier);
@@ -164,17 +144,7 @@ void *func_rt(void *arg)
 void *func_noise(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int rc, i, j, tid = gettid();
-	cpu_set_t mask;
-	CPU_ZERO(&mask);
-	CPU_SET(0, &mask);
-
-	rc = sched_setaffinity(0, sizeof(mask), &mask);
-	if (rc < 0) {
-		printf("Thread %d: Can't set affinity: %d %s\n", tid, rc,\
-			strerror(rc));
-		exit(-1);
-	}
+	int i, j, tid = gettid();
 
 	printf("Noise Thread %d started running with prio %d\n", tid,\
 		pthr->priority);
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#13 lore raw

PATCH 4/6 realtime: use busy_work_ms from librttest to burn cpu cycles

In reply to a message not in the archive

From: 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-1.c |   24 ++++++------------------
 testcases/realtime/func/pi-tests/testpi-2.c |   24 ++++++------------------
 2 files changed, 12 insertions(+), 36 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +6 -18
index 25541d7..71b01ec 100644
@@ -81,7 +81,7 @@ pthread_mutex_t glob_mutex;
 void *func_nonrt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int i, j, tid = gettid();
+	int i, tid = gettid();
 
 	printf("Thread %d started running with priority %d\n", tid,\
 		pthr->priority);
@@ -97,11 +97,7 @@ void *func_nonrt(void *arg)
 				tid, i,  pthr->policy, pthr->priority);
 			fflush(NULL);
 		}
-		pthr->id++;
-		for (j = 0; j < 5000; j++) {
-			pthread_mutex_lock(&(pthr->mutex));
-			pthread_mutex_unlock(&(pthr->mutex));
-		}
+		busy_work_ms(1);
 	}
 	pthread_mutex_unlock(&glob_mutex);
 	return NULL;
@@ -110,7 +106,7 @@ void *func_nonrt(void *arg)
 void *func_rt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int i, j, tid = gettid();
+	int i, tid = gettid();
 
 	printf("Thread %d started running with prio %d\n", tid, pthr->priority);
 	pthread_barrier_wait(&barrier);
@@ -129,11 +125,7 @@ void *func_rt(void *arg)
 				tid, i, pthr->policy, pthr->priority);
 			fflush(NULL);
 		}
-		pthr->id++;
-		for (j = 0; j < 5000; j++) {
-			pthread_mutex_lock(&(pthr->mutex));
-			pthread_mutex_unlock(&(pthr->mutex));
-		}
+		busy_work_ms(1);
 	}
 	pthread_mutex_unlock(&glob_mutex);
 	return NULL;
@@ -142,7 +134,7 @@ void *func_rt(void *arg)
 void *func_noise(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int i, j, tid = gettid();
+	int i, tid = gettid();
 
 	printf("Noise Thread %d started running with prio %d\n", tid,
 		pthr->priority);
@@ -155,11 +147,7 @@ void *func_noise(void *arg)
 				pthr->priority);
 			fflush(NULL);
 		}
-		pthr->id++;
-		for (j = 0; j < 5000; j++) {
-			pthread_mutex_lock(&(pthr->mutex));
-			pthread_mutex_unlock(&(pthr->mutex));
-		}
+		busy_work_ms(1);
 	}
 	return NULL;
 }
testcases/realtime/func/pi-tests/testpi-2.c +6 -18
index eb00129..68dde44 100644
@@ -83,7 +83,7 @@ pthread_mutex_t glob_mutex;
 void *func_lowrt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int i, j, tid = gettid();
+	int i, tid = gettid();
 
 	printf("Thread %d started running with priority %d\n", tid,\
 		pthr->priority);
@@ -99,11 +99,7 @@ void *func_lowrt(void *arg)
 				tid, i, pthr->policy, pthr->priority);
 			fflush(NULL);
 		}
-		pthr->id++;
-		for (j = 0; j < 5000; j++) {
-			pthread_mutex_lock(&(pthr->mutex));
-			pthread_mutex_unlock(&(pthr->mutex));
-		}
+		busy_work_ms(1);
 	}
 	pthread_mutex_unlock(&glob_mutex);
 	return NULL;
@@ -112,7 +108,7 @@ void *func_lowrt(void *arg)
 void *func_rt(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int i, j, tid = gettid();
+	int i, tid = gettid();
 
 	printf("Thread %d started running with prio %d\n", tid, pthr->priority);
 	pthread_barrier_wait(&barrier);
@@ -131,11 +127,7 @@ void *func_rt(void *arg)
 				tid, i, pthr->policy, pthr->priority);
 			fflush(NULL);
 		}
-		pthr->id++;
-		for (j = 0; j < 5000; j++) {
-			pthread_mutex_lock(&(pthr->mutex));
-			pthread_mutex_unlock(&(pthr->mutex));
-		}
+		busy_work_ms(1);
 	}
 	pthread_mutex_unlock(&glob_mutex);
 	return NULL;
@@ -144,7 +136,7 @@ void *func_rt(void *arg)
 void *func_noise(void *arg)
 {
 	struct thread *pthr = (struct thread *)arg;
-	int i, j, tid = gettid();
+	int i, tid = gettid();
 
 	printf("Noise Thread %d started running with prio %d\n", tid,\
 		pthr->priority);
@@ -157,11 +149,7 @@ void *func_noise(void *arg)
 				pthr->priority);
 			fflush(NULL);
 		}
-		pthr->id++;
-		for (j = 0; j < 5000; j++) {
-			pthread_mutex_lock(&(pthr->mutex));
-			pthread_mutex_unlock(&(pthr->mutex));
-		}
+		busy_work_ms(1);
 	}
 	return NULL;
 }
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#14 lore raw

PATCH 5/6 realtime: remove thread_stop which is not used anywhere

In reply to a message not in the archive

From: gowrishankar <[email protected]>

Tests testpi-1 and testpi-2 defines THREAD_STOP which is not used anywhere in the program.

---
 testcases/realtime/func/pi-tests/testpi-1.c |    3 ---
 testcases/realtime/func/pi-tests/testpi-2.c |    3 ---
 2 files changed, 0 insertions(+), 6 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +0 -3
index 71b01ec..3e05e56 100644
@@ -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)
testcases/realtime/func/pi-tests/testpi-2.c +0 -3
index 68dde44..f0e86ea 100644
@@ -75,9 +75,6 @@ int gettid(void)
 }
 
 typedef void *(*entrypoint_t)(void *);
-
-#define THREAD_STOP    1
-
 pthread_mutex_t glob_mutex;
 
 void *func_lowrt(void *arg)
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#15 lore raw

PATCH 6/6 realtime: synchronization fixes for high priority noise thread

In reply to a message not in the archive

From: gowrishankar <[email protected]>

In a scenario where high priority noise thread is not scheduled after the barrier but some other real-time thread, the test intention gets broken by the test code, as priority inversion will never happen. We need to tightly synchronize the threads so the noise thread always begins the test so that it gets preempted by low prio thread through PI logic and is done with conditional variables.

This change is applied on both the tests testpi-1 and testpi-2.

---
 testcases/realtime/func/pi-tests/testpi-1.c |   23 +++++++++++++++++++++--
 testcases/realtime/func/pi-tests/testpi-2.c |   24 ++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)
testcases/realtime/func/pi-tests/testpi-1.c +21 -2
index 3e05e56..5d18f29 100644
@@ -30,8 +30,9 @@
  *
  *
  * HISTORY
- *      2010-04-22 Code cleanup by Gowrishankar
- *
+ *      2010-04-22 Code cleanup and thread synchronization changes by using
+ *                 conditional variables,
+ *                 by Gowrishankar([email protected]).
  *
  *****************************************************************************/
 
@@ -74,6 +75,8 @@ int gettid(void)
 
 typedef void *(*entrypoint_t)(void *);
 pthread_mutex_t glob_mutex;
+static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
 
 void *func_nonrt(void *arg)
 {
@@ -88,6 +91,11 @@ void *func_nonrt(void *arg)
 	/* Wait for other RT threads to start up */
 	pthread_barrier_wait(&barrier);
 
+	/* Wait for the high priority noise thread to start and signal us */
+	pthread_mutex_lock(&cond_mutex);
+	pthread_cond_wait(&cond_var, &cond_mutex);
+	pthread_mutex_unlock(&cond_mutex);
+
 	for (i = 0; i < 10000; i++) {
 		if (i%100 == 0) {
 			printf("Thread %d loop %d pthread pol %d pri %d\n",\
@@ -137,6 +145,14 @@ void *func_noise(void *arg)
 		pthr->priority);
 	pthread_barrier_wait(&barrier);
 
+	/* Let others wait at conditional variable */
+	usleep(1000);
+
+	/* Noise thread begins the test */
+	pthread_mutex_lock(&cond_mutex);
+	pthread_cond_broadcast(&cond_var);
+	pthread_mutex_unlock(&cond_mutex);
+
 	for (i = 0; i < 10000; i++) {
 		if (i%100 == 0) {
 			printf("Noise Thread %d loop %d pthread pol %d "\
@@ -197,5 +213,8 @@ int main(int argc, char *argv[])
 	printf("Criteria:Low Priority Thread should Preempt Higher Priority "\
 		"Noise Thread\n");
 
+	pthread_mutex_destroy(&glob_mutex);
+	pthread_mutex_destroy(&cond_mutex);
+	pthread_cond_destroy(&cond_var);
 	return 0;
 }
testcases/realtime/func/pi-tests/testpi-2.c +22 -2
index f0e86ea..55b391b 100644
@@ -31,8 +31,9 @@
  *
  *
  * HISTORY
- *      2010-04-22 Code cleanup by Gowrishankar
- *
+ *      2010-04-22 Code cleanup and thread synchronization changes by using
+ *                 conditional variables,
+ *                 by Gowrishankar([email protected]).
  *
  *****************************************************************************/
 
@@ -76,6 +77,8 @@ int gettid(void)
 
 typedef void *(*entrypoint_t)(void *);
 pthread_mutex_t glob_mutex;
+static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
 
 void *func_lowrt(void *arg)
 {
@@ -90,6 +93,11 @@ void *func_lowrt(void *arg)
 	/* Wait for other RT threads to start up */
 	pthread_barrier_wait(&barrier);
 
+	/* Wait for the high priority noise thread to start and signal us */
+	pthread_mutex_lock(&cond_mutex);
+	pthread_cond_wait(&cond_var, &cond_mutex);
+	pthread_mutex_unlock(&cond_mutex);
+
 	for (i = 0; i < 10000; i++) {
 		if (i%100 == 0) {
 			printf("Thread %d loop %d pthread pol %d pri %d\n",\
@@ -139,6 +147,14 @@ void *func_noise(void *arg)
 		pthr->priority);
 	pthread_barrier_wait(&barrier);
 
+	/* Let others wait at conditional variable */
+	usleep(1000);
+
+	/* Noise thread begins the test */
+	pthread_mutex_lock(&cond_mutex);
+	pthread_cond_broadcast(&cond_var);
+	pthread_mutex_unlock(&cond_mutex);
+
 	for (i = 0; i < 10000; i++) {
 		if (i%100 == 0) {
 			printf("Noise Thread %d loop %d pthread pol %d "\
@@ -197,5 +213,9 @@ int main(int argc, char *argv[])
 	printf("Done\n");
 	printf("Criteria: Low Priority Thread and High Priority Thread "\
 		"should prempt each other multiple times\n");
+
+	pthread_mutex_destroy(&glob_mutex);
+	pthread_mutex_destroy(&cond_mutex);
+	pthread_cond_destroy(&cond_var);
 	return 0;
 }
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list