included #68 cpu binding for FreeBSD, thanks to devnexen

This commit is contained in:
hexcoder-
2019-09-28 20:50:13 +02:00
parent 6e25fde883
commit 942245b985
2 changed files with 19 additions and 2 deletions

View File

@ -45,6 +45,10 @@ ifneq "$(filter Linux GNU%,$(shell uname))" ""
LDFLAGS += -ldl LDFLAGS += -ldl
endif endif
ifneq "$(findstring FreeBSD, $(shell uname))" ""
CFLAGS += -pthread
endif
ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" "" ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" ""
TEST_CC = afl-gcc TEST_CC = afl-gcc
else else

View File

@ -52,9 +52,15 @@
#include "types.h" #include "types.h"
#include "debug.h" #include "debug.h"
#ifdef __linux__ #if defined(__linux__) || defined(__FreeBSD__)
#define HAVE_AFFINITY 1 #define HAVE_AFFINITY 1
#endif /* __linux__ */ # if defined(__FreeBSD__)
# include <pthread.h>
# include <pthread_np.h>
# include <sys/cpuset.h>
# define cpu_set_t cpuset_t
# endif
#endif /* __linux__ || __FreeBSD__ */
/* Get unix time in microseconds. */ /* Get unix time in microseconds. */
@ -160,8 +166,15 @@ int main(int argc, char** argv) {
CPU_ZERO(&c); CPU_ZERO(&c);
CPU_SET(i, &c); CPU_SET(i, &c);
#if defined(__FreeBSD__)
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
PFATAL("pthread_setaffinity_np failed");
#endif
#if defined(__linux__)
if (sched_setaffinity(0, sizeof(c), &c)) if (sched_setaffinity(0, sizeof(c), &c))
PFATAL("sched_setaffinity failed"); PFATAL("sched_setaffinity failed");
#endif
util_perc = measure_preemption(CTEST_CORE_TRG_MS); util_perc = measure_preemption(CTEST_CORE_TRG_MS);