On Sun, Nov 21, 2021 at 07:58:55PM +0400, Roman Bogorodskiy wrote:
Recently, FreeBSD has got sched_get/setaffinity(3) implementations
and
the sched.h header as well [1]. To make these routines visible,
users have to define _WITH_CPU_SET_T.
This breaks current detection. Specifically, meson sees the
sched_getaffinity() symbol and defines WITH_SCHED_GETAFFINITY. This
define unlocks Linux implementation of virProcessSetAffinity() and other
functions, which fails to build on FreeBSD because cpu_set_t is not
visible as _WITH_CPU_SET_T is not defined.
For now, change detection to the following:
- Instead of checking sched_getaffinity(), check if 'cpu_set_t' is
available through sched.h
- Explicitly check the sched.h header instead of assuming its presence
if WITH_SCHED_SETSCHEDULER is defined
Makes sense, although even the sched_getaffinity() is guarded by the new
_WITH_CPU_SET_T so there should be no error with the current code, am I
right? And if I understand correctly we cannot use the FreeBSD
implementation as is because they do not have all the CPU_* macros we
need, right?
1:
https://cgit.freebsd.org/src/commit/?id=43736b71dd051212d5c55be9fa21c4599...
https://cgit.freebsd.org/src/commit/?id=160b4b922b6021848b6b48afc894d16b8...
https://cgit.freebsd.org/src/commit/?id=90fa9705d5cd29cf11c5dc7319299788d...
Signed-off-by: Roman Bogorodskiy <bogorodskiy(a)gmail.com>
---
meson.build | 4 +++-
src/util/virprocess.c | 8 ++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/meson.build b/meson.build
index 9022bcfdc9..e4f36e8574 100644
--- a/meson.build
+++ b/meson.build
@@ -553,7 +553,6 @@ functions = [
'posix_fallocate',
'posix_memalign',
'prlimit',
- 'sched_getaffinity',
'sched_setscheduler',
'setgroups',
'setns',
@@ -602,6 +601,7 @@ headers = [
'net/if.h',
'pty.h',
'pwd.h',
+ 'sched.h',
'sys/auxv.h',
'sys/ioctl.h',
'sys/mount.h',
@@ -671,6 +671,8 @@ symbols = [
# Check for BSD approach for setting MAC addr
[ 'net/if_dl.h', 'link_addr', '#include
<sys/types.h>\n#include <sys/socket.h>' ],
+
+ [ 'sched.h', 'cpu_set_t' ],
]
if host_machine.system() == 'linux'
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 6de3f36f52..81de90200e 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -35,7 +35,7 @@
# include <sys/time.h>
# include <sys/resource.h>
#endif
-#if WITH_SCHED_SETSCHEDULER
+#if WITH_SCHED_H
# include <sched.h>
#endif
@@ -480,7 +480,7 @@ int virProcessKillPainfully(pid_t pid, bool force)
return virProcessKillPainfullyDelay(pid, force, 0, false);
}
-#if WITH_SCHED_GETAFFINITY
+#if WITH_DECL_CPU_SET_T
int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet)
{
@@ -626,7 +626,7 @@ virProcessGetAffinity(pid_t pid)
return ret;
}
-#else /* WITH_SCHED_GETAFFINITY */
+#else /* WITH_DECL_CPU_SET_T */
int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED,
virBitmap *map G_GNUC_UNUSED,
@@ -646,7 +646,7 @@ virProcessGetAffinity(pid_t pid G_GNUC_UNUSED)
_("Process CPU affinity is not supported on this
platform"));
return NULL;
}
-#endif /* WITH_SCHED_GETAFFINITY */
+#endif /* WITH_DECL_CPU_SET_T */
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
--
2.33.1