]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: support vcpu pinning
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 4 Feb 2026 18:39:43 +0000 (19:39 +0100)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Thu, 19 Feb 2026 17:51:23 +0000 (18:51 +0100)
Bhyve supports vcpu pinning using the `-p vcpu:hostcpu`
argument. This argument can be specified multiple times for the same
vcpu to pin it to multiple hostcpu's.

Bhyve currently does not allow to change vcpu pinning configuration for
the VM that is already running.

Use this to support domain's vcpupin configuration such as:

  <cputune>
    <vcpupin vcpu="0" cpuset="1,2,3"/>
  </cputune>

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/drvbhyve.rst
src/bhyve/bhyve_command.c
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.args [new file with mode: 0644]
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.xml [new file with mode: 0644]
tests/bhyvexml2argvtest.c

index 5a45e9056f4eb3ae1ece9d9efe698845f900cc5f..f4aec9ffadd68730fd9e4eb18a820beab229607a 100644 (file)
@@ -737,6 +737,26 @@ Example:
 Please refer to ``cam(4)``, ``ctl(4)``, and ``ctld(8)`` manual pages
 for more details on CAM and CTL.
 
+vCPU pinning
+~~~~~~~~~~~~
+
+:since:`Since 12.1.0`, it is possible to pin domain vCPUs
+to the specific host CPUs.
+
+Example:
+
+::
+
+  <domain type='bhyve'>
+    ...
+    <vcpu>2</vcpu>
+    <cputune>
+      <vcpupin vcpu="0" cpuset="1-4,^2"/>
+      <vcpupin vcpu="1" cpuset="0,4"/>
+    </cputune>
+    ...
+  </domain>
+
 Guest-specific considerations
 -----------------------------
 
index 417daefa7fc00678fe1339638d1aaa38ce29cc28..37618812bcf65e74893fbd45b659fb5c3c95b82a 100644 (file)
@@ -940,6 +940,21 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
         virCommandAddArgFormat(cmd, "%d", nvcpus);
     }
 
+    /* CPU tuning */
+    for (i = 0; i < virDomainDefGetVcpusMax(def); i++) {
+        virDomainVcpuDef *vcpu = virDomainDefGetVcpu(def, i);
+
+        if (vcpu->cpumask) {
+            ssize_t j = -1;
+
+            while ((j = virBitmapNextSetBit(vcpu->cpumask, j)) >= 0) {
+                virCommandAddArg(cmd, "-p");
+                virCommandAddArgFormat(cmd, "%zu:%zu", i, j);
+            }
+
+        }
+    }
+
     /* Memory */
     virCommandAddArg(cmd, "-m");
     virCommandAddArgFormat(cmd, "%llu",
diff --git a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.args b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.args
new file mode 100644 (file)
index 0000000..c873766
--- /dev/null
@@ -0,0 +1,15 @@
+bhyve \
+-c 2 \
+-p 0:1 \
+-p 0:3 \
+-p 0:4 \
+-p 1:0 \
+-p 1:4 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
+bhyve
diff --git a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.ldargs b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.ldargs
new file mode 100644 (file)
index 0000000..5905f4b
--- /dev/null
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.xml b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-vcpupin.xml
new file mode 100644 (file)
index 0000000..bfa13c7
--- /dev/null
@@ -0,0 +1,27 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>2</vcpu>
+  <cputune>
+    <vcpupin vcpu="0" cpuset="1-4,^2"/>
+    <vcpupin vcpu="1" cpuset="0,4"/>
+  </cputune>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
index 21d568088483cc49d1e9cd92db7d067744bcc54c..2330e70bbf6e0f2b357244e73a54340931fe60d4 100644 (file)
@@ -283,6 +283,7 @@ mymain(void)
     DO_TEST("slirp-mac-addr");
     DO_TEST_FAILURE("slirp-ip");
     DO_TEST("virtio-scsi");
+    DO_TEST("vcpupin");
 
     /* Address allocation tests */
     DO_TEST("addr-single-sata-disk");