summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2020-05-12 21:19:12 +0100
committerDavid Carlier <devnexen@gmail.com>2020-05-12 21:21:22 +0100
commit4715ce59037d5806ede71e605f53b1addb7014ed (patch)
tree0da1a609614be57b08de27387dfc9123707fa50e
parentb726d64229a58e0683925c8e8f89ab6257dddfd7 (diff)
downloadredis-4715ce59037d5806ede71e605f53b1addb7014ed.tar.gz
NetBSD build update.
This platform supports CPU affinity (but not OpenBSD).
-rw-r--r--src/Makefile10
-rw-r--r--src/config.h2
-rw-r--r--src/setcpuaffinity.c19
3 files changed, 30 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 55f862cfc..b8c05c32b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -129,6 +129,14 @@ ifeq ($(uname_S),DragonFly)
# FreeBSD
FINAL_LIBS+= -lpthread -lexecinfo
else
+ifeq ($(uname_S),OpenBSD)
+ # OpenBSD
+ FINAL_LIBS+= -lpthread -lexecinfo
+else
+ifeq ($(uname_S),NetBSD)
+ # NetBSD
+ FINAL_LIBS+= -lpthread -lexecinfo
+else
# All the other OSes (notably Linux)
FINAL_LDFLAGS+= -rdynamic
FINAL_LIBS+=-ldl -pthread -lrt
@@ -138,6 +146,8 @@ endif
endif
endif
endif
+endif
+endif
# Include paths to dependencies
FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
diff --git a/src/config.h b/src/config.h
index 6025d4e96..0fcc42972 100644
--- a/src/config.h
+++ b/src/config.h
@@ -248,7 +248,7 @@ int pthread_setname_np(const char *name);
#endif
/* Check if we can use setcpuaffinity(). */
-#if (defined __linux || defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)
+#if (defined __linux || defined __NetBSD__ || defined __FreeBSD__)
#define USE_SETCPUAFFINITY
void setcpuaffinity(const char *cpulist);
#endif
diff --git a/src/setcpuaffinity.c b/src/setcpuaffinity.c
index dcae81c71..13594113c 100644
--- a/src/setcpuaffinity.c
+++ b/src/setcpuaffinity.c
@@ -36,6 +36,10 @@
#include <sys/param.h>
#include <sys/cpuset.h>
#endif
+#ifdef __NetBSD__
+#include <pthread.h>
+#include <sched.h>
+#endif
#include "config.h"
#ifdef USE_SETCPUAFFINITY
@@ -71,11 +75,18 @@ void setcpuaffinity(const char *cpulist) {
#ifdef __FreeBSD__
cpuset_t cpuset;
#endif
+#ifdef __NetBSD__
+ cpuset_t *cpuset;
+#endif
if (!cpulist)
return;
+#ifndef __NetBSD__
CPU_ZERO(&cpuset);
+#else
+ cpuset = cpuset_create();
+#endif
q = cpulist;
while (p = q, q = next_token(q, ','), p) {
@@ -110,7 +121,11 @@ void setcpuaffinity(const char *cpulist) {
return;
while (a <= b) {
+#ifndef __NetBSD__
CPU_SET(a, &cpuset);
+#else
+ cpuset_set(a, cpuset);
+#endif
a += s;
}
}
@@ -124,6 +139,10 @@ void setcpuaffinity(const char *cpulist) {
#ifdef __FreeBSD__
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset), &cpuset);
#endif
+#ifdef __NetBSD__
+ pthread_setaffinity_np(pthread_self(), cpuset_size(cpuset), cpuset);
+ cpuset_destroy(cpuset);
+#endif
}
#endif /* USE_SETCPUAFFINITY */