VMware Cloud Community
dtracey
Expert
Expert
Jump to solution

Disable Hyperthreading via PowerCLI

Hello Chaps,

Does anyone know a way of disabling CPU hyperthreading via PowerCLI?

I can report whether it's enabled or not with this:

Get-Host | Select-Object Name,HyperthreadingActive

But now I need to disable it...

Thanks,

Dan

0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, dtracey-

It looks like you can enable/disable hyperthreading on the host using the HostCpuSchedulerSystem, which is part of the HostConfigManager for the host.  So, for one host, it would be something like:

## host upon which to act
$strMyHostName = "myhost.domain.com"
## get the View object for the HostCpuSchedulerSystem
$viewHostCPUSchedulerSystem = Get-View (Get-View -ViewType HostSystem -Property ConfigManager.CpuScheduler -Filter @{"Name" = $strMyHostName}).ConfigManager.CpuScheduler
## disable hyperthreading
$viewHostCPUSchedulerSystem.DisableHyperThreading()

You could quickly adjust this to do all desired hosts, as you see fit.  Note, if the method succeeds, this tells the system to not "treat hyperthreads as schedulable resources the next time the CPU scheduler starts", per the docs.

View solution in original post

0 Kudos
8 Replies
mattboren
Expert
Expert
Jump to solution

Hello, dtracey-

It looks like you can enable/disable hyperthreading on the host using the HostCpuSchedulerSystem, which is part of the HostConfigManager for the host.  So, for one host, it would be something like:

## host upon which to act
$strMyHostName = "myhost.domain.com"
## get the View object for the HostCpuSchedulerSystem
$viewHostCPUSchedulerSystem = Get-View (Get-View -ViewType HostSystem -Property ConfigManager.CpuScheduler -Filter @{"Name" = $strMyHostName}).ConfigManager.CpuScheduler
## disable hyperthreading
$viewHostCPUSchedulerSystem.DisableHyperThreading()

You could quickly adjust this to do all desired hosts, as you see fit.  Note, if the method succeeds, this tells the system to not "treat hyperthreads as schedulable resources the next time the CPU scheduler starts", per the docs.

0 Kudos
dtracey
Expert
Expert
Jump to solution

Hi Matt,

Ive played around with your script, but can't seem to get it to work.  It appears that the DisableHyperThreading method doesnt exist.

Did you put that together from the vSphere 5 API documentation?  As if so, I'm working with ESXi 4.1 hosts.

Did the script work for you?

Thanks for your help.

Dan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The DisableHyperThreading method is available in vSphere 4.1.

And the call works, provided you have CPUs that support HT of course.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mattboren
Expert
Expert
Jump to solution

Hello, Dan-

Hmm.  Yes, as LucD pointed out, the method is available in vSphere 4.1 (just need CPUs that support hyperthreading).  Yes, the host CpuSchedulerSystem I was using did have that method available.

What error(s) do you get, and at what point?

To be sure that the object that $viewHostCPUSchedulerSystem object has the DisableHyperThreading() method, you can use the Get-Member cmdlet.  It should return something like:

PS C:\> $viewHostCPUSchedulerSystem | Get-Member

   TypeName: VMware.Vim.HostCpuSchedulerSystem

Name                  MemberType Definition
----                  ---------- ----------
DisableHyperThreading Method     System.Void DisableHyperThreading()
EnableHyperThreading  Method     System.Void EnableHyperThreading()
Equals                Method     bool Equals(System.Object obj)
GetHashCode           Method     int GetHashCode()

....

What does this return for you?

dtracey
Expert
Expert
Jump to solution

Hi Matt,

I did actually manage to get this to work.

I think the reason it was failing initially is that when I connected to the host, i was using connect-viserver to the IP address and not to the hostname.

It seems to be happy now that i'm connecting using the hostname, i assume because the value for $vmhost is the fqdn rather than the IP...

I'm just going to have to try and work out how to ignore this command if hyperthreading is already disabled, but that's another day!

Thanks for your help.


Dan

0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Dan,

Is there any specific reason to turn HT off ?

I thought that by enabling HT you can perform multitasking more.

/* Please feel free to provide any comments or input you may have. */
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is a nice collection of considerations in the post Hyper-threading on VMware vSphere


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dtracey
Expert
Expert
Jump to solution

Hi Albert,

Its a mix of business constraints (legacy concepts of security and physical CPU sharing), and technical constraints.  The (non Windows) OSes and apps that we run have been benchmarked and perform worse on HT CPUs.

It's a weird world!

Dan

0 Kudos