On Wed, Aug 16, 2017 at 11:28:52AM -0400, Mark Staudinger wrote: > On Wed, 16 Aug 2017 10:47:32 -0400, Dmitry Sivachenko <[email protected]> > wrote: > > > > > > On 16 Aug 2017, at 17:40, Mark Staudinger <[email protected]> > > > wrote: > > > > > > On Wed, 16 Aug 2017 10:35:05 -0400, Dmitry Sivachenko > > > <[email protected]> wrote: > > > > > > > Hello, > > > > > > > > are you installing haproxy form FreeBSD ports? > > > > > > > > I just tried your configuration and it works as you expect. > > > > > > > > If you are building haproxy by hand, add USE_CPU_AFFINITY=1 > > > > parameter to make manually. FreeBSD port do that for you. > > > > > > > > > > > > > > > > > > > > > Hi Dmitry, > > > > > > I am running (for now) a locally compiled from source version. > > > > > > Build options : > > > TARGET = freebsd > > > CPU = generic > > > CC = clang > > > CFLAGS = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement > > > -fwrapv > > > OPTIONS = USE_CPU_AFFINITY=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=1 > > > USE_STATIC_PCRE=1 USE_PCRE_JIT=1 > > > > > > > > Strange. I am testing on FreeBSD-10-stable though. > > > > May be you add return code check for cpuset_setaffinity() and log > > possible error? > > Output of from truss on starup yields this: > > 3862: cpuset_setaffinity(0x3,0x2,0xffffffffffffffff,0x8,0x773dd0) ERR#34 > 'Result too large' > 3863: cpuset_setaffinity(0x3,0x2,0xffffffffffffffff,0x8,0x773dd8) ERR#34 > 'Result too large' >
Hi Mark, I think I know what's going on. Can you try the attached patch ? Thanks ! Olivier
>From d01f5a680cd8dcfb8d90da05cd7474d29c759fa9 Mon Sep 17 00:00:00 2001 From: Olivier Houchard <[email protected]> Date: Wed, 16 Aug 2017 17:29:11 +0200 Subject: [PATCH] MINOR: Fix CPU usage on FreeBSD. Use a cpuset_t instead of assuming the cpu mask is an unsigned long. This should fix setting the CPU affinity on FreeBSD >= 11. --- src/haproxy.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/haproxy.c b/src/haproxy.c index 52722db8..67347d68 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2556,7 +2556,18 @@ int main(int argc, char **argv) proc < LONGBITS && /* only the first 32/64 processes may be pinned */ global.cpu_map[proc]) /* only do this if the process has a CPU map */ #ifdef __FreeBSD__ - cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(unsigned long), (void *)&global.cpu_map[proc]); + { + cpuset_t cpuset; + int i; + unsigned long cpu_map = global.cpu_map[proc]; + + CPU_ZERO(&cpuset); + while ((i = ffsl(cpu_map)) > 0) { + CPU_SET(i - 1, &cpuset); + cpu_map &= ~(1 << (i - 1)); + } + ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset), &cpuset); + } #else sched_setaffinity(0, sizeof(unsigned long), (void *)&global.cpu_map[proc]); #endif -- 2.11.1

