meson: improve CPU affinity routines check

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

1:
https://cgit.freebsd.org/src/commit/?id=43736b71dd051212d5c55be9fa21c45993017fbb
https://cgit.freebsd.org/src/commit/?id=160b4b922b6021848b6b48afc894d16b879b7af2
https://cgit.freebsd.org/src/commit/?id=90fa9705d5cd29cf11c5dc7319299788dec2546a

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Roman Bogorodskiy 2021-11-21 15:56:06 +04:00
parent 9b0a6d959b
commit c07cf0a686
2 changed files with 7 additions and 5 deletions

View File

@ -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'

View File

@ -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)