From: David Xu Date: Mon, 21 Feb 2005 13:47:21 +0000 (+0000) Subject: Set initial thread's stack to 2M on 32 bits platform, 1M for default stack. X-Git-Tag: v2.0.1~8612 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/eddabc992697f5f22d5596980ca5b7f9cec39702 Set initial thread's stack to 2M on 32 bits platform, 1M for default stack. Double the stack sizes on 64 bits platform. --- diff --git a/lib/libthread_xu/thread/thr_attr.c b/lib/libthread_xu/thread/thr_attr.c index 8ffb748de6..f5772e7285 100644 --- a/lib/libthread_xu/thread/thr_attr.c +++ b/lib/libthread_xu/thread/thr_attr.c @@ -93,7 +93,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/lib/libthread_xu/thread/thr_attr.c,v 1.1 2005/02/01 12:38:27 davidxu Exp $ + * $DragonFly: src/lib/libthread_xu/thread/thr_attr.c,v 1.2 2005/02/21 13:47:21 davidxu Exp $ */ #include @@ -321,6 +321,8 @@ _pthread_attr_init(pthread_attr_t *attr) int ret; pthread_attr_t pattr; + _thr_check_init(); + /* Allocate memory for the attribute object: */ if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL) /* Insufficient memory: */ @@ -329,7 +331,6 @@ _pthread_attr_init(pthread_attr_t *attr) /* Initialise the attribute object with the defaults: */ memcpy(pattr, &_pthread_attr_default, sizeof(struct pthread_attr)); - pattr->guardsize_attr = _thr_guard_default; /* Return a pointer to the attribute object: */ *attr = pattr; diff --git a/lib/libthread_xu/thread/thr_init.c b/lib/libthread_xu/thread/thr_init.c index 9710cd602f..7da956772d 100644 --- a/lib/libthread_xu/thread/thr_init.c +++ b/lib/libthread_xu/thread/thr_init.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libpthread/thread/thr_init.c,v 1.66 2004/08/21 11:49:19 davidxu Exp $ - * $DragonFly: src/lib/libthread_xu/thread/thr_init.c,v 1.1 2005/02/01 12:38:27 davidxu Exp $ + * $DragonFly: src/lib/libthread_xu/thread/thr_init.c,v 1.2 2005/02/21 13:47:21 davidxu Exp $ */ /* Allocate space for global thread variables here: */ @@ -320,7 +320,7 @@ init_main_thread(struct pthread *thread) * resource limits, so this stack needs an explicitly mapped * red zone to protect the thread stack that is just beyond. */ - if (mmap((void *)_usrstack - THR_STACK_INITIAL - + if (mmap((void *)_usrstack - _thr_stack_initial - _thr_guard_default, _thr_guard_default, 0, MAP_ANON, -1, 0) == MAP_FAILED) PANIC("Cannot allocate red zone for initial thread"); @@ -334,8 +334,8 @@ init_main_thread(struct pthread *thread) * actually free() it; it just puts it in the free * stack queue for later reuse. */ - thread->attr.stackaddr_attr = (void *)_usrstack - THR_STACK_INITIAL; - thread->attr.stacksize_attr = THR_STACK_INITIAL; + thread->attr.stackaddr_attr = (void *)_usrstack - _thr_stack_initial; + thread->attr.stacksize_attr = _thr_stack_initial; thread->attr.guardsize_attr = _thr_guard_default; thread->attr.flags |= THR_STACK_USER; diff --git a/lib/libthread_xu/thread/thr_private.h b/lib/libthread_xu/thread/thr_private.h index b52fe0429b..9fda6afa83 100644 --- a/lib/libthread_xu/thread/thr_private.h +++ b/lib/libthread_xu/thread/thr_private.h @@ -32,7 +32,7 @@ * Private thread definitions for the uthread kernel. * * $FreeBSD: src/lib/libpthread/thread/thr_private.h,v 1.120 2004/11/01 10:49:34 davidxu Exp $ - * $DragonFly: src/lib/libthread_xu/thread/thr_private.h,v 1.1 2005/02/01 12:38:27 davidxu Exp $ + * $DragonFly: src/lib/libthread_xu/thread/thr_private.h,v 1.2 2005/02/21 13:47:21 davidxu Exp $ */ #ifndef _THR_PRIVATE_H @@ -265,14 +265,14 @@ struct pthread_attr { /* * Miscellaneous definitions. */ -#define THR_STACK_DEFAULT 0x100000 +#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024) /* * Maximum size of initial thread's stack. This perhaps deserves to be larger * than the stacks of other threads, since many applications are likely to run * almost entirely on this stack. */ -#define THR_STACK_INITIAL 0x200000 +#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2) /* * Define the different priority ranges. All applications have thread @@ -644,6 +644,8 @@ SCLASS struct pthread_cond_attr _pthread_condattr_default SCLASS pid_t _thr_pid SCLASS_PRESET(0); SCLASS int _thr_guard_default; +SCLASS int _thr_stack_default SCLASS_PRESET(THR_STACK_DEFAULT); +SCLASS int _thr_stack_initial SCLASS_PRESET(THR_STACK_INITIAL); SCLASS int _thr_page_size; /* Garbage thread count. */ SCLASS int _gc_count SCLASS_PRESET(0); diff --git a/lib/libthread_xu/thread/thr_stack.c b/lib/libthread_xu/thread/thr_stack.c index 927d7350a7..4ac8b6b93c 100644 --- a/lib/libthread_xu/thread/thr_stack.c +++ b/lib/libthread_xu/thread/thr_stack.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libpthread/thread/thr_stack.c,v 1.9 2004/10/06 08:11:07 davidxu Exp $ - * $DragonFly: src/lib/libthread_xu/thread/thr_stack.c,v 1.1 2005/02/01 12:38:27 davidxu Exp $ + * $DragonFly: src/lib/libthread_xu/thread/thr_stack.c,v 1.2 2005/02/21 13:47:21 davidxu Exp $ */ #include #include @@ -79,7 +79,7 @@ static LIST_HEAD(, stack) mstackq = LIST_HEAD_INITIALIZER(mstackq); * | Red Zone (guard page) | red zone for 2nd thread * | | * +-----------------------------------+ - * | stack 2 - PTHREAD_STACK_DEFAULT | top of 2nd thread stack + * | stack 2 - _thr_stack_default | top of 2nd thread stack * | | * | | * | | @@ -90,7 +90,7 @@ static LIST_HEAD(, stack) mstackq = LIST_HEAD_INITIALIZER(mstackq); * | Red Zone | red zone for 1st thread * | | * +-----------------------------------+ - * | stack 1 - PTHREAD_STACK_DEFAULT | top of 1st thread stack + * | stack 1 - _thr_stack_default | top of 1st thread stack * | | * | | * | | @@ -101,7 +101,7 @@ static LIST_HEAD(, stack) mstackq = LIST_HEAD_INITIALIZER(mstackq); * | Red Zone | * | | red zone for main thread * +-----------------------------------+ - * | USRSTACK - PTHREAD_STACK_INITIAL | top of main thread stack + * | USRSTACK - _thr_stack_initial | top of main thread stack * | | ^ * | | | * | | | @@ -188,7 +188,7 @@ _thr_stack_alloc(struct pthread_attr *attr) else { /* Allocate a stack from usrstack. */ if (last_stack == NULL) - last_stack = _usrstack - THR_STACK_INITIAL - + last_stack = _usrstack - _thr_stack_initial - _thr_guard_default; /* Allocate a new stack. */