Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1 | From f839de283c44ffe46a2d14bfdf854c145abd8ed6 Mon Sep 17 00:00:00 2001 |
| 2 | From: Colin Ian King <colin.king@canonical.com> |
| 3 | Date: Mon, 19 Jul 2021 20:49:34 +0100 |
| 4 | Subject: [PATCH] Detemine minimal stack size via sysconf, then PTHREAD_STACK_MIN then guess |
| 5 | |
| 6 | Don't rely on PTHREAD_STACK_MIN being defined, use sysconf, then |
| 7 | PTHREAD_STACK_MIN if it is defined, then 8K default. |
| 8 | |
| 9 | Upstream-Status: Backport [https://kernel.ubuntu.com/git/cking/stress-ng.git/commit/?id=f839de283c44ffe46a2d14bfdf854c145abd8ed6] |
| 10 | Signed-off-by: Colin Ian King <colin.king@canonical.com> |
| 11 | --- |
| 12 | core-helper.c | 31 +++++++++++++++++++++++++++++++ |
| 13 | stress-ng.h | 1 + |
| 14 | stress-pthread.c | 13 ++----------- |
| 15 | 3 files changed, 34 insertions(+), 11 deletions(-) |
| 16 | |
| 17 | diff --git a/core-helper.c b/core-helper.c |
| 18 | index 508627f2..97a3b869 100644 |
| 19 | --- a/core-helper.c |
| 20 | +++ b/core-helper.c |
| 21 | @@ -2494,6 +2494,37 @@ size_t stress_min_sig_stack_size(void) |
| 22 | return (size_t)sz; |
| 23 | } |
| 24 | |
| 25 | +size_t stress_min_pthread_stack_size(void) |
| 26 | +{ |
| 27 | + static long sz = -1, min; |
| 28 | + |
| 29 | + /* return cached copy */ |
| 30 | + if (sz > 0) |
| 31 | + return sz; |
| 32 | + |
| 33 | + min = stress_min_aux_sig_stack_size(); |
| 34 | +#if defined(__SC_THREAD_STACK_MIN_VALUE) |
| 35 | + sz = sysconf(__SC_THREAD_STACK_MIN_VALUE); |
| 36 | + if (sz > min) |
| 37 | + min = sz; |
| 38 | +#endif |
| 39 | +#if defined(_SC_THREAD_STACK_MIN_VALUE) |
| 40 | + sz = sysconf(_SC_THREAD_STACK_MIN_VALUE); |
| 41 | + if (sz > min) |
| 42 | + min = sz; |
| 43 | +#endif |
| 44 | +#if defined(PTHREAD_STACK_MIN) |
| 45 | + if (PTHREAD_STACK_MIN > min) |
| 46 | + min = PTHREAD_STACK_MIN; |
| 47 | +#endif |
| 48 | + if (8192 > min) |
| 49 | + min = 8192; |
| 50 | + |
| 51 | + sz = min; |
| 52 | + |
| 53 | + return (size_t)sz; |
| 54 | +} |
| 55 | + |
| 56 | /* |
| 57 | * stress_sig_handler_exit() |
| 58 | * signal handler that exits a process via _exit(0) for |
| 59 | diff --git a/stress-ng.h b/stress-ng.h |
| 60 | index 8a8b17ae..cd744756 100644 |
| 61 | --- a/stress-ng.h |
| 62 | +++ b/stress-ng.h |
| 63 | @@ -4056,6 +4056,7 @@ extern WARN_UNUSED int32_t stress_get_opt_ionice_class(const char *const str); |
| 64 | /* Misc helper funcs */ |
| 65 | extern WARN_UNUSED size_t stress_sig_stack_size(void); |
| 66 | extern WARN_UNUSED size_t stress_min_sig_stack_size(void); |
| 67 | +extern WARN_UNUSED size_t stress_min_pthread_stack_size(void); |
| 68 | |
| 69 | #define STRESS_SIGSTKSZ (stress_sig_stack_size()) |
| 70 | #define STRESS_MINSIGSTKSZ (stress_min_sig_stack_size()) |
| 71 | diff --git a/stress-pthread.c b/stress-pthread.c |
| 72 | index 0da3aeec..27777af8 100644 |
| 73 | --- a/stress-pthread.c |
| 74 | +++ b/stress-pthread.c |
| 75 | @@ -69,12 +69,7 @@ static const stress_opt_set_func_t opt_set_funcs[] = { |
| 76 | |
| 77 | #if defined(HAVE_LIB_PTHREAD) |
| 78 | |
| 79 | -/* Some systems such as GNU/HURD don't define PTHREAD_STACK_MIN */ |
| 80 | -#if !defined(PTHREAD_STACK_MIN) |
| 81 | -#define PTHREAD_STACK_MIN (16 * KB) |
| 82 | -#endif |
| 83 | - |
| 84 | -#define DEFAULT_STACK_MIN (16 * KB) |
| 85 | +#define DEFAULT_STACK_MIN (8 * KB) |
| 86 | |
| 87 | #if defined(HAVE_GET_ROBUST_LIST) && \ |
| 88 | defined(HAVE_LINUX_FUTEX_H) |
| 89 | @@ -404,11 +399,7 @@ static int stress_pthread(const stress_args_t *args) |
| 90 | stress_pthread_args_t pargs = { args, NULL, 0 }; |
| 91 | sigset_t set; |
| 92 | #if defined(HAVE_PTHREAD_ATTR_SETSTACK) |
| 93 | -#if DEFAULT_STACK_MIN == PTHREAD_STACK_MIN |
| 94 | - const size_t stack_size = PTHREAD_STACK_MIN; |
| 95 | -#else |
| 96 | - const size_t stack_size = STRESS_MAXIMUM(DEFAULT_STACK_MIN, PTHREAD_STACK_MIN); |
| 97 | -#endif |
| 98 | + const size_t stack_size = STRESS_MAXIMUM(DEFAULT_STACK_MIN, stress_min_pthread_stack_size()); |
| 99 | #endif |
| 100 | |
| 101 | keep_running_flag = true; |
| 102 | -- |
| 103 | 2.32.0 |