kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 27b4447a302c6d9a254199b09019a95bb16de7dd
parent 9512805c04500e8da31c78953924373b996e2245
Author: Joris Vink <joris@coders.se>
Date:   Sun, 26 Oct 2014 22:41:55 +0100

Allow workers to bind to specific CPUs on FreeBSD.

Diffstat:
src/bsd.c | 38++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/bsd.c b/src/bsd.c @@ -16,9 +16,10 @@ #include <sys/param.h> #include <sys/event.h> - -#ifdef __MACH__ #include <sys/sysctl.h> + +#if defined(__FreeBSD_version) +#include <sys/cpuset.h> #endif #include "kore.h" @@ -40,27 +41,36 @@ static u_int32_t event_count = 0; void kore_platform_init(void) { -#ifndef __MACH__ - cpu_count = 0; -#else +#if defined(__MACH__) || defined(__FreeBSD_version) long n; size_t len = sizeof(n); - int mib[] = { CTL_HW, HW_AVAILCPU }; - - sysctl(mib, 2, &n, &len, NULL, 0); - if (n < 1) { - mib[1] = HW_NCPU; - sysctl(mib, 2, &n, &len, NULL, 0); - } + int mib[] = { CTL_HW, HW_NCPU }; - if (n >= 1) + if (sysctl(mib, 2, &n, &len, NULL, 0) == -1) { + kore_debug("kore_platform_init(): sysctl %s", errno_s); + cpu_count = 1; + } else { cpu_count = (u_int16_t)n; -#endif /* !__MACH__ */ + } +#else + cpu_count = 0; +#endif /* __MACH__ || __FreeBSD_version */ } void kore_platform_worker_setcpu(struct kore_worker *kw) { +#if defined(__FreeBSD_version) + cpuset_t cpuset; + + CPU_ZERO(&cpuset); + CPU_SET(kw->cpu, &cpuset); + if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, + -1, sizeof(cpuset), &cpuset) == -1) { + fatal("failed: %s", errno_s); + } + +#endif /* __FreeBSD_version */ } void