Compare commits
No commits in common. "ad66680e62838beeab861e91dfebe1c902ff6c20" and "54d7b4677482942b0084bbb8c9bd91faf0798e97" have entirely different histories.
ad66680e62
...
54d7b46774
@ -63,7 +63,7 @@ struct liServer {
|
|||||||
liWorker *main_worker;
|
liWorker *main_worker;
|
||||||
guint worker_count;
|
guint worker_count;
|
||||||
GArray *workers;
|
GArray *workers;
|
||||||
#if defined(LIGHTY_OS_LINUX) || defined(LIGHTY_OS_FREEBSD)
|
#ifdef LIGHTY_OS_LINUX
|
||||||
liValue *workers_cpu_affinity;
|
liValue *workers_cpu_affinity;
|
||||||
#endif
|
#endif
|
||||||
GArray *ts_formats; /** array of (GString*), add with li_server_ts_format_add() */
|
GArray *ts_formats; /** array of (GString*), add with li_server_ts_format_add() */
|
||||||
|
@ -99,10 +99,6 @@
|
|||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LIGHTY_OS_FREEBSD)
|
|
||||||
# include <sys/cpuset.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* on linux 2.4.x you get either sendfile or LFS */
|
/* on linux 2.4.x you get either sendfile or LFS */
|
||||||
#if defined(LIGHTY_OS_LINUX) && defined(HAVE_SYS_SENDFILE_H) && defined(HAVE_SENDFILE) && (defined(_LARGEFILE_SOURCE) || defined(HAVE_SENDFILE64)) && defined(HAVE_WRITEV) && !defined(HAVE_SENDFILE_BROKEN)
|
#if defined(LIGHTY_OS_LINUX) && defined(HAVE_SYS_SENDFILE_H) && defined(HAVE_SENDFILE) && (defined(_LARGEFILE_SOURCE) || defined(HAVE_SENDFILE64)) && defined(HAVE_WRITEV) && !defined(HAVE_SENDFILE_BROKEN)
|
||||||
# define USE_LINUX_SENDFILE
|
# define USE_LINUX_SENDFILE
|
||||||
|
@ -10,7 +10,7 @@ typedef enum {
|
|||||||
} liCounterType;
|
} liCounterType;
|
||||||
|
|
||||||
/* log message, print backtrace, and abort() (use LI_FATAL(msg) to call it) */
|
/* log message, print backtrace, and abort() (use LI_FATAL(msg) to call it) */
|
||||||
LI_API HEDLEY_NO_RETURN void li_fatal(const char *filename, unsigned int line, const char *function, const char *msg);
|
LI_API void li_fatal(const char *filename, unsigned int line, const char *function, const char *msg) HEDLEY_NO_RETURN;
|
||||||
/* if libunwind is available this prints a backtrace to STDERR */
|
/* if libunwind is available this prints a backtrace to STDERR */
|
||||||
LI_API void li_print_backtrace_stderr(void);
|
LI_API void li_print_backtrace_stderr(void);
|
||||||
/* LI_FORCE_ASSERT is *always* active - in debug and release builds */
|
/* LI_FORCE_ASSERT is *always* active - in debug and release builds */
|
||||||
|
@ -628,7 +628,7 @@ static int do_listen(liServer *srv, liSocketAddress *addr, GString *str) {
|
|||||||
}
|
}
|
||||||
#ifdef TCP_FASTOPEN
|
#ifdef TCP_FASTOPEN
|
||||||
v = 1000;
|
v = 1000;
|
||||||
setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &v, sizeof(v));
|
setsockopt(s, SOL_TCP, TCP_FASTOPEN, &v, sizeof(v));
|
||||||
#endif
|
#endif
|
||||||
if (-1 == listen(s, 1000)) {
|
if (-1 == listen(s, 1000)) {
|
||||||
close(s);
|
close(s);
|
||||||
@ -668,7 +668,7 @@ static int do_listen(liServer *srv, liSocketAddress *addr, GString *str) {
|
|||||||
}
|
}
|
||||||
#ifdef TCP_FASTOPEN
|
#ifdef TCP_FASTOPEN
|
||||||
v = 1000;
|
v = 1000;
|
||||||
setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &v, sizeof(v));
|
setsockopt(s, SOL_TCP, TCP_FASTOPEN, &v, sizeof(v));
|
||||||
#endif
|
#endif
|
||||||
if (-1 == listen(s, 1000)) {
|
if (-1 == listen(s, 1000)) {
|
||||||
close(s);
|
close(s);
|
||||||
|
@ -76,7 +76,7 @@ int li_angel_fake_listen(liServer *srv, GString *str) {
|
|||||||
}
|
}
|
||||||
#ifdef TCP_FASTOPEN
|
#ifdef TCP_FASTOPEN
|
||||||
v = 1000;
|
v = 1000;
|
||||||
setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &v, sizeof(v));
|
setsockopt(s, SOL_TCP, TCP_FASTOPEN, &v, sizeof(v));
|
||||||
#endif
|
#endif
|
||||||
if (-1 == listen(s, 1000)) {
|
if (-1 == listen(s, 1000)) {
|
||||||
ERROR(srv, "Couldn't listen on '%s': %s", tmpstr->str, g_strerror(errno));
|
ERROR(srv, "Couldn't listen on '%s': %s", tmpstr->str, g_strerror(errno));
|
||||||
|
@ -1205,7 +1205,7 @@ static gboolean core_workers(liServer *srv, liPlugin* p, liValue *val, gpointer
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean core_workers_cpu_affinity(liServer *srv, liPlugin* p, liValue *val, gpointer userdata) {
|
static gboolean core_workers_cpu_affinity(liServer *srv, liPlugin* p, liValue *val, gpointer userdata) {
|
||||||
#if defined(LIGHTY_OS_LINUX) || defined(LIGHTY_OS_FREEBSD)
|
#if defined(LIGHTY_OS_LINUX)
|
||||||
UNUSED(p); UNUSED(userdata);
|
UNUSED(p); UNUSED(userdata);
|
||||||
|
|
||||||
if (LI_VALUE_LIST != li_value_type(val)) {
|
if (LI_VALUE_LIST != li_value_type(val)) {
|
||||||
@ -1232,7 +1232,7 @@ static gboolean core_workers_cpu_affinity(liServer *srv, liPlugin* p, liValue *v
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
UNUSED(p); UNUSED(val); UNUSED(userdata);
|
UNUSED(p); UNUSED(val); UNUSED(userdata);
|
||||||
ERROR(srv, "%s", "workers.cpu_affinity is only available on Linux and FreeBSD systems");
|
ERROR(srv, "%s", "workers.cpu_affinity is only available on Linux systems");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2160,81 +2160,47 @@ static const liPluginAngel angelcbs[] = {
|
|||||||
};
|
};
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#if defined(LIGHTY_OS_LINUX) || defined(LIGHTY_OS_FREEBSD)
|
|
||||||
/* settings CPU affinity is only supported on linux and FreeBSD */
|
|
||||||
|
|
||||||
#if defined(LIGHTY_OS_LINUX)
|
|
||||||
typedef cpu_set_t li_cpu_set_t;
|
|
||||||
#elif defined(LIGHTY_OS_FREEBSD)
|
|
||||||
typedef cpuset_t li_cpu_set_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static gboolean pin_cpu(liServer *srv, liWorker *wrk, li_cpu_set_t *cpu_set, gint64 ndx) {
|
|
||||||
size_t cpu_ndx;
|
|
||||||
|
|
||||||
if (ndx < 0 || ((guint64)ndx) > CPU_SETSIZE) {
|
|
||||||
ERROR(srv, "invalid cpu affinity index for worker #%u: %"G_GINT64_FORMAT, wrk->ndx+1, ndx);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cpu_ndx = (size_t) ndx;
|
|
||||||
CPU_SET(cpu_ndx, cpu_set);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void plugin_core_prepare_worker_cpu_affinity(liServer *srv, liWorker *wrk) {
|
|
||||||
li_cpu_set_t mask;
|
|
||||||
liValue *v = srv->workers_cpu_affinity;
|
|
||||||
|
|
||||||
if (NULL == v) return;
|
|
||||||
|
|
||||||
if (wrk->ndx >= li_value_list_len(v)) {
|
|
||||||
WARNING(srv, "worker #%u has no entry in workers.cpu_affinity", wrk->ndx+1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CPU_ZERO(&mask);
|
|
||||||
|
|
||||||
v = li_value_list_at(v, wrk->ndx);
|
|
||||||
if (LI_VALUE_NUMBER == li_value_type(v)) {
|
|
||||||
if (!pin_cpu(srv, wrk, &mask, v->data.number)) {
|
|
||||||
return; /* pin_cpu already printed error */
|
|
||||||
}
|
|
||||||
DEBUG(srv, "binding worker #%u to cpu %u", wrk->ndx+1, (guint)v->data.number);
|
|
||||||
} else {
|
|
||||||
g_string_truncate(wrk->tmp_str, 0);
|
|
||||||
|
|
||||||
LI_VALUE_FOREACH(entry, v)
|
|
||||||
if (!pin_cpu(srv, wrk, &mask, entry->data.number)) {
|
|
||||||
return; /* pin_cpu already printed error */
|
|
||||||
}
|
|
||||||
g_string_append_printf(wrk->tmp_str, _entry_i ? ",%u":"%u", (guint)entry->data.number);
|
|
||||||
LI_VALUE_END_FOREACH()
|
|
||||||
|
|
||||||
DEBUG(srv, "binding worker #%u to cpus %s", wrk->ndx+1, wrk->tmp_str->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(LIGHTY_OS_LINUX)
|
|
||||||
if (0 != sched_setaffinity(0, sizeof(mask), &mask)) {
|
|
||||||
ERROR(srv, "couldn't set cpu affinity mask for worker #%u: %s", wrk->ndx+1, g_strerror(errno));
|
|
||||||
}
|
|
||||||
#elif defined(LIGHTY_OS_FREEBSD)
|
|
||||||
if (0 != cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask), &mask)) {
|
|
||||||
ERROR(srv, "couldn't set cpu affinity mask for worker #%u: %s", wrk->ndx+1, g_strerror(errno));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void plugin_core_prepare_worker_cpu_affinity(liServer *srv, liWorker *wrk) {
|
|
||||||
UNUSED(srv);
|
|
||||||
UNUSED(wrk);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void plugin_core_prepare_worker(liServer *srv, liPlugin *p, liWorker *wrk) {
|
static void plugin_core_prepare_worker(liServer *srv, liPlugin *p, liWorker *wrk) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
|
|
||||||
plugin_core_prepare_worker_cpu_affinity(srv, wrk);
|
#if defined(LIGHTY_OS_LINUX)
|
||||||
|
/* sched_setaffinity is only available on linux */
|
||||||
|
{
|
||||||
|
cpu_set_t mask;
|
||||||
|
liValue *v = srv->workers_cpu_affinity;
|
||||||
|
|
||||||
|
if (NULL == v) return;
|
||||||
|
|
||||||
|
if (wrk->ndx >= li_value_list_len(v)) {
|
||||||
|
WARNING(srv, "worker #%u has no entry in workers.cpu_affinity", wrk->ndx+1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPU_ZERO(&mask);
|
||||||
|
|
||||||
|
v = li_value_list_at(v, wrk->ndx);
|
||||||
|
if (LI_VALUE_NUMBER == li_value_type(v)) {
|
||||||
|
CPU_SET(v->data.number, &mask);
|
||||||
|
DEBUG(srv, "binding worker #%u to cpu %u", wrk->ndx+1, (guint)v->data.number);
|
||||||
|
} else {
|
||||||
|
g_string_truncate(wrk->tmp_str, 0);
|
||||||
|
|
||||||
|
LI_VALUE_FOREACH(entry, v)
|
||||||
|
CPU_SET(entry->data.number, &mask);
|
||||||
|
g_string_append_printf(wrk->tmp_str, _entry_i ? ",%u":"%u", (guint)entry->data.number);
|
||||||
|
LI_VALUE_END_FOREACH()
|
||||||
|
|
||||||
|
DEBUG(srv, "binding worker #%u to cpus %s", wrk->ndx+1, wrk->tmp_str->str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != sched_setaffinity(0, sizeof(mask), &mask)) {
|
||||||
|
ERROR(srv, "couldn't set cpu affinity mask for worker #%u: %s", wrk->ndx, g_strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
UNUSED(srv);
|
||||||
|
UNUSED(wrk);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void li_plugin_core_init(liServer *srv, liPlugin *p, gpointer userdata) {
|
void li_plugin_core_init(liServer *srv, liPlugin *p, gpointer userdata) {
|
||||||
|
Loading…
Reference in New Issue
Block a user