Skip to content

hypervisor/kubevirt: implement CPU pinning for HV=k (KubeVirt)#5676

Open
zedi-pramodh wants to merge 1 commit intolf-edge:masterfrom
zedi-pramodh:cpu-pinning-support
Open

hypervisor/kubevirt: implement CPU pinning for HV=k (KubeVirt)#5676
zedi-pramodh wants to merge 1 commit intolf-edge:masterfrom
zedi-pramodh:cpu-pinning-support

Conversation

@zedi-pramodh
Copy link

When CPUsPinned is set on a domain config, the KubeVirt VMI spec now:

  • Sets DedicatedCPUPlacement=true so the KubeVirt CPU Manager pins each vCPU to a unique physical CPU thread
  • Sets CPU Requests==Limits and Memory Requests==Limits in the VMI domain resources to achieve Kubernetes Guaranteed QoS, which is required by the kubelet static CPU Manager policy to honour dedicated CPU placement

Additional changes to complete CPU pinning support for HV=k (KubeVirt):

  1. pkg/kube/kubevirt-features.yaml Add CPUManager to the KubeVirt CR featureGates list so KubeVirt's CPU Manager integration is activated on fresh installs.

  2. pkg/kube/kubevirt-utils.sh Update Kubevirt_migrate_feature_gates() to detect and patch in the CPUManager gate on upgrade from older EVE images. The sentinel check is updated from VideoConfig to CPUManager (the newest required gate) so the patch runs once on any image that lacks it.

  3. pkg/kube/config.yaml Add cpu-manager-policy=static and cpu-manager-reconcile-period=5s to the k3s kubelet-arg list. The static policy is required by Kubernetes for exclusive (pinned) CPU allocation: pods must be in Guaranteed QoS (Requests == Limits) and the kubelet will then assign dedicated pCPUs. The reconcile period keeps the CPU Manager state in sync quickly.

  4. Refactor the code in Kubevirt VM start where it is leading to infinite loop in case of error in ReplicaSet creation.

How to test and validate this PR

  1. Create a VM with CPU pinning enabled.
  2. Once the VM starts verify that qemu process has the affinity set using task set command.
  3. Launch another VM with CPU pinning enabled even if sufficient CPUs are not available, that VM will be in Pending start state.
  4. Delete VM from step2 and notice VM in steps 3 will start since it got CPU

Changelog notes

CPU Pinning support for eve-k VMs

Checklist

  • I've provided a proper description
  • I've added the proper documentation
  • I've tested my PR on amd64 device
  • I've written the test verification instructions

And the last but not least:

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

Please, check the boxes above after submitting the PR in interactive mode.

When CPUsPinned is set on a domain config, the KubeVirt VMI spec now:
- Sets DedicatedCPUPlacement=true so the KubeVirt CPU Manager pins
  each vCPU to a unique physical CPU thread
- Sets CPU Requests==Limits and Memory Requests==Limits in the VMI domain resources to achieve
  Kubernetes Guaranteed QoS, which is required by the kubelet static
  CPU Manager policy to honour dedicated CPU placement

Additional changes to complete CPU pinning support for HV=k (KubeVirt):

1. pkg/kube/kubevirt-features.yaml
   Add CPUManager to the KubeVirt CR featureGates list so KubeVirt's
   CPU Manager integration is activated on fresh installs.

2. pkg/kube/kubevirt-utils.sh
   Update Kubevirt_migrate_feature_gates() to detect and patch in the
   CPUManager gate on upgrade from older EVE images. The sentinel check
   is updated from VideoConfig to CPUManager (the newest required gate)
   so the patch runs once on any image that lacks it.

3. pkg/kube/config.yaml
   Add cpu-manager-policy=static and cpu-manager-reconcile-period=5s to
   the k3s kubelet-arg list. The static policy is required by Kubernetes
   for exclusive (pinned) CPU allocation: pods must be in Guaranteed QoS
   (Requests == Limits) and the kubelet will then assign dedicated pCPUs.
   The reconcile period keeps the CPU Manager state in sync quickly.

4. Refactor the code in Kubevirt VM start where it is leading to infinite loop in case of
   error in ReplicaSet creation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Pramodh Pallapothu <pramodh@zededa.com>
@codecov
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 29.49%. Comparing base (2281599) to head (8958df5).
⚠️ Report is 339 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5676      +/-   ##
==========================================
+ Coverage   19.52%   29.49%   +9.96%     
==========================================
  Files          19       18       -1     
  Lines        3021     2417     -604     
==========================================
+ Hits          590      713     +123     
+ Misses       2310     1552     -758     
- Partials      121      152      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rene
Copy link
Contributor

rene commented Mar 16, 2026

@zedi-pramodh , LGTM, just minor things:

  1. There is one valid Yetus error to fix
  2. We don't add newlines between the Co-Authered-By/Signed-off-by lines, so in your commit you can just put like this:
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Pramodh Pallapothu <pramodh@zededa.com>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants