Make usermode stacksize (-s) configurable at compile-time
PATCH 1/1 Make usermode stacksize (-s) configurable at compile-time
Hi !
We encontered problems with the low default value for the stacksize in usermode (ok, whats "low"). For environments like scratchbox, its hard to use "-s" as qemu is called by binfmt mechanism. The attached patch makes this configurable at compile-time.
configure +11 -0
@@ -220,6 +220,7 @@ uname_release="" io_thread="no" mixemu="no" kerneldir="" +user_mode_stacksize="" aix="no" blobs="yes" pkgversion=""
@@ -557,6 +558,8 @@ for opt do ;; --kerneldir=*) kerneldir="$optarg" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --with-pkgversion=*) pkgversion=" ($optarg)" ;; --disable-docs) docs="no"
@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support" echo " --enable-io-thread enable IO thread" echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH" +echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2576,3 +2580,10 @@ d=libuser mkdir -p $d rm -f $d/Makefile ln -s $source_path/Makefile.user $d/Makefile + +# change default stacksize in usermode +# +if test "$user_mode_stacksize" != "" ; then + echo "user_mode_stack $user_mode_stacksize" + echo "QEMU_CFLAGS+=-DUSER_MODE_STACKSIZE=$user_mode_stacksize" >> $config_host_mak +fi
linux-user/main.c +4 -0
@@ -51,7 +51,11 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ +#if defined(USER_MODE_STACKSIZE ) +unsigned long x86_stack_size =USER_MODE_STACKSIZE ; +#else unsigned long x86_stack_size =512 *1024 ; +#endif void gemu_log (const char *fmt, ...) {
configure +11 -0
@@ -220,6 +220,7 @@ uname_release="" io_thread="no" mixemu="no" kerneldir="" +user_mode_stacksize="" aix="no" blobs="yes" pkgversion=""
@@ -557,6 +558,8 @@ for opt do ;; --kerneldir=*) kerneldir="$optarg" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --with-pkgversion=*) pkgversion=" ($optarg)" ;; --disable-docs) docs="no"
@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support" echo " --enable-io-thread enable IO thread" echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH" +echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2576,3 +2580,10 @@ d=libuser mkdir -p $d rm -f $d/Makefile ln -s $source_path/Makefile.user $d/Makefile + +# change default stacksize in usermode +# +if test "$user_mode_stacksize" != "" ; then + echo "user_mode_stack $user_mode_stacksize" + echo "QEMU_CFLAGS+=-DUSER_MODE_STACKSIZE=$user_mode_stacksize" >> $config_host_mak +fi
linux-user/main.c +4 -0
@@ -51,7 +51,11 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ +#if defined(USER_MODE_STACKSIZE ) +unsigned long x86_stack_size =USER_MODE_STACKSIZE ; +#else unsigned long x86_stack_size =512 *1024 ; +#endif void gemu_log (const char *fmt, ...) {
2009/10/25 Jan-Simon Möller <[email protected]>:
Quoted 42 lines
Hi !
We encontered problems with the low default value for the stacksize in usermode (ok, whats "low"). For environments like scratchbox, its hard to use "-s" as qemu is called by binfmt mechanism. The attached patch makes this configurable at compile-time.
Signed-off-by Jan-Simon Möller <[email protected]>configure +0
-0@@ -220,6 +220,7 @@ uname_release=""io_thread="no"
mixemu="no"
kerneldir=""
+user_mode_stacksize=""
aix="no"
blobs="yes"
pkgversion=""configure +0
-0@@ -557,6 +558,8 @@ for opt do ;;--kerneldir=*) kerneldir="$optarg"
;;
+ --user-mode-stacksize=*) user_mode_stacksize="$optarg"
+ ;;
--with-pkgversion=*) pkgversion=" ($optarg)" ;;
--disable-docs) docs="no"configure +0
-0@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support"echo " --enable-io-thread enable IO thread"
echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH"
+echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo ""
echo "NOTE: The object files are built at the place where configure is launched" exit 1configure +0
-0@@ -2576,3 +2580,10 @@ d=libusermkdir -p $d
rm -f $d/Makefile
ln -s $source_path/Makefile.user $d/Makefile
configure d=libuser · line 2589
Quoted 7 lines
configure +7
-0+ +# change default stacksize in usermode +# +if test "$user_mode_stacksize" != "" ; then + echo "user_mode_stack $user_mode_stacksize" + echo "QEMU_CFLAGS+=-DUSER_MODE_STACKSIZE=$user_mode_stacksize" >> $config_host_mak +fi
Wouldn't it be better to set this earlier only if target_user_only is set to yes and use cflags?
Something like this:
if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != ""; then
cflags="-DUSER_MODE_STACKSIZE $cflags"
fi
just after the test for pie (line 2478) for instance.
The informative echo should go with the others (line 1853).
Quoted 11 lines
linux-user/main.c +0
-0@@ -51,7 +51,11 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE; /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, sowe allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */
linux-user/main.c +3
-0+#if defined(USER_MODE_STACKSIZE ) +unsigned long x86_stack_size =USER_MODE_STACKSIZE ; +#else
Quoted 2 lines
unsigned long
x86_stack_size= 512 * 1024;
+#endif
I'd prefer:
#ifndef USER_MODE_STACKSIZE
#define x86_stack_size (512 * 1024)
#endif
unsigned long x86_stack_size = USER_MODE_STACKSIZE;
Laurent
Quoted 4 lines
void
gemu_log(const char *fmt, ...)
{
Am Sonntag 25 Oktober 2009 16:54:16 schrieb Laurent Desnogues:
Quoted 10 lines
Wouldn't it be better to set this earlier only if
target_user_onlyis set to yes and use cflags?Something like this:
if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != ""; then
cflags="-DUSER_MODE_STACKSIZE $cflags"
fijust after the test for pie (line 2478) for instance.
Done.
Quoted 1 line
The informative echo should go with the others (line 1853).
Its not clear at this stage, if its "default" or the cmdline value, as $target_user_only isn't evaluated until line 2171 .
I'd leave therefore the echo in line 2491.
Quoted 9 lines
I'd prefer:
#ifndef
USER_MODE_STACKSIZE
#definex86_stack_size(512 * 1024)
#endif
unsigned longx86_stack_size=USER_MODE_STACKSIZE;
You mean probably?
#ifndef USER_MODE_STACKSIZE
#define USER_MODE_STACKSIZE (512 * 1024) #endif
unsigned long x86_stack_size = USER_MODE_STACKSIZE;
Done.
Patch will follow in next mail as reply.
Tnx and have phun !
Jan-Simon
We encontered problems with the low default value for the stacksize in usermode (ok, whats "low"). For environments like scratchbox, its hard to use "-s" as qemu is called by binfmt mechanism. The attached patch makes this configurable at compile-time.
configure +14 -0
@@ -220,6 +220,7 @@ uname_release="" io_thread="no" mixemu="no" kerneldir="" +user_mode_stacksize="" aix="no" blobs="yes" pkgversion=""
@@ -557,6 +558,8 @@ for opt do ;; --kerneldir=*) kerneldir="$optarg" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --with-pkgversion=*) pkgversion=" ($optarg)" ;; --disable-docs) docs="no"
@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support" echo " --enable-io-thread enable IO thread" echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH" +echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2481,6 +2485,16 @@ if test "$target_user_only" = "yes" -a "$static" = "no" -a \ ldflags="-pie $ldflags" fi +# change default stacksize in usermode +# +if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != "" ; then + cflags="-DUSER_MODE_STACKSIZE=$user_mode_stacksize $cflags" + echo "user_mode_stack $user_mode_stacksize" +else + echo "user_mode_stack default" +fi + + if test "$target_softmmu" = "yes" -a \( \ "$TARGET_ARCH" = "microblaze" -o \ "$TARGET_ARCH" = "cris" \) ; then
linux-user/main.c +4 -1
@@ -51,7 +51,10 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size =512 *1024 ; +#ifndef USER_MODE_STACKSIZE +#define USER_MODE_STACKSIZE (512 * 1024) +#endif +unsigned long x86_stack_size =USER_MODE_STACKSIZE ;void gemu_log (const char *fmt, ...) {
configure +14 -0
@@ -220,6 +220,7 @@ uname_release="" io_thread="no" mixemu="no" kerneldir="" +user_mode_stacksize="" aix="no" blobs="yes" pkgversion=""
@@ -557,6 +558,8 @@ for opt do ;; --kerneldir=*) kerneldir="$optarg" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --with-pkgversion=*) pkgversion=" ($optarg)" ;; --disable-docs) docs="no"
@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support" echo " --enable-io-thread enable IO thread" echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH" +echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2481,6 +2485,16 @@ if test "$target_user_only" = "yes" -a "$static" = "no" -a \ ldflags="-pie $ldflags" fi +# change default stacksize in usermode +# +if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != "" ; then + cflags="-DUSER_MODE_STACKSIZE=$user_mode_stacksize $cflags" + echo "user_mode_stack $user_mode_stacksize" +else + echo "user_mode_stack default" +fi + + if test "$target_softmmu" = "yes" -a \( \ "$TARGET_ARCH" = "microblaze" -o \ "$TARGET_ARCH" = "cris" \) ; then
linux-user/main.c +4 -1
@@ -51,7 +51,10 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size =512 *1024 ; +#ifndef USER_MODE_STACKSIZE +#define USER_MODE_STACKSIZE (512 * 1024) +#endif +unsigned long x86_stack_size =USER_MODE_STACKSIZE ;void gemu_log (const char *fmt, ...) {
Review if test "$target_user_only" = "yes" -a "$static" = "no" -a \ · line 2492
Quoted 9 lines · Jan-Simon Möller
(quoted diff) +5
-0@@ -2481,6 +2485,16 @@ if test "$target_user_only" = "yes" -a "$static" = "no" -a \ ldflags="-pie $ldflags" fi +# change default stacksize in usermode +# +if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != "" ; then + cflags="-DUSER_MODE_STACKSIZE=$user_mode_stacksize $cflags" + echo "user_mode_stack $user_mode_stacksize"
Put this line together with:
echo "PIE user targets $user_pie"
Quoted 13 lines
(quoted diff) +5
-0+else + echo "user_mode_stack default" +fi + + if test "$target_softmmu" = "yes" -a \( \ "$TARGET_ARCH" = "microblaze" -o \ "$TARGET_ARCH" = "cris" \) ; thenlinux-user/main.c +0
-0
linux-user/main.c const char *qemu_uname_release = CONFIG_UNAME_RELEASE; · line 56
Quoted 7 lines
linux-user/main.c +3
-1@@ -51,7 +51,10 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size =512 *1024 ; +#ifndef USER_MODE_STACKSIZE +#define USER_MODE_STACKSIZE (512 * 1024) +#endif
If we are changing the code in configure anyways, why don't add the default there?
Something like this (I tested that it compiled, but didn't tested usermode). I am assuming that you only want it for linux-user.
Quoted 1 line
From
0dc910f5d1b2e1dd7120abf32d25db190cd394e5Mon Sep 17 00:00:00 2001
From: Juan Quintela <[email protected]>
Date: Sun, 25 Oct 2009 22:06:52 +0100
Subject: [PATCH] User mode stacksize implementation
--- configure | 5 +++++ linux-user/main.c | 2 +- 2 files changed, 6 insertions(+), 1 deletions(-)
configure +5 -0
@@ -225,6 +225,7 @@ blobs="yes" pkgversion="" check_utests="no" user_pie="no" +user_mode_stacksize="512*1024" # OS specific if check_define __linux__ ; then
@@ -517,6 +518,8 @@ for opt do ;; --disable-user-pie) user_pie="no" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --enable-uname-release=*) uname_release="$optarg" ;; --sparc_cpu=*)
@@ -1841,6 +1844,7 @@ echo "uname -r $uname_release" echo "NPTL support $nptl" echo "GUEST_BASE $guest_base" echo "PIE user targets $user_pie" +echo "User mode stacksize $user_mode_stacksize" echo "vde support $vde" echo "IO thread $io_thread" echo "Linux AIO support $linux_aio"
@@ -2361,6 +2365,7 @@ if test "$target_user_only" = "yes" ; then fi if test "$target_linux_user" = "yes" ; then echo "CONFIG_LINUX_USER=y" >> $config_target_mak + echo "CONFIG_USER_MODE_STACKSIZE=$user_mode_stacksize" >> $config_target_mak fi if test "$target_darwin_user" = "yes" ; then echo "CONFIG_DARWIN_USER=y" >> $config_target_mak
linux-user/main.c +1 -1
@@ -51,7 +51,7 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size =512 *1024 ; +unsigned long x86_stack_size =CONFIG_USER_MODE_STACKSIZE ;void gemu_log (const char *fmt, ...) {
Signature · 1 line
1.6.2.5
Am Sonntag 25 Oktober 2009 22:09:10 schrieb Juan Quintela:
Quoted 5 lines
If we are changing the code in configure anyways, why don't add the default there?
Something like this (I tested that it compiled, but didn't tested usermode). I am assuming that you only want it for linux-user.
I like this version.
Quoted 6 lines
Quoted 2 lines
From
0dc910f5d1b2e1dd7120abf32d25db190cd394e5Mon Sep 17 00:00:00 2001From: Juan Quintela <[email protected]>
Date: Sun, 25 Oct 2009 22:06:52 +0100
Subject: [PATCH] User mode stacksize implementation
Best,
Jan-Simon
Quoted 3 lines · Jan-Simon Möller
We encontered problems with the low default value for the stacksize in usermode (ok, whats "low"). For environments like scratchbox, its hard to use "-s" as qemu is called by binfmt mechanism. The attached patch makes this configurable at compile-time.
Note, this will only change the stack size for the main thread, at least with LinuxThreads. Other thread stacks are allocated by the pthread (LinuxThreads or NPTL), and their stack size is changed by pthread_attr_setstacksize instead.
-- Jamie
Quoted 3 lines · Jan-Simon Möller
We encontered problems with the low default value for the stacksize in usermode (ok, whats "low"). For environments like scratchbox, its hard to use "-s" as qemu is called by binfmt mechanism. The attached patch makes this configurable at compile-time.
fwiw in scratchbox we have a wrapper in between binfmt and qemu (called misc_runner) that sets any necessary command line parameters for qemu. You might want to consider a similar approach so we don't need to add a configure option (and thus hardcode the setting) to qemu for every command line option that might need changing.
Quoted 128 lines
Signed-off-by Jan-Simon Möller <[email protected]>configure +14
-0@@ -220,6 +220,7 @@ uname_release="" io_thread="no" mixemu="no" kerneldir="" +user_mode_stacksize="" aix="no" blobs="yes" pkgversion=""@@ -557,6 +558,8 @@ for opt do ;; --kerneldir=*) kerneldir="$optarg" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --with-pkgversion=*) pkgversion=" ($optarg)" ;; --disable-docs) docs="no"@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support" echo " --enable-io-thread enable IO thread" echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH" +echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1@@ -2481,6 +2485,16 @@ if test "$target_user_only" = "yes" -a "$static" = "no" -a \ ldflags="-pie $ldflags" fi +# change default stacksize in usermode +# +if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != "" ; then + cflags="-DUSER_MODE_STACKSIZE=$user_mode_stacksize $cflags" + echo "user_mode_stack $user_mode_stacksize" +else + echo "user_mode_stack default" +fi + + if test "$target_softmmu" = "yes" -a \( \ "$TARGET_ARCH" = "microblaze" -o \ "$TARGET_ARCH" = "cris" \) ; thenlinux-user/main.c +4
-1@@ -51,7 +51,10 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size =512 *1024 ; +#ifndef USER_MODE_STACKSIZE +#define USER_MODE_STACKSIZE (512 * 1024) +#endif +unsigned long x86_stack_size =USER_MODE_STACKSIZE ;void gemu_log (const char *fmt, ...) {configure +14
-0@@ -220,6 +220,7 @@ uname_release="" io_thread="no" mixemu="no" kerneldir="" +user_mode_stacksize="" aix="no" blobs="yes" pkgversion=""@@ -557,6 +558,8 @@ for opt do ;; --kerneldir=*) kerneldir="$optarg" ;; + --user-mode-stacksize=*) user_mode_stacksize="$optarg" + ;; --with-pkgversion=*) pkgversion=" ($optarg)" ;; --disable-docs) docs="no"@@ -713,6 +716,7 @@ echo " --enable-linux-aio enable Linux AIO support" echo " --enable-io-thread enable IO thread" echo " --disable-blobs disable installing provided firmware blobs" echo " --kerneldir=PATH look for kernel includes in PATH" +echo " --user-mode-stacksize= set default stack size in bytes (as -s, only in usermode)" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1@@ -2481,6 +2485,16 @@ if test "$target_user_only" = "yes" -a "$static" = "no" -a \ ldflags="-pie $ldflags" fi +# change default stacksize in usermode +# +if test "$target_user_only" = "yes" -a "$user_mode_stacksize" != "" ; then + cflags="-DUSER_MODE_STACKSIZE=$user_mode_stacksize $cflags" + echo "user_mode_stack $user_mode_stacksize" +else + echo "user_mode_stack default" +fi + + if test "$target_softmmu" = "yes" -a \( \ "$TARGET_ARCH" = "microblaze" -o \ "$TARGET_ARCH" = "cris" \) ; thenlinux-user/main.c +4
-1@@ -51,7 +51,10 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */ -unsigned long x86_stack_size =512 *1024 ; +#ifndef USER_MODE_STACKSIZE +#define USER_MODE_STACKSIZE (512 * 1024) +#endif +unsigned long x86_stack_size =USER_MODE_STACKSIZE ;void gemu_log (const char *fmt, ...) {
Quoted 6 lines
Quoted 1 line
The attached patch makes this configurable at compile-time.
fwiw in scratchbox we have a wrapper in between binfmt and qemu (called
misc_runner) that sets any necessary command line parameters for qemu. You might want to consider a similar approach so we don't need to add a configure option (and thus hardcode the setting) to qemu for every command line option that might need changing.
I got your point. But OTOH I just make the default configurable.
IMHO this leads to:
* add an (optional) config-file for the usermode to overwrite defaults or
* extend and generalize the wrapper and use it in binfmt instead of qemu directly
Let me sleep over it a bit - for now: other opinions ?
Best,
Jan-Simon