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
This commit is contained in:
parent
08b2e406c2
commit
f1a4637bd1
@ -331,6 +331,7 @@ CONFIG_NET_RESOLV_ENTRIES=4
|
||||
# Settings for examples/ostest
|
||||
CONFIG_EXAMPLES_OSTEST_LOOPS=1
|
||||
CONFIG_EXAMPLES_OSTEST_STACKSIZE=4096
|
||||
CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=3
|
||||
|
||||
#
|
||||
# Settings for examples/nsh
|
||||
|
@ -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
|
||||
^^^^^^^^^^^^
|
||||
|
@ -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 <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
|
@ -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 <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
@ -47,17 +43,17 @@
|
||||
#include <fcntl.h>
|
||||
#include "ostest.h"
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
|
||||
static FAR char buffer[1024];
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
int dev_null(void)
|
||||
{
|
||||
|
@ -33,10 +33,6 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
@ -48,6 +44,7 @@
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include <nuttx/init.h>
|
||||
|
||||
#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
|
||||
****************************************************************************/
|
||||
|
@ -36,18 +36,41 @@
|
||||
#ifndef __OSTEST_H
|
||||
#define __OSTEST_H
|
||||
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
@ -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 <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user