meson: Restore check for sched_getaffinity()

Commit c07cf0a686 replaced this check with one for the
presence of cpu_set_t.

The idea at the time was that only sched_{get,set}affinity()
were visible by default, while making cpu_set_t visible required
defining _WITH_CPU_SET_T. So libvirt would detect the function
and attempt to use it, but the code would not compile because
the necessary data type had not been made accessible.

The commit in question brought three FreeBSD commits as evidence
of this. While [1] and [2] do indeed seem to support this
explanation, [3] from just a few days later made it so that not
just cpu_set_t, but also the functions, required user action to
be visible. This arguably would have made the change unnecessary.

However, [4] from roughly a month later changed things once
again: it completely removed _WITH_CPU_SET_T, making both the
functions and the data type visible by default.

This is the status quo that seems to have persisted until
today. If one were to check any recent FreeBSD build job
performed as part of our CI pipeline, for example [5] and [6]
for FreeBSD 13 and 14 respectively, they would be able to
confirm that in both cases cpu_set_t is detected as available.

Since there is no longer a difference between the availability
of the functions and that of the data type, go back to what we
had before.

This has the interesting side-effect of fixing a bug
introduced by the commit in question.

When detection was changed from the function to the data type,
most uses of WITH_SCHED_GETAFFINITY were replaced with uses of
WITH_DECL_CPU_SET_T, but not all of them: specifically, those
that decided whether qemuProcessInitCpuAffinity() would be
actually implemented or replaced with a no-op stub were not
updated, which means that we've been running the stub version
everywhere except on FreeBSD ever since.

The code has been copied to the Cloud Hypervisor driver in
the meantime, which is similarly affected. Now that we're
building the actual implementation, we need to add virnuma.h
to the includes.

As a nice bonus this also makes things work correctly on
GNU/Hurd, where cpu_set_t is available but
sched_{get,set}affinity() are non-working stubs.

[1] https://cgit.freebsd.org/src/commit/?id=160b4b922b6021848b6b48afc894d16b879b7af2
[2] https://cgit.freebsd.org/src/commit/?id=43736b71dd051212d5c55be9fa21c45993017fbb
[3] https://cgit.freebsd.org/src/commit/?id=90fa9705d5cd29cf11c5dc7319299788dec2546a
[4] https://cgit.freebsd.org/src/commit/?id=5e04571cf3cf4024be926976a6abf19626df30be
[5] https://gitlab.com/libvirt/libvirt/-/jobs/6266401204
[6] https://gitlab.com/libvirt/libvirt/-/jobs/6266401205

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2024-02-27 15:52:15 +01:00
parent 593da429ff
commit 526e7ee15a
3 changed files with 5 additions and 5 deletions

View File

@ -584,6 +584,7 @@ functions = [
'posix_fallocate', 'posix_fallocate',
'posix_memalign', 'posix_memalign',
'prlimit', 'prlimit',
'sched_getaffinity',
'sched_setscheduler', 'sched_setscheduler',
'setgroups', 'setgroups',
'setrlimit', 'setrlimit',
@ -682,8 +683,6 @@ symbols = [
# Check for BSD approach for setting MAC addr # Check for BSD approach for setting MAC addr
[ 'net/if_dl.h', 'link_addr', '#include <sys/types.h>\n#include <sys/socket.h>' ], [ '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' if host_machine.system() == 'linux'

View File

@ -33,6 +33,7 @@
#include "virfile.h" #include "virfile.h"
#include "virjson.h" #include "virjson.h"
#include "virlog.h" #include "virlog.h"
#include "virnuma.h"
#include "virstring.h" #include "virstring.h"
#include "ch_interface.h" #include "ch_interface.h"

View File

@ -500,7 +500,7 @@ virProcessGetAffinity(pid_t pid)
return ret; return ret;
} }
#elif WITH_DECL_CPU_SET_T #elif defined(WITH_SCHED_GETAFFINITY)
int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet) int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet)
{ {
@ -592,7 +592,7 @@ virProcessGetAffinity(pid_t pid)
return ret; return ret;
} }
#else /* WITH_DECL_CPU_SET_T */ #else /* ! (defined(WITH_BSD_CPU_AFFINITY) || defined(WITH_SCHED_GETAFFINITY)) */
int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED, int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED,
virBitmap *map G_GNUC_UNUSED, virBitmap *map G_GNUC_UNUSED,
@ -612,7 +612,7 @@ virProcessGetAffinity(pid_t pid G_GNUC_UNUSED)
_("Process CPU affinity is not supported on this platform")); _("Process CPU affinity is not supported on this platform"));
return NULL; return NULL;
} }
#endif /* WITH_DECL_CPU_SET_T */ #endif /* ! (defined(WITH_BSD_CPU_AFFINITY) || defined(WITH_SCHED_GETAFFINITY)) */
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)