2
0
Fork 0

Move sched_[gs]etaffinity to plugin_core

personal/stbuehler/wip
Stefan Bühler 2010-02-13 15:54:48 +01:00
parent 905a83fc77
commit d0f6484e7c
2 changed files with 31 additions and 23 deletions

View File

@ -10,6 +10,8 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <sched.h>
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;
}

View File

@ -9,8 +9,6 @@
# include <lauxlib.h>
#endif
#include <sched.h>
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);
}