Understanding ESXi CPU scheduling – Hyper threading

Hyper threading is one of the most confused concepts, first something around hyper threading Definition.

Hyper-threading (officially called Hyper-Threading Technology or HT Technology, and abbreviated as HTT or HT) is Intel’s proprietary simultaneous multi threading (SMT) implementation used to improve parallelization of computations (doing multiple tasks at once) performed on x86 microprocessors.  For each processor core that is physically present, the operating system addresses two virtual (logical) cores and shares the workload between them when possible. The main function of hyper-threading is to increase the number of independent instructions in the pipeline; it takes advantage of superscalar architecture, in which multiple instructions operate on separate data in parallel (* source Wikipedia)

What it means is, if you have a CPU with hyper threading enabled it creates 1 virtual copy of the physical core. As a result the virtual machines can see 2 logical processors. As a result, the number of vCPU you can assign to the VM doubles. This does not mean the processing power doubles.

The processing power of your CPU remains same, the speed still remains same. What changes is you now use maximum amount of CPU and reduce CPU idle time (host CPU IDLE, we will talk about %IDLE when discussing ESXTOP).

withoutHT

In a non-hyper threaded core the Core gets one instruction, processor executes the instruction and then waits till the next instruction is scheduled on to it. Thus there is an IDLE time in between for the processor.

Sometimes there are cases when there is IDLE time also due to following reasons

  1. Cache Miss – data needed to execute a certain instruction is not available in the cache.
  2. Branch Misdirection – the prediction which direction the branch will go is wrong
  3. Data dependency – there is dependency on some other data to process instruction.

(* please read instruction life cycle for more details)

Now during the above 3 reasons not even the full cycle is used and CPU power is wasted.

With Hyper threaded systems the, the processor duplicates certain sections of the processor, specifically those that store architectural state, but does not duplicate the main execution resource.

In effect the OS will see 2 logical processors instead of 1.

Note: 1 of those is the physical core and other is virtual Core.

Now the OS can schedule 2 instructions at same time.

WithHT

The processor now does not have to wait for the next instruction to co in and the CPU IDLE time is less. This in effect will increase the performance of the OS. What we need to keep in mind is that the physical core is scheduled on priority over the virtual core. Also the heavy instructions will be given priority to run over the physical core and the smaller instruction will be queued.

The OS is unaware of this and will schedule all the instructions evenly.

There is an additional level of complexity when it comes to Virtualizations as the Guest OS does not have control of the physical core, this is handled by ESXi schedular. We will cover this in right sizing the VM topic.

Some Myths around Hyper threading

  1. Hyper threading doubles the number of processors – No, it only creates logical processor and allows time sharing
  2. Hyper threading doubles the performance of processor – No, in fact there is only around 30 % gain in performance due to less wastage total performance is still only 66% of max capacity.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s