The Secret Of CPU HYPERTHREADING In Depth


👤 Diwas Poudel    🕒 Jan 16 2020    📁 Fix    📜 0 comment

HyperThreading

Actually most of us are not much familiar with Hyperthreading technology. But this technology is not new to this world. Intel is using it for around 18 to 20 years. This technology is one of the great revolutions in the processor industry.

                   This Technology should be interesting to you if you're gamer or technology freak. 

Short History

HyperThreading Technology is originally developed by Digital Equipment Corporation, however, it was brought to market by Intel with x86 bit architecture Foster MP-Based Xeon Processor in February 2002 and in Pentium 4 Desktop CPUs in November 2002. This Intel Pentium 4 with a 3.06 GHz processor was the first processor in history to break the 3 GHz barrier (officially announced). Intel Pentium 4 becomes the first HyperThreading desktop processor. So, we can say the Pentium 4 desktop was first to process two independent threads at the same time.

Later, in the ItaniumAtomand Core seriesIntel also included the technology.

Intel has already licensed the patents for "Hyperthreading" in 1997 AD and was bought late to the market in 2002 AD.

Evolution of CPU Hyperthreading (in short)

There are mainly three types of CPU available in the market.

1) Single Core CPU

In single-core based CPU,  multitasking is done with context switching but can do just one task at a time. Each core has only one thread. Then came MultiCore CPU

2) MultiCore CPU

In multi-core based CPU, each core has separate circuitry(hardware) and its own cache and can read and execute instruction separately. Core and Core work parallelly and don't interleave. A dual-core processor is considered a CPU with two physical cores and the quad-core processor is called four physical cores. Then came a Hyperthreading CPU.

3) Hyperthreading CPU

Explained below 👇

 

 

fig: Intel Pentium4 Processor

Intel® first Hyperthreading Pentium® 4 Processor features are:

Product Collection Legacy Intel® Pentium® Processor
Code Name Products formerly Northwood
No. of Cores 1
No. of Thread  2
Processor Base Frequency 3.06 GHz
Cache 512 KB L2 Cache
Bus Speed 533 MHz FSB
Intel Turbo Boost Technology
Intel 64
Intel Hyperthreading Technology
Instruction Set 32 bit

for more visits here.


What is Hyperthreading?

Hyperthreading Technology is hardware techniques of the simultaneous multithreading (SMT) implementation from Intel and is mainly developed to improve overall superscalar CPU performance by properly utilizing CPU idle time while performing several tasks. It's usually known as HT Technology.

SMT is the most widely used multithreading techniques nowadays.

In general, Hyper-threading is a mechanism whereby a CPU divides up its physical cores into virtual/logical cores and OS treated those logical cores as if they are actually physical cores. So, here OS got tricked.Therefore, OS schedules two tasks on 2 virtual cores as used to do on 2 physical cores in a multiprocessor system. 

Note that such virtual cores / logical cores are also known as the threads. Suppose Intel CPU has 2 cores then using HT Technology, 4 Threads or 4 Logical Cores/ Virtual Cores is created.

Example:

If I have a computer that has a 4-core processor, runs two threads per core, then


Logical Cores = # of Physical Core * Thread on each core

Therefore, Logical Cores = 4 * 2 = 8 cores

Explanation: This above-mentioned hardware has a 4 core (4 physical processor units) processor and has 2 threads in every core so this has a total of (4 *2) = 8 logical CPU.

This concept of behaving 1 processor (physical processor) as 2 processors (logical processor) is hyperthreading.

 

In a nutshell, we can run a lot of applications at the same time with high performance if you have a hyperthreaded CPU. Also Hyper-threading usually doesn't make your CPU much faster, but what it does is make it smoother and more responsive and help you clean up the hits and stutters that occur when you run out of threads.

Technical Details on HyperThreading

Hyperthreading creates two logical processors from one physical core. There are two separate hardware registers ( called architectural states) on each core. Therefore each hardware register has a separate program counter and stack pointer. But both of them will share internal microarchitecture components called execution units. So, hardware can switch between two threads ( two logical processors) by selecting register set A or register set B.

Fig: CPU with Hyperthreading (source info )

During the processing of threads, some of the inner components of the core (called executive units) are always idle in any clock cycle. By enabling hyper-threading, the execution units will simultaneously process instructions from two threads so that only for much less time execution units will be idle during each clock cycle.

In other words, Hyperthreading helps to hide the latency of the memory and allow prefetch buffers and other elements within the CPU instruction pipeline to remain full by alternating the tasks. The tasks that they are operating on to ensure that all the various execution units within the CPU are basically busy at any given point in time.

 

 

