From 54da7c3e55056efd93adece52076b720490258d6 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Thu, 28 Jun 2012 15:03:15 +0200 Subject: mghttpd: Add stack size and scheduling options --- cpukit/mghttpd/mongoose.1 | 12 +++++++++++ cpukit/mghttpd/mongoose.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/cpukit/mghttpd/mongoose.1 b/cpukit/mghttpd/mongoose.1 index e02b186c2d..0d37585955 100644 --- a/cpukit/mghttpd/mongoose.1 +++ b/cpukit/mghttpd/mongoose.1 @@ -143,6 +143,18 @@ will serve all URLs that start with "/config" from the "/etc" directory, and call handle_doc.cgi script for .doc and .rtf file requests. If some pattern matches, no further matching/substitution is performed (first matching pattern wins). Use full paths in substitutions. Default: "" +.It Fl x Ar thread_stack_size +Use the given amount of stack for each thread. Default: "" +.It Fl y Ar thread_priority +Use the given priority for all posix threads. If this option is used without the +thread_policy option, the systems default scheduling policy will be used for the +threads instead of inheriting the policy of the creating thread. Default: "" +.It Fl z Ar thread_policy +Select the posix scheduling policy for the threads. Possible Values are 's' for +sporadic (not on all systems available), 'r' for round robin, 'f' for fifo or +'o' for other scheduling strategie. If this option is used without the +thread_priority option, the systems default priority will be used for the +threads instead of inheriting the priority of the creating thread. Default: "" .El .Pp .Sh EMBEDDING diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c index 7462e6e7b8..d28d8a7270 100644 --- a/cpukit/mghttpd/mongoose.c +++ b/cpukit/mghttpd/mongoose.c @@ -424,6 +424,7 @@ enum { ENABLE_KEEP_ALIVE, ACCESS_CONTROL_LIST, MAX_REQUEST_SIZE, EXTRA_MIME_TYPES, LISTENING_PORTS, DOCUMENT_ROOT, SSL_CERTIFICATE, NUM_THREADS, RUN_AS_USER, REWRITE, + THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_POLICY, NUM_OPTIONS }; @@ -451,6 +452,9 @@ static const char *config_options[] = { "t", "num_threads", "10", "u", "run_as_user", NULL, "w", "url_rewrite_patterns", NULL, + "x", "thread_stack_size", NULL, + "y", "thread_priority", NULL, + "z", "thread_policy", NULL, NULL }; #define ENTRIES_PER_CONFIG_OPTION 3 @@ -1277,12 +1281,62 @@ static int start_thread(struct mg_context *ctx, mg_thread_func_t func, pthread_t thread_id; pthread_attr_t attr; int retval; + char* stacksize = ctx->config[THREAD_STACK_SIZE]; + char* priority = ctx->config[THREAD_PRIORITY]; + char* policy = ctx->config[THREAD_POLICY]; + int noinheritsched = 0; (void) pthread_attr_init(&attr); (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); // TODO(lsm): figure out why mongoose dies on Linux if next line is enabled // (void) pthread_attr_setstacksize(&attr, sizeof(struct mg_connection) * 5); + if (stacksize != NULL) { + size_t size = atoi(stacksize); + (void) pthread_attr_setstacksize(&attr, size); + } + + if (priority != NULL) { + struct sched_param sched_param; + memset(&sched_param, 0, sizeof(sched_param)); + sched_param.sched_priority = atoi(priority); + (void) pthread_attr_setschedparam(&attr, &sched_param); + noinheritsched = 1; + } + + if (policy != NULL) { + int p_policy; + (void) pthread_attr_getschedpolicy(&attr, &p_policy); + + switch (policy[0]) { + case 'o': + p_policy = SCHED_OTHER; + break; + case 'f': + p_policy = SCHED_FIFO; + break; + case 'r': + p_policy = SCHED_RR; + break; +#if defined(_POSIX_SPORADIC_SERVER) || defined(_POSIX_THREAD_SPORADIC_SERVER) + case 's': + p_policy = SCHED_SPORADIC; + break; +#endif + default: + cry(fc(ctx), "%s: Unknown scheduler: %s", __func__, policy); + break; + } + + (void) pthread_attr_setschedpolicy(&attr, p_policy); + + noinheritsched = 1; + } + + if (noinheritsched != 0) { + (void) pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + } + if ((retval = pthread_create(&thread_id, &attr, func, param)) != 0) { cry(fc(ctx), "%s: %s", __func__, strerror(retval)); } -- cgit v1.2.3