Enable Intel Hyperthreading in Java

I have a multi-threaded program running on a quad-core Intel i7. When I execute Runtime.getRuntime.availableProcessors() , I get 8, and I know that hyperthreading is available on this CPU.

However, when I create threads, my processor levels are 100% (i.e. non-zero) for 4 threads, which means that 4 threads are not used. Is there a way to enable hyperthreading in Java?

+3
source share
2 answers

Hyper-threading is ensured by the fact that all modern JVMs use their own threads, so this is the OS / CPU configuration setting.

However, Hyperthreading does not give you extra cores, it allows you to get a fine-grained timeshare from the four processors that you have. That is, while one thread stalled, let's say, expecting the memory page to fly into the cache, then another thread could crash and use parts of the processor. It adds about 10% to the size of the processor core due to more complex planning requirements and does not bring benefits to all applications.

If you allocated four cpus with four threads, then this is possible when turning on or off the hyperflow. It just means that these threads are hot, without blocking.

The reason Java reports an 8-core processor rather than 4 is because the OS tells Java that the processor has 8 cores. The OS believes that since the OS was told to plan threads as if it were an 8-core processor, this made adding hyper-thread support to the OS much easier. The OS continues to manage threads as before, ignoring most of the internal workflow of the hyperthread and allows the processor to control low-level assembly planning when and when parts of the processor become available.

A more detailed discussion with standards can be found here.

+6
source

Use the following command

 $ lscpu 

The output can be used to determine the actual number of cores, and if you have hyperthreading enabled or not.

 Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 32 On-line CPU(s) list: 0-31 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 45 Stepping: 7 CPU MHz: 2399.995 BogoMIPS: 4799.35 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 20480K NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30 NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 

The actual parallelism that can be achieved will be (Number of sockets) X (Cores per socket) X (Threads per core). To determine if your processor is hyperthreaded or not, you can use the Threads per core parameter.

+1
source

Source: https://habr.com/ru/post/984608/


All Articles