From 6402191f6de8e1c59164cc710b8f4a5e54dd75cd Mon Sep 17 00:00:00 2001 From: Bas Raayman Date: Fri, 19 Nov 2021 13:34:38 +0100 Subject: [PATCH 1/2] Add vCPU hard pinning --- client/v3/v3_structs.go | 6 ++++++ .../data_source_nutanix_virtual_machine.go | 9 +++++++++ nutanix/resource_nutanix_virtual_machine.go | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/client/v3/v3_structs.go b/client/v3/v3_structs.go index f543d3d74..e9e73cb09 100644 --- a/client/v3/v3_structs.go +++ b/client/v3/v3_structs.go @@ -286,6 +286,9 @@ type VMResources struct { // Indicates whether to passthrough the host’s CPU features to the guest. Enabling this will disable live migration of the VM. EnableCPUPassthrough *bool `json:"enable_cpu_passthrough,omitempty" mapstructure:"enable_cpu_passthrough,omitempty"` + // Indicates whether a VMs cores are getting pinned on either CPU1, CPU2, CPU3 or CPU4. By default, the Linux Scheduler in AHV will pin all cores wherever they are best available. + EnableCPUPinning *bool `json:"is_vcpu_hard_pinned,omitempty" mapstructure:"is_vcpu_hard_pinned,omitempty"` + // Information regarding vNUMA configuration. VMVnumaConfig *VMVnumaConfig `json:"vnuma_config,omitempty" mapstructure:"vnuma_config,omitempty"` @@ -516,6 +519,9 @@ type VMResourcesDefStatus struct { // Indicates whether to passthrough the host’s CPU features to the guest. Enabling this will disable live migration of the VM. EnableCPUPassthrough *bool `json:"enable_cpu_passthrough,omitempty" mapstructure:"enable_cpu_passthrough,omitempty"` + // Indicates whether a VMs cores are getting pinned on either CPU1, CPU2, CPU3 or CPU4. By default, the Linux Scheduler in AHV will pin all cores wherever they are best available. + EnableCPUPinning *bool `json:"is_vcpu_hard_pinned,omitempty" mapstructure:"is_vcpu_hard_pinned,omitempty"` + // Information regarding vNUMA configuration. VnumaConfig *VMVnumaConfig `json:"vnuma_config,omitempty" mapstructure:"vnuma_config,omitempty"` diff --git a/nutanix/data_source_nutanix_virtual_machine.go b/nutanix/data_source_nutanix_virtual_machine.go index c4806ea66..cb84ca9e7 100644 --- a/nutanix/data_source_nutanix_virtual_machine.go +++ b/nutanix/data_source_nutanix_virtual_machine.go @@ -198,6 +198,10 @@ func dataSourceNutanixVirtualMachine() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Computed: true, + }, "num_vnuma_nodes": { Type: schema.TypeInt, Computed: true, @@ -802,6 +806,7 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{ d.Set("description", utils.StringValue(resp.Status.Description)) d.Set("state", utils.StringValue(resp.Status.State)) d.Set("enable_cpu_passthrough", utils.BoolValue(resp.Status.Resources.EnableCPUPassthrough)) + d.Set("is_vcpu_hard_pinned", utils.BoolValue(resp.Status.Resources.EnableCPUPinning)) d.Set("num_vnuma_nodes", utils.Int64Value(resp.Status.Resources.VnumaConfig.NumVnumaNodes)) d.Set("guest_os_id", utils.StringValue(resp.Status.Resources.GuestOsID)) d.Set("power_state", utils.StringValue(resp.Status.Resources.PowerState)) @@ -1007,6 +1012,10 @@ func resourceNutanixDatasourceVirtualMachineInstanceResourceV0() *schema.Resourc Type: schema.TypeBool, Computed: true, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Computed: true, + }, "num_vnuma_nodes": { Type: schema.TypeInt, Computed: true, diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index eed654c6d..7e608ac0b 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -291,6 +291,11 @@ func resourceNutanixVirtualMachine() *schema.Resource { Optional: true, Default: false, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "use_hot_add": { Type: schema.TypeBool, Optional: true, @@ -1083,6 +1088,7 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{}) } d.Set("enable_cpu_passthrough", resp.Status.Resources.EnableCPUPassthrough) + d.Set("is_vcpu_hard_pinned", resp.Status.Resources.EnableCPUPinning) d.Set("guest_customization_cloud_init_user_data", cloudInitUser) d.Set("guest_customization_cloud_init_meta_data", cloudInitMeta) d.Set("hardware_clock_timezone", utils.StringValue(resp.Status.Resources.HardwareClockTimezone)) @@ -1195,6 +1201,11 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ // TODO: Is this correct? hotPlugChange = false } + if d.HasChange("is_vcpu_hard_pinned") { + _, n := d.GetChange("is_vcpu_hard_pinned") + res.EnableCPUPinning = utils.BoolPtr(n.(bool)) + hotPlugChange = false + } if d.HasChange("num_vnuma_nodes") { _, n := d.GetChange("num_vnuma_nodes") res.VMVnumaConfig = &v3.VMVnumaConfig{ @@ -1645,6 +1656,9 @@ func getVMResources(d *schema.ResourceData, vm *v3.VMResources) error { if v, ok := d.GetOk("enable_cpu_passthrough"); ok { vm.EnableCPUPassthrough = utils.BoolPtr(v.(bool)) } + if v, ok := d.GetOk("is_vcpu_hard_pinned"); ok { + vm.EnableCPUPinning = utils.BoolPtr(v.(bool)) + } if v, ok := d.GetOk("num_sockets"); ok { vm.NumSockets = utils.Int64Ptr(int64(v.(int))) } @@ -2448,6 +2462,11 @@ func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource { Optional: true, Default: false, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "num_vnuma_nodes": { Type: schema.TypeInt, Optional: true, From b3660eac86c0b69508bdc4a1e3ebb3007de00902 Mon Sep 17 00:00:00 2001 From: Bas Raayman Date: Fri, 3 Dec 2021 12:02:00 +0100 Subject: [PATCH 2/2] add cpu pinning to documentation --- website/docs/r/virtual_machine.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index 5773b01fb..e7a40267f 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -100,6 +100,7 @@ The following arguments are supported: * `use_hot_add`: - (Optional) Use Hot Add when modifying VM resources. Passing value false will result in VM reboots. Default value is `true`. * `num_threads_per_core`: - (Optional) Number of threads per core. * `enable_cpu_passthrough`: - (Optional) Add true to enable CPU passthrough. +* `is_vcpu_hard_pinned`: - (Optional) Add true to enable CPU pinning. ### Disk List