From b260e145e74450b7bfb6095b6eeeb4397083847e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 15 Oct 2020 08:19:41 -0400 Subject: [PATCH] TT#97500 set thread stack size closes #1078 Change-Id: Iebe5effb917731c8ca553c9e599df613e763b255 --- daemon/aux.c | 8 ++++++++ daemon/rtpengine.pod | 5 +++++ lib/auxlib.c | 4 ++++ lib/auxlib.h | 1 + recording-daemon/main.c | 11 +++++++++++ recording-daemon/rtpengine-recording.pod | 5 +++++ 6 files changed, 34 insertions(+) diff --git a/daemon/aux.c b/daemon/aux.c index a8dca475e..eee18854f 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -9,6 +9,7 @@ #include #include #include "log.h" +#include "main.h" @@ -221,6 +222,13 @@ static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread abort(); if (pthread_attr_setdetachstate(&att, joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED)) abort(); + if (rtpe_config.common.thread_stack > 0) { + if (pthread_attr_setstacksize(&att, rtpe_config.common.thread_stack * 1024)) { + ilog(LOG_ERR, "Failed to set thread stack size to %llu", + (unsigned long long) rtpe_config.common.thread_stack * 1024); + abort(); + } + } ret = pthread_create(&thr, &att, func, arg); pthread_attr_destroy(&att); if (ret) diff --git a/daemon/rtpengine.pod b/daemon/rtpengine.pod index 4248c5f41..18c760d4d 100644 --- a/daemon/rtpengine.pod +++ b/daemon/rtpengine.pod @@ -288,6 +288,11 @@ decoding the media file, and another to schedule and send out RTP packets. So for example, if this option is set to 4, in total 8 threads will be launched. +=item B<--thread-stack=>I + +Set the stack size of each thread to the value given in kB. Defaults to 2048 +kB. Can be set to -1 to leave the default provided by the OS unchanged. + =item B<--sip-source> The original B as well as older version of B by default diff --git a/lib/auxlib.c b/lib/auxlib.c index 3cb015a15..347be237a 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -153,6 +153,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char { "log-mark-suffix", 0, 0, G_OPTION_ARG_STRING, &rtpe_common_config_ptr->log_mark_suffix,"Suffix for sensitive log info", NULL }, { "pidfile", 'p', 0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->pidfile, "Write PID to file", "FILE" }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->foreground, "Don't fork to background", NULL }, + { "thread-stack", 0,0, G_OPTION_ARG_INT, &rtpe_common_config_ptr->thread_stack, "Thread stack size in kB", "INT" }, { NULL, } }; @@ -322,6 +323,9 @@ out: max_log_line_length = 0; } + if (rtpe_common_config_ptr->thread_stack == 0) + rtpe_common_config_ptr->thread_stack = 2048; + return; diff --git a/lib/auxlib.h b/lib/auxlib.h index 095d21eba..e2c3d032e 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -24,6 +24,7 @@ struct rtpengine_common_config { char *log_mark_suffix; char *pidfile; int foreground; + int thread_stack; }; extern struct rtpengine_common_config *rtpe_common_config_ptr; diff --git a/recording-daemon/main.c b/recording-daemon/main.c index 3d56cb6d0..51ddac802 100644 --- a/recording-daemon/main.c +++ b/recording-daemon/main.c @@ -93,6 +93,17 @@ static void setup(void) { static void start_poller_thread(void) { + pthread_attr_t att; + if (pthread_attr_init(&att)) + abort(); + if (rtpe_common_config.thread_stack > 0) { + if (pthread_attr_setstacksize(&att, rtpe_common_config.thread_stack * 1024)) { + ilog(LOG_ERR, "Failed to set thread stack size to %llu", + (unsigned long long) rtpe_common_config.thread_stack * 1024); + abort(); + } + } + pthread_t *thr = g_slice_alloc(sizeof(*thr)); int ret = pthread_create(thr, NULL, poller_thread, GUINT_TO_POINTER(garbage_new_thread_num())); diff --git a/recording-daemon/rtpengine-recording.pod b/recording-daemon/rtpengine-recording.pod index e561e27c3..152a6a664 100644 --- a/recording-daemon/rtpengine-recording.pod +++ b/recording-daemon/rtpengine-recording.pod @@ -120,6 +120,11 @@ reside on a file system that supports the B mechanism. How many worker threads to launch. Defaults to B<8>. +=item B<--thread-stack=>I + +Set the stack size of each thread to the value given in kB. Defaults to 2048 +kB. Can be set to -1 to leave the default provided by the OS unchanged. + =item B<--output-storage=>B|B|B Where to store media files. By default, media files are written directly to the