summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mauderer <christian.mauderer@embedded-brains.de>2012-06-28 15:03:15 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-07-12 09:51:44 +0200
commit54da7c3e55056efd93adece52076b720490258d6 (patch)
tree33ad5d664eda66412739ab7869932a813159148f
parentmghttpd: Use MD5 library (diff)
downloadrtems-54da7c3e55056efd93adece52076b720490258d6.tar.bz2
mghttpd: Add stack size and scheduling options
-rw-r--r--cpukit/mghttpd/mongoose.112
-rw-r--r--cpukit/mghttpd/mongoose.c54
2 files changed, 66 insertions, 0 deletions
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));
}