Configuring simultaneous multithreading


By default, Compute Engine enables simultaneous multithreading (SMT) on all virtual machine (VM) instances. With SMT enabled, a single physical CPU core can run 2 virtual CPUs (vCPUs), each as separate threads. You can disable SMT by reducing the number of threads—the number of effective vCPUs—per core to 1. This document describes how and why to change the number of threads that run on each physical CPU core.

Considerations for configuring SMT

Performance
Reducing the number of threads that run on each physical CPU core can help improve performance of workloads that are highly-parallel or that perform floating point calculations.
Security
If a VM runs untrusted code, reducing the number of threads per core can help mitigate CPU vulnerabilities such as Microarchitectural Data Sampling.

Limitations

The number of threads per core is not configurable on machine types that have fewer than 2 vCPUs, for example, n1-standard-1.

Pricing

You are billed for the number of vCPUs defined by a VM's machine type, not the number threads that run on each core. For example, the n2-standard-8 machine type can run up to 8 vCPUs, which is 2 vCPUs for each of the 4 physical CPU cores. If you decide to only run 1 thread per core—effectively 4 vCPUs—you are still billed for 8 vCPUs. For more information about how you are billed for VMs, see VM instance pricing.

Configuring SMT

Configure SMT on a VM by using the following procedure.

gcloud

Configure SMT while creating a VM by using the following gcloud beta compute instances create command:

gcloud beta compute instances create VM_NAME \
  --zone=ZONE \
  --machine-type=MACHINE_TYPE \
  --threads-per-core=THREADS_PER_CORE

Replace the following:

  • VM_NAME: the name for the new VM.

  • ZONE: the zone for the new VM.

  • MACHINE_TYPE: the machine type for the new VM. Must be a machine type with 2 or more vCPUs.

  • THREADS_PER_CORE: the number of threads per physical core. Current processors support 2 threads per core for SMT, which is enabled by default. To disable SMT, set to 1.

API

Configure SMT while creating a VM by using the instances.insert method with the threadsPerCore field.

POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances

{
  ⋮
  "advancedMachineFeatures": {
    "threadsPerCore": "THREADS_PER_CORE"
    },
  ⋮
}

Replace the following:

  • PROJECT_ID: the project ID.

  • ZONE: the zone for the new VM.

  • THREADS_PER_CORE: the number of threads per physical core. Current processors support 2 threads per core for SMT, which is enabled by default. To disable SMT, set to 1.

Verifying the SMT configuration

Verify the SMT configuration by using the procedure that corresponds to the OS that is running on the VM.

Linux

Verify the SMT configuration on Linux-based VMs by using the following procedure:

  1. Connect to the Linux VM.

  2. Run the lscpu command.

    lscpu
    
  3. In the output, verify the value for the number of threads per core.

    In the following sample output, the value for the number of threads per core is 1.

    ⋮
    CPU(s):              1
    On-line CPU(s) list: 0
    Thread(s) per core:  1
    Core(s) per socket:  1
    Socket(s):           1
    NUMA node(s):        1
    Vendor ID:           GenuineIntel
    CPU family:          6
    Model:               85
    Model name:          Intel(R) Xeon(R) CPU
    ⋮
    

Windows

Verify the SMT configuration on Windows-based VMs by using the following procedure:

  1. Connect to the Windows VM.

  2. Open the command-line interface for Windows Management Instrumentation (WMI).

    wmic
    
  3. View the number of cores and the number of logical processors by running the following command:

    CPU Get NumberOfCores,NumberofLogicalProcessors
    
  4. In the output, verify the value for the number of threads per core.

    In the following sample output, the value for the number of threads per core is 1.

    NumberOfCores  NumberOfLogicalProcessors
    1              1
    

What's next