From d0f6484e7ccdb6f24d9ae310015c2d049ab06cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sat, 13 Feb 2010 15:54:48 +0100 Subject: [PATCH] Move sched_[gs]etaffinity to plugin_core --- src/main/plugin_core.c | 31 +++++++++++++++++++++++++++++++ src/main/worker.c | 23 ----------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/main/plugin_core.c b/src/main/plugin_core.c index 5e5b74a..4a427bf 100644 --- a/src/main/plugin_core.c +++ b/src/main/plugin_core.c @@ -10,6 +10,8 @@ #include #include +#include + static liAction* core_list(liServer *srv, liPlugin* p, liValue *val, gpointer userdata) { liAction *a; guint i; @@ -1552,6 +1554,33 @@ static const liPluginAngel angelcbs[] = { { NULL, NULL } }; +static void plugin_core_prepare_worker(liServer *srv, liPlugin *p, liWorker *wrk) { + UNUSED(p); + +#ifdef LIGHTY_OS_LINUX + /* sched_setaffinity is only available on linux */ + { + cpu_set_t mask; + + if (0 != sched_getaffinity(0, sizeof(mask), &mask)) { + ERROR(srv, "couldn't get cpu affinity mask: %s", g_strerror(errno)); + } else { + guint cpus = 0; + while (CPU_ISSET(cpus, &mask)) cpus++; + if (cpus) { + CPU_ZERO(&mask); + CPU_SET(wrk->ndx % cpus, &mask); + if (0 != sched_setaffinity(0, sizeof(mask), &mask)) { + ERROR(srv, "couldn't set cpu affinity mask: %s", g_strerror(errno)); + } + } else { + ERROR(srv, "%s", "cpu 0 not enabled, no affinity set"); + } + } + } +#endif +} + void li_plugin_core_init(liServer *srv, liPlugin *p, gpointer userdata) { UNUSED(srv); UNUSED(userdata); @@ -1560,4 +1589,6 @@ void li_plugin_core_init(liServer *srv, liPlugin *p, gpointer userdata) { p->actions = actions; p->setups = setups; p->angelcbs = angelcbs; + + p->handle_prepare_worker = plugin_core_prepare_worker; } diff --git a/src/main/worker.c b/src/main/worker.c index 7036b9f..a44d279 100644 --- a/src/main/worker.c +++ b/src/main/worker.c @@ -9,8 +9,6 @@ # include #endif -#include - static liConnection* worker_con_get(liWorker *wrk); /* closing sockets - wait for proper shutdown */ @@ -540,27 +538,6 @@ void li_worker_free(liWorker *wrk) { } void li_worker_run(liWorker *wrk) { -#ifdef LIGHTY_OS_LINUX - /* sched_setaffinity is only available on linux */ - cpu_set_t mask; - - if (0 != sched_getaffinity(0, sizeof(mask), &mask)) { - ERROR(wrk->srv, "couldn't get cpu affinity mask: %s", g_strerror(errno)); - } else { - guint cpus = 0; - while (CPU_ISSET(cpus, &mask)) cpus++; - if (cpus) { - CPU_ZERO(&mask); - CPU_SET(wrk->ndx % cpus, &mask); - if (0 != sched_setaffinity(0, sizeof(mask), &mask)) { - ERROR(wrk->srv, "couldn't set cpu affinity mask: %s", g_strerror(errno)); - } - } else { - ERROR(wrk->srv, "%s", "cpu 0 not enabled, no affinity set"); - } - } -#endif - ev_loop(wrk->loop, 0); }