forked from Imagelibrary/rtems
mghttpd: Add stack size and scheduling options
This commit is contained in:
committed by
Sebastian Huber
parent
ea008e2d0d
commit
54da7c3e55
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user