Myth of HyperThreading

  • Physical Core is the same as Logical / Virtual Core.
  • Hyper-Threading is the same as HyperTransport.
  • Hyperthreading does practically double the physical core of the CPU.

Performance Claims of HyperThreading

Intel boosts up to a 30% performance improvement compared with an otherwise identical, non-simultaneous multithreading Pentium 4 Computer.

HyperThreading Parallelism?

Hyperthreading can't do much for a single-threaded processor in your computer where you can operate only on one task at a time.

Task running in one virtual core is independent of other virtual core operating in the same core processor. Also, two virtual cores within one physical core cannot truly operate in parallel with respect to each other. But works interleaving or concurrency so that one logical processor does half of the task on one work and another logical processor does half on other work and soon and continuously interleaved.

Application of HyperThreading

How much benefit you will get from hyperthreading depends on what you are actually doing. Advantage of hyperthreading depends on the types of workloads and it falls two categories in general:

1)Extensive Multi-Tasking workflows.

Hyperthreading is a valuable feature if your workflow consists of a long chain of resources using tasks and you need to do many tasks at once. 

2)Workloads that makes CPU load for a maximum of 100% of the time.

You will not get any benefit of hyperthreading when you are just using common applications like web browsers, wordprocessors, emailing. To take advantage of Hyperthreading you must run heavy applications like graphics, multimedia gaming. You may get the benefit of hyperthreading if runs application like MAYA, Photoshop, Illustrator, etc

                     Hyper Threading's greatest advantage is that the CPU remains active all/much of the time.

Image Depicting CPU Hyperthreading

Check Hyperthreading is available in your System

Do you have hyperthreading in your system? There are various ways of knowing whether your system is hyperthreading enabled system or not?

Method 1: Using TaskManager (Simplest Way)

  • To open the Task Manager, press Ctrl + Shift + Esc keys simultaneously.
  • Go to the Performance tab
  • Select the CPU section from the left pane.
  • On the bottom right you will see the number of physical processors and logical processors.

 

💡 Note! If the number of the logical processors is the same as core then it's clear that your system has no hyperthreading support or hyperthreading is not enabled.

Method 2: Using wmic command ( For Command Lover )

Open command prompt and type "wmic" and press "Enter"

 wmic

This will activate wmic interface and then type below code and press Enter

CPU Get NumberOfCores,NumberOfLogicalProcessors /Format:List

There you get the total logical and physical processor as shown below:

  • NumberOfCores=2

  • NumberOfLogicalProcessors=4

Here, Total Logical Processor is 4 so , on each physical processor we have 4/2 = 2 logical processor.

Check-in Your Linux System 

Type lscpu in the command line and press Enter and look at "Thread(s) per core" section as shown below:

 

Architecture:        x86_64                                                                                                                            
CPU op-mode(s):      32-bit, 64-bit                                                                                                                    
Byte Order:          Little Endian                                                                                                                     
CPU(s):              8                                                                                                                                 
On-line CPU(s) list: 0-7                                                                                                                               
Thread(s) per core:  2     // Look Here                                                                                                                             
Core(s) per socket:  4                                                                                                                                 
Socket(s):           1                                                                                                                                 
NUMA node(s):        1                                                                                                                                 
Vendor ID:           GenuineIntel                                                                                                                      
CPU family:          6                                                                                                                                 
Model:               158                                                                                                                               
Model name:          Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz                                                                                         
-----      

If you haven't enabled hyperthreading in your system then these techniques will not work.

 

When to test Hyperthreading

You can test and know-how actually hyperthreading is helping if below condition meets:

  • If the server has more than one CPU socket.
  • If the server supports a large number of cores per socket.
  • If the running application is a single-threaded application or does not efficiently handle multiple threads.
  • The application has an extremely high memory rate.

It is also important to remember that hyperthreading is not routinely used by the system with the Windows Performance Monitor tool with the CPU load of 0 -50 percent.

 

The goal of Hyperthreading CPU

1) If you have to buy a CPU with 4 cores then it cost more than 4 logical cores CPU. So the main goal of CPU hyperthreading technology is to minimize cost so that the logical processor technology will get more improvements in the future.

2) Also other is for making CPU fully active all the time.

Advantage of HyperThreading

  • It increases core performance.
  • It can use high ends apps and games.
  • It can enhance time for response and reaction of the system.
  • It increases no. of transactions that can be executed.
  • It can handle increased server workloads.
  • It reduces memory latency.
  • It can improve overall system performance
  • It makes the system more responsive.
  • It smoothes out computer experiences.
  • Utilize existing 32-bit application technologies while ensuring and maintaining 64-bit future readiness.
  • The number of transactions that can be executed can be increased.

Disadvantage of Hyperthreading

  • Shared resource conflicts may occur.
  • Threads are non-deterministic and involved extra design overload.