FreeBSD 14 implements sched_{get,set}affinity() for
compatibility with Linux, but we should still use the native
syscalls instead.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/util/virprocess.c | 110 +++++++++++++++++++++---------------------
1 file changed, 55 insertions(+), 55 deletions(-)
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 8384bd1378..426d56c1ce 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -444,7 +444,61 @@ int virProcessKillPainfully(pid_t pid, bool force)
return virProcessKillPainfullyDelay(pid, force, 0, false);
}
-#if WITH_DECL_CPU_SET_T
+#if defined(WITH_BSD_CPU_AFFINITY)
+
+int virProcessSetAffinity(pid_t pid,
+ virBitmap *map,
+ bool quiet)
+{
+ size_t i;
+ cpuset_t mask;
+
+ CPU_ZERO(&mask);
+ for (i = 0; i < virBitmapSize(map); i++) {
+ if (virBitmapIsBitSet(map, i))
+ CPU_SET(i, &mask);
+ }
+
+ if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid,
+ sizeof(mask), &mask) != 0) {
+ if (quiet) {
+ VIR_DEBUG("cannot set CPU affinity on process %d: %s",
+ pid, g_strerror(errno));
+ } else {
+ virReportSystemError(errno,
+ _("cannot set CPU affinity on process %1$d"),
pid);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+virBitmap *
+virProcessGetAffinity(pid_t pid)
+{
+ size_t i;
+ cpuset_t mask;
+ virBitmap *ret = NULL;
+
+ CPU_ZERO(&mask);
+ if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid,
+ sizeof(mask), &mask) != 0) {
+ virReportSystemError(errno,
+ _("cannot get CPU affinity of process %1$d"),
pid);
+ return NULL;
+ }
+
+ ret = virBitmapNew(sizeof(mask) * 8);
+
+ for (i = 0; i < sizeof(mask) * 8; i++)
+ if (CPU_ISSET(i, &mask))
+ ignore_value(virBitmapSetBit(ret, i));
+
+ return ret;
+}
+
+#elif WITH_DECL_CPU_SET_T
int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet)
{
@@ -536,60 +590,6 @@ virProcessGetAffinity(pid_t pid)
return ret;
}
-#elif defined(WITH_BSD_CPU_AFFINITY)
-
-int virProcessSetAffinity(pid_t pid,
- virBitmap *map,
- bool quiet)
-{
- size_t i;
- cpuset_t mask;
-
- CPU_ZERO(&mask);
- for (i = 0; i < virBitmapSize(map); i++) {
- if (virBitmapIsBitSet(map, i))
- CPU_SET(i, &mask);
- }
-
- if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid,
- sizeof(mask), &mask) != 0) {
- if (quiet) {
- VIR_DEBUG("cannot set CPU affinity on process %d: %s",
- pid, g_strerror(errno));
- } else {
- virReportSystemError(errno,
- _("cannot set CPU affinity on process %1$d"),
pid);
- return -1;
- }
- }
-
- return 0;
-}
-
-virBitmap *
-virProcessGetAffinity(pid_t pid)
-{
- size_t i;
- cpuset_t mask;
- virBitmap *ret = NULL;
-
- CPU_ZERO(&mask);
- if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid,
- sizeof(mask), &mask) != 0) {
- virReportSystemError(errno,
- _("cannot get CPU affinity of process %1$d"),
pid);
- return NULL;
- }
-
- ret = virBitmapNew(sizeof(mask) * 8);
-
- for (i = 0; i < sizeof(mask) * 8; i++)
- if (CPU_ISSET(i, &mask))
- ignore_value(virBitmapSetBit(ret, i));
-
- return ret;
-}
-
#else /* WITH_DECL_CPU_SET_T */
int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED,
--
2.43.2