From 2a408bbed14bb9aa903ceb90ce0e8c0712bd5090 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Mon, 22 Nov 2021 10:23:14 +0100 Subject: [PATCH] sched_getcpu() and pthread_setaffinity_np() are non-portable Reported by Yuri Victorovich, on FreeBSD. * configure.ac: Test for them. * spot/mc/mc_instanciator.hh: Only use them if they are present. * NEWS: Mention the fix. --- NEWS | 3 +++ configure.ac | 7 ++++++- spot/mc/mc_instanciator.hh | 9 +++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 26f45d376..747f78d64 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ New in spot 2.10.1.dev (not yet released) - twa_graph::purge_dead_states() now also removes edges labeled by bddfalse. + - only use sched_getcpu() and pthread_setaffinity_np() when they are + available. + New in spot 2.10.1 (2021-11-19) Build: diff --git a/configure.ac b/configure.ac index b708d080c..850496254 100644 --- a/configure.ac +++ b/configure.ac @@ -148,7 +148,12 @@ CHECK_ATOMIC AX_CHECK_BUDDY AC_CHECK_HEADERS([sys/times.h valgrind/memcheck.h spawn.h]) -AC_CHECK_FUNCS([times kill alarm sigaction]) +AC_CHECK_FUNCS([times kill alarm sigaction sched_getcpu]) + +oLIBS=$LIBS +LIBS="$LIBS -lpthread" +AC_CHECK_FUNCS([pthread_setaffinity_np]) +LIBS=$oLIBS LT_CONFIG_LTDL_DIR([ltdl]) LT_INIT([win32-dll]) diff --git a/spot/mc/mc_instanciator.hh b/spot/mc/mc_instanciator.hh index 39b9411d2..db7b35373 100644 --- a/spot/mc/mc_instanciator.hh +++ b/spot/mc/mc_instanciator.hh @@ -19,6 +19,8 @@ #pragma once +#include +#include #include #include #include @@ -31,7 +33,6 @@ #include #include #include -#include #include namespace spot @@ -115,7 +116,7 @@ namespace spot { threads[i] = std::thread ([&swarmed, &iomutex, i, &barrier] { -#if defined(unix) || defined(__unix__) || defined(__unix) +#ifdef SPOT_HAVE_SCHED_GETCPU { std::lock_guard iolock(iomutex); std::cout << "Thread #" << i @@ -129,8 +130,8 @@ namespace spot swarmed[i]->run(); }); -#if defined(unix) || defined(__unix__) || defined(__unix) - // Pins threads to a dedicated core. +#ifdef SPOT_PTHREAD_SETAFFINITY_NP + // Pin threads to a dedicated core. cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(i, &cpuset);