qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] linux-user: bigger default stack


From: Riku Voipio
Subject: [Qemu-devel] [PATCH] linux-user: bigger default stack
Date: Thu, 3 Mar 2011 17:37:37 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

PTHREAD_STACK_MIN (16KB) is somewhat inadequate for a new stack. follow
the pthread_create defaults, ie setting to RLIMIT_STACK or if unlimited
to 2MB.

Signed-off-by: Riku Voipio <address@hidden>
---
 linux-user/syscall.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 23d7a63..99484ce 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3692,8 +3692,6 @@ static abi_long do_arch_prctl(CPUX86State *env, int code, 
abi_ulong addr)
 
 #if defined(CONFIG_USE_NPTL)
 
-#define NEW_STACK_SIZE PTHREAD_STACK_MIN
-
 static pthread_mutex_t clone_lock = PTHREAD_MUTEX_INITIALIZER;
 typedef struct {
     CPUState *env;
@@ -3738,7 +3736,6 @@ static void *clone_func(void *arg)
 #else
 /* this stack is the equivalent of the kernel stack associated with a
    thread/process */
-#define NEW_STACK_SIZE 8192
 
 static int clone_func(void *arg)
 {
@@ -3749,6 +3746,22 @@ static int clone_func(void *arg)
 }
 #endif
 
+#define DEFAULT_STACK_SIZE 0x200000
+
+static long get_new_stack_size(void)
+{
+    struct rlimit limit;
+    if ((getrlimit(RLIMIT_STACK, &limit) == 0) &&
+        (limit.rlim_cur != RLIM_INFINITY)) {
+        return limit.rlim_cur;
+    }
+#if defined(CONFIG_USE_NPTL)
+    return DEFAULT_STACK_SIZE > PTHREAD_STACK_MIN ? DEFAULT_STACK_SIZE : 
PTHREAD_STACK_MIN;
+#else
+    return DEFAULT_STACK_SIZE;
+#endif
+}
+
 /* do_fork() Must return host values and target errnos (unlike most
    do_*() functions). */
 static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,
@@ -3775,6 +3788,7 @@ static int do_fork(CPUState *env, unsigned int flags, 
abi_ulong newsp,
         new_thread_info info;
         pthread_attr_t attr;
 #endif
+        long new_stack_size = get_new_stack_size();
         ts = qemu_mallocz(sizeof(TaskState));
         init_task_state(ts);
         /* we create a new CPU instance. */
@@ -3812,7 +3826,7 @@ static int do_fork(CPUState *env, unsigned int flags, 
abi_ulong newsp,
             info.parent_tidptr = parent_tidptr;
 
         ret = pthread_attr_init(&attr);
-        ret = pthread_attr_setstacksize(&attr, NEW_STACK_SIZE);
+        ret = pthread_attr_setstacksize(&attr, new_stack_size);
         ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
         /* It is not safe to deliver signals until the child has finished
            initializing, so temporarily block all signals.  */
@@ -3841,11 +3855,11 @@ static int do_fork(CPUState *env, unsigned int flags, 
abi_ulong newsp,
         if (flags & CLONE_NPTL_FLAGS2)
             return -EINVAL;
         /* This is probably going to die very quickly, but do it anyway.  */
-        new_stack = qemu_mallocz (NEW_STACK_SIZE);
+        new_stack = qemu_mallocz (new_stack_size);
 #ifdef __ia64__
-        ret = __clone2(clone_func, new_stack, NEW_STACK_SIZE, flags, new_env);
+        ret = __clone2(clone_func, new_stack, new_stack_size, flags, new_env);
 #else
-       ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
+        ret = clone(clone_func, new_stack + new_stack_size, flags, new_env);
 #endif
 #endif
     } else {
-- 
1.7.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]