support: Add use_stack_min option to support_small_thread_stack_size

It allows it to return PTHREAD_STACK_MIN if defined.

Checked on x86_64-linux-gnu and with a build for i686-gnu.

Suggested-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
This commit is contained in:
Adhemerval Zanella
2026-05-20 11:49:09 -03:00
parent 4e3489bd2a
commit f86b51dd6a
9 changed files with 24 additions and 22 deletions
+1 -6
View File
@@ -51,12 +51,7 @@ static int
do_test (void)
{
char *path = xasprintf ("%s/elf/tst-bz26577-mod.so", support_objdir_root);
size_t stacksize =
#ifdef PTHREAD_STACK_MIN
PTHREAD_STACK_MIN;
#else
support_small_thread_stack_size ();
#endif
size_t stacksize = support_small_thread_stack_size (true);
pthread_attr_t attr;
xpthread_attr_init (&attr);
+1 -1
View File
@@ -128,7 +128,7 @@ do_test_threads (bool set_guard)
{
pthread_attr_t attr;
xpthread_attr_init (&attr);
size_t stacksize = support_small_thread_stack_size ();
size_t stacksize = support_small_thread_stack_size (false);
void *stack = xmmap (0,
stacksize,
PROT_READ | PROT_WRITE,
+2 -2
View File
@@ -176,7 +176,7 @@ do_test1 (void *closure)
pthread_attr_t attr;
xpthread_attr_init (&attr);
size_t stacksize = support_small_thread_stack_size ();
size_t stacksize = support_small_thread_stack_size (false);
void *stack = xmmap (0,
stacksize,
PROT_READ | PROT_WRITE,
@@ -201,7 +201,7 @@ do_test2 (void *closure)
pthread_attr_t attr;
xpthread_attr_init (&attr);
size_t stacksize = support_small_thread_stack_size ();
size_t stacksize = support_small_thread_stack_size (false);
void *stack = xmmap (0,
stacksize,
PROT_READ | PROT_WRITE,
+1 -1
View File
@@ -81,7 +81,7 @@ do_realpath (void *arg)
const size_t syscall_usage = 1 * PATH_MAX + 1024;
const size_t realpath_usage = 2 * PATH_MAX + 1024;
const size_t thread_usage = 1 * PATH_MAX + 1024;
size_t stack_size = support_small_thread_stack_size ()
size_t stack_size = support_small_thread_stack_size (false)
- syscall_usage - realpath_usage - thread_usage;
char stack[stack_size];
char *resolved = stack + stack_size - thread_usage + 1024;
@@ -21,13 +21,16 @@
#include <support/xthread.h>
size_t
support_small_thread_stack_size (void)
support_small_thread_stack_size (bool use_stack_min)
{
/* Some architectures have too small values for PTHREAD_STACK_MIN
which cannot be used for creating threads. Ensure that the stack
size is at least 256 KiB. */
size is at least 256 KiB if USE_STACK_MIN is false. */
size_t stack_size = 256 * 1024;
#ifdef PTHREAD_STACK_MIN
if (use_stack_min)
return PTHREAD_STACK_MIN;
if (stack_size < PTHREAD_STACK_MIN)
stack_size = PTHREAD_STACK_MIN;
#endif
@@ -35,7 +38,9 @@ support_small_thread_stack_size (void)
}
void
support_set_small_thread_stack_size (pthread_attr_t *attr)
support_set_small_thread_stack_size (pthread_attr_t *attr,
bool use_stack_min)
{
xpthread_attr_setstacksize (attr, support_small_thread_stack_size ());
xpthread_attr_setstacksize
(attr, support_small_thread_stack_size (use_stack_min));
}
@@ -24,7 +24,7 @@ allocate (void *closure)
{
pthread_attr_t *result = malloc (sizeof (*result));
xpthread_attr_init (result);
support_set_small_thread_stack_size (result);
support_set_small_thread_stack_size (result, false);
return result;
}
+7 -5
View File
@@ -90,11 +90,13 @@ void xpthread_attr_setguardsize (pthread_attr_t *attr,
void xpthread_kill (pthread_t thr, int signo);
/* Return the stack size used on support_set_small_thread_stack_size. */
size_t support_small_thread_stack_size (void);
/* Set the stack size in ATTR to a small value, but still large enough
to cover most internal glibc stack usage. */
void support_set_small_thread_stack_size (pthread_attr_t *attr);
/* Return the stack size used on support_set_small_thread_stack_size,
or PTHREAD_STACK_MIN (if defined) is USE_STACK_MIN is set. */
size_t support_small_thread_stack_size (bool use_stack_min);
/* Set the stack size in ATTR to a small value. Use PTHREAD_STACK_MIN (if
defined) or a large enough to cover most internal glibc stack usage. */
void support_set_small_thread_stack_size (pthread_attr_t *attr,
bool use_stack_min);
/* Return a pointer to a thread attribute which requests a small
stack. The caller must not free this pointer. */
@@ -136,7 +136,7 @@ early_test (struct conf *conf)
printf ("error: pthread_attr_init failed: %s\n", strerror (ret));
return false;
}
support_set_small_thread_stack_size (&attr);
support_set_small_thread_stack_size (&attr, false);
/* Spawn a thread pinned to each available CPU. */
for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
@@ -208,7 +208,7 @@ early_test (struct conf *conf)
printf ("error: pthread_attr_init failed: %s\n", strerror (ret));
return false;
}
support_set_small_thread_stack_size (&attr);
support_set_small_thread_stack_size (&attr, false);
/* This count assumes that all the threads below are created
successfully, and call pthread_barrier_wait(). If any threads