From 6f83493635cb3507332725d981ac00053414b4ab Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 18 Sep 2008 23:42:12 +0000 Subject: Make number of threads in barrier test configurable git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@935 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/examples/README.txt | 4 ++ nuttx/examples/ostest/barrier.c | 91 +++++++++++++++++++++++++++++----------- nuttx/examples/ostest/cancel.c | 6 +-- nuttx/examples/ostest/dev_null.c | 26 +++++------- nuttx/examples/ostest/main.c | 21 +--------- nuttx/examples/ostest/ostest.h | 31 ++++++++++++-- nuttx/examples/ostest/sighand.c | 6 +-- 7 files changed, 116 insertions(+), 69 deletions(-) (limited to 'nuttx/examples') diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt index d47e5cdc1..0608f9dd4 100644 --- a/nuttx/examples/README.txt +++ b/nuttx/examples/README.txt @@ -26,6 +26,10 @@ examples/ostest zero, the test runs forever. * CONFIG_EXAMPLES_OSTEST_STACKSIZE Used to create the ostest task. Default is 8192. + * CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS + Specifies the number of threads to create in the barrier + test. The default is 8 but a smaller number may be needed on + systems without sufficient memory to start so many threads. examples/nsh ^^^^^^^^^^^^ diff --git a/nuttx/examples/ostest/barrier.c b/nuttx/examples/ostest/barrier.c index 2b6755c9d..6b33ac0e3 100644 --- a/nuttx/examples/ostest/barrier.c +++ b/nuttx/examples/ostest/barrier.c @@ -1,7 +1,7 @@ -/*********************************************************************** - * barrier.c +/**************************************************************************** + * examples/ostest/barrier.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,18 +31,37 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ***********************************************************************/ + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include #include #include #include + #include "ostest.h" -#define NBARRIER_THREADS 8 +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ static pthread_barrier_t barrier; +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: barrier_func + ****************************************************************************/ + static void *barrier_func(void *parameter) { int id = (int)parameter; @@ -55,19 +74,25 @@ static void *barrier_func(void *parameter) /* Wait at the barrier until all threads are synchronized. */ - printf("barrier_func: Thread %d calling pthread_barrier_wait()\n", id); + printf("barrier_func: Thread %d calling pthread_barrier_wait()\n", + id); status = pthread_barrier_wait(&barrier); if (status == 0) { - printf("barrier_func: Thread %d, back with status=0 (I am not special)\n", id, status); + printf("barrier_func: Thread %d, back with " + "status=0 (I am not special)\n", + id, status); } else if (status == PTHREAD_BARRIER_SERIAL_THREAD) { - printf("barrier_func: Thread %d, back with status=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)\n", id, status); + printf("barrier_func: Thread %d, back with " + "status=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)\n", + id, status); } else { - printf("barrier_func: ERROR thread %d could not get semaphore value\n", id); + printf("barrier_func: ERROR thread %d could not get semaphore value\n", + id); } #ifndef CONFIG_DISABLE_SIGNALS @@ -77,9 +102,17 @@ static void *barrier_func(void *parameter) return NULL; } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: barrier_test + ****************************************************************************/ + void barrier_test(void) { - pthread_t barrier_thread[NBARRIER_THREADS]; + pthread_t barrier_thread[CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS]; pthread_addr_t result; pthread_attr_t attr; pthread_barrierattr_t barrierattr; @@ -91,33 +124,39 @@ void barrier_test(void) status = pthread_barrierattr_init(&barrierattr); if (status != OK) { - printf("barrier_test: pthread_barrierattr_init failed, status=%d\n", status); + printf("barrier_test: pthread_barrierattr_init failed, status=%d\n", + status); } - status = pthread_barrier_init(&barrier, &barrierattr, NBARRIER_THREADS); + status = pthread_barrier_init(&barrier, &barrierattr, + CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS); if (status != OK) { - printf("barrier_test: pthread_barrierattr_init failed, status=%d\n", status); + printf("barrier_test: pthread_barrierattr_init failed, status=%d\n", + status); } /* Create the barrier */ status = pthread_barrierattr_init(&barrierattr); - /* Start NBARRIER_THREADS thread instances */ + /* Start CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS thread instances */ status = pthread_attr_init(&attr); if (status != OK) { - printf("barrier_test: pthread_attr_init failed, status=%d\n", status); + printf("barrier_test: pthread_attr_init failed, status=%d\n", + status); } - for (i = 0; i < NBARRIER_THREADS; i++) + for (i = 0; i < CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS; i++) { - status = pthread_create(&barrier_thread[i], &attr, barrier_func, (pthread_addr_t)i); + status = pthread_create(&barrier_thread[i], &attr, barrier_func, + (pthread_addr_t)i); if (status != 0) { - printf("barrier_test: Error in thread %d create, status=%d\n", i, status); + printf("barrier_test: Error in thread %d create, status=%d\n", + i, status); } else { @@ -127,16 +166,18 @@ void barrier_test(void) /* Wait for all thread instances to complete */ - for (i = 0; i < NBARRIER_THREADS; i++) + for (i = 0; i < CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS; i++) { status = pthread_join(barrier_thread[i], &result); if (status != 0) { - printf("barrier_test: Error in thread %d join, status=%d\n", i, status); + printf("barrier_test: Error in thread %d join, status=%d\n", + i, status); } else { - printf("barrier_test: Thread %d completed with result=%p\n", i, result); + printf("barrier_test: Thread %d completed with result=%p\n", + i, result); } } @@ -145,12 +186,14 @@ void barrier_test(void) status = pthread_barrier_destroy(&barrier); if (status != OK) { - printf("barrier_test: pthread_barrier_destroy failed, status=%d\n", status); + printf("barrier_test: pthread_barrier_destroy failed, status=%d\n", + status); } status = pthread_barrierattr_destroy(&barrierattr); if (status != OK) { - printf("barrier_test: pthread_barrierattr_destroy failed, status=%d\n", status); + printf("barrier_test: pthread_barrierattr_destroy failed, status=%d\n", + status); } } diff --git a/nuttx/examples/ostest/cancel.c b/nuttx/examples/ostest/cancel.c index 4af1b86fb..193b2fbda 100644 --- a/nuttx/examples/ostest/cancel.c +++ b/nuttx/examples/ostest/cancel.c @@ -1,7 +1,7 @@ /*********************************************************************** - * cancel.c + * examples/ostest/cancel.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/nuttx/examples/ostest/dev_null.c b/nuttx/examples/ostest/dev_null.c index 57776b495..e8fc6cf3f 100644 --- a/nuttx/examples/ostest/dev_null.c +++ b/nuttx/examples/ostest/dev_null.c @@ -1,7 +1,7 @@ -/************************************************************ - * dev_null.c +/**************************************************************************** + * examples/ostest/dev_null.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,15 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include @@ -47,17 +43,17 @@ #include #include "ostest.h" -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ + ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 static FAR char buffer[1024]; -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ int dev_null(void) { diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c index bb12b49ce..5f7683be6 100644 --- a/nuttx/examples/ostest/main.c +++ b/nuttx/examples/ostest/main.c @@ -33,10 +33,6 @@ * ****************************************************************************/ -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - /**************************************************************************** * Included Files ****************************************************************************/ @@ -48,6 +44,7 @@ #include #include #include + #include "ostest.h" /**************************************************************************** @@ -57,22 +54,6 @@ #define PRIORITY 100 #define NARGS 4 -/* The task_create task size can be specified in the defconfig file */ - -#ifdef CONFIG_EXAMPLES_OSTEST_STACKSIZE -# define STACKSIZE CONFIG_EXAMPLES_OSTEST_STACKSIZE -#else -# define STACKSIZE 8192 -#endif - -/* The number of times to execute the test can be specified in the defconfig - * file. - */ - -#ifndef CONFIG_EXAMPLES_OSTEST_LOOPS -# define CONFIG_EXAMPLES_OSTEST_LOOPS 1 -#endif - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/nuttx/examples/ostest/ostest.h b/nuttx/examples/ostest/ostest.h index 08396b3ff..c94412cc1 100644 --- a/nuttx/examples/ostest/ostest.h +++ b/nuttx/examples/ostest/ostest.h @@ -36,18 +36,41 @@ #ifndef __OSTEST_H #define __OSTEST_H -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - /**************************************************************************** * Included Files ****************************************************************************/ +#include + /**************************************************************************** * Definitions ****************************************************************************/ +/* The task_create task size can be specified in the defconfig file */ + +#ifdef CONFIG_EXAMPLES_OSTEST_STACKSIZE +# define STACKSIZE CONFIG_EXAMPLES_OSTEST_STACKSIZE +#else +# define STACKSIZE 8192 +#endif + +/* The number of times to execute the test can be specified in the defconfig + * file. + */ + +#ifndef CONFIG_EXAMPLES_OSTEST_LOOPS +# define CONFIG_EXAMPLES_OSTEST_LOOPS 1 +#endif + +/* This is the number of threads that are created in the barrier test. + * A smaller number should be selected on systems without sufficient memory + * to start so many threads. + */ + +#ifndef CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS +# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8 +#endif + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/nuttx/examples/ostest/sighand.c b/nuttx/examples/ostest/sighand.c index 64b550458..223761f1f 100644 --- a/nuttx/examples/ostest/sighand.c +++ b/nuttx/examples/ostest/sighand.c @@ -1,7 +1,7 @@ /*********************************************************************** - * sighand.c + * examples/ostest/sighand.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * -- cgit v1.2.3