summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authormarcus <marcus@FreeBSD.org>2005-03-06 07:56:18 +0000
committermarcus <marcus@FreeBSD.org>2005-03-06 07:56:18 +0000
commita424dc9347b4199bfc24854e05adef230b855449 (patch)
treebf55900895a5847c1f4598e2931ce955b402e7b7 /lib/libthr
parentd9a2f9579c8605dc4edb21456e19448dce44f346 (diff)
downloadFreeBSD-src-a424dc9347b4199bfc24854e05adef230b855449.zip
FreeBSD-src-a424dc9347b4199bfc24854e05adef230b855449.tar.gz
Increase the default stacksizes:
32-bit 64-bit main thread 2 MB 4 MB other threads 1 MB 2 MB Approved by: mtm Adapted from: libpthread
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_init.c22
-rw-r--r--lib/libthr/thread/thr_private.h12
-rw-r--r--lib/libthr/thread/thr_stack.c12
3 files changed, 31 insertions, 15 deletions
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 3291738..45d238c 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -154,6 +154,8 @@ static void *libgcc_references[] = {
int _pthread_guard_default;
int _pthread_page_size;
+int _pthread_stack_default;
+int _pthread_stack_initial;
/*
* Initialize the current thread.
@@ -252,9 +254,17 @@ _thread_init(void)
_pthread_page_size = getpagesize();
_pthread_guard_default = getpagesize();
-
- pthread_attr_default.guardsize_attr = _pthread_guard_default;
+ if (sizeof(void *) == 8) {
+ _pthread_stack_default = PTHREAD_STACK64_DEFAULT;
+ _pthread_stack_initial = PTHREAD_STACK64_INITIAL;
+ }
+ else {
+ _pthread_stack_default = PTHREAD_STACK32_DEFAULT;
+ _pthread_stack_initial = PTHREAD_STACK32_INITIAL;
+ }
+ pthread_attr_default.guardsize_attr = _pthread_guard_default;
+ pthread_attr_default.stacksize_attr = _pthread_stack_default;
/*
* Make gcc quiescent about {,libgcc_}references not being
@@ -317,22 +327,22 @@ _thread_init(void)
* this stack needs an explicitly mapped red zone to protect the
* thread stack that is just beyond.
*/
- if (mmap(_usrstack - PTHREAD_STACK_INITIAL -
+ if (mmap(_usrstack - _pthread_stack_initial -
_pthread_guard_default, _pthread_guard_default, 0,
MAP_ANON, -1, 0) == MAP_FAILED)
PANIC("Cannot allocate red zone for initial thread");
/* Set the main thread stack pointer. */
- pthread->stack = _usrstack - PTHREAD_STACK_INITIAL;
+ pthread->stack = _usrstack - _pthread_stack_initial;
/* Set the stack attributes. */
pthread->attr.stackaddr_attr = pthread->stack;
- pthread->attr.stacksize_attr = PTHREAD_STACK_INITIAL;
+ pthread->attr.stacksize_attr = _pthread_stack_initial;
/* Setup the context for initial thread. */
getcontext(&pthread->ctx);
pthread->ctx.uc_stack.ss_sp = pthread->stack;
- pthread->ctx.uc_stack.ss_size = PTHREAD_STACK_INITIAL;
+ pthread->ctx.uc_stack.ss_size = _pthread_stack_initial;
/* Initialize the atfork list and mutex */
TAILQ_INIT(&_atfork_list);
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 47183d7..c6ddb79 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -305,7 +305,8 @@ struct pthread_attr {
/*
* Miscellaneous definitions.
*/
-#define PTHREAD_STACK_DEFAULT 65536
+#define PTHREAD_STACK32_DEFAULT (1 * 1024 * 1024)
+#define PTHREAD_STACK64_DEFAULT (2 * 1024 * 1024)
/*
* Size of default red zone at the end of each stack. In actuality, this "red
* zone" is merely an unmapped region, except in the case of the initial stack.
@@ -318,12 +319,17 @@ extern int _pthread_guard_default;
extern int _pthread_page_size;
+extern int _pthread_stack_default;
+
+extern int _pthread_stack_initial;
+
/*
* 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 PTHREAD_STACK_INITIAL 0x100000
+#define PTHREAD_STACK32_INITIAL (2 * 1024 * 1024)
+#define PTHREAD_STACK64_INITIAL (4 * 1024 * 1024)
/*
* Define the different priority ranges. All applications have thread
@@ -711,7 +717,7 @@ SCLASS struct pthread_attr pthread_attr_default
#ifdef GLOBAL_PTHREAD_PRIVATE
= { SCHED_RR, 0, TIMESLICE_USEC, PTHREAD_DEFAULT_PRIORITY,
PTHREAD_CREATE_RUNNING, PTHREAD_CREATE_JOINABLE, NULL, NULL, NULL,
- PTHREAD_STACK_DEFAULT, -1 };
+ -1, -1 };
#else
;
#endif
diff --git a/lib/libthr/thread/thr_stack.c b/lib/libthr/thread/thr_stack.c
index 2b6ba8e..bd82157 100644
--- a/lib/libthr/thread/thr_stack.c
+++ b/lib/libthr/thread/thr_stack.c
@@ -78,7 +78,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 - _pthread_stack_default | top of 2nd thread stack
* | |
* | |
* | |
@@ -89,7 +89,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 - _pthread_stack_default | top of 1st thread stack
* | |
* | |
* | |
@@ -100,7 +100,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 - _pthread_stack_initial | top of main thread stack
* | | ^
* | | |
* | | |
@@ -137,7 +137,7 @@ _thread_stack_alloc(size_t stacksize, size_t guardsize)
* If the stack and guard sizes are default, try to allocate a stack
* from the default-size stack cache:
*/
- if (stack_size == PTHREAD_STACK_DEFAULT &&
+ if (stack_size == _pthread_stack_default &&
guardsize == _pthread_guard_default) {
/*
* Use the garbage collector mutex for synchronization of the
@@ -183,7 +183,7 @@ _thread_stack_alloc(size_t stacksize, size_t guardsize)
if (stack == NULL) {
if (last_stack == NULL)
- last_stack = _usrstack - PTHREAD_STACK_INITIAL -
+ last_stack = _usrstack - _pthread_stack_initial -
_pthread_guard_default;
/* Allocate a new stack. */
@@ -224,7 +224,7 @@ _thread_stack_free(void *stack, size_t stacksize, size_t guardsize)
spare_stack->guardsize = guardsize;
spare_stack->stackaddr = stack;
- if (spare_stack->stacksize == PTHREAD_STACK_DEFAULT &&
+ if (spare_stack->stacksize == _pthread_stack_default &&
spare_stack->guardsize == _pthread_guard_default) {
/* Default stack/guard size. */
LIST_INSERT_HEAD(&_dstackq, spare_stack, qe);
OpenPOWER on IntegriCloud