在Java中启用Intel超线程 [英] Enable Intel Hyperthreading in Java

查看:395
本文介绍了在Java中启用Intel超线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在四核Intel i7上运行的多线程程序。当我执行 Runtime.getRuntime.availableProcessors()时,我得到8,我知道这个CPU上有超线程。

I have a multithreaded 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.

但是,当我创建线程时,我的CPU级别为4个线程的100%(即非零),这意味着4个线程未被使用。有没有办法在Java中启用超线程?

However, when I create threads, my CPU levels are at 100% (i.e. non-zero) for 4 threads, meaning that 4 threads are unused. Is there any way to enable hyperthreading in Java?

推荐答案

超线程是通过所有现代JVM使用本机线程的事实来实现的,因此这是OS / CPU配置设置。

Hyperthreading is enabled by the fact that all modern JVMs use native threads, thus this is a OS/CPU config setting.

但是,超线程不会为您提供额外的内核,它允许您拥有的四个cpu的细粒度分时。也就是说,当一个线程停止时,比如等待一页内存飞入缓存,然后另一个线程可以俯冲并利用CPU的一部分。由于更复杂的调度要求,它增加了大约10%的额外CPU大小,并且不会使所有应用程序受益。

However Hyperthreading does not give you extra cores, it permits fine grained timeshare of the four cpus that you have. That is, while one thread is stalled, say waiting for a page of memory to be flown into the cache then another thread can swoop in and make use of parts of the CPU. It adds about 10% extra to the size of a CPU core due to more complex scheduling requirements and does not benefit all applications.

如果你已经用四个线程最大化了四个cpus,那么打开或关闭超线程就可以了。它只是意味着那些线程正在运行,没有太多阻塞。

If you have maxed out the four cpus with four threads, then that is possible with hyperthreading turned on or off. It just means that those threads are running hot, without blocking much.

Java报告8核CPU而不是4核的原因是因为操作系统告诉Java CPU有8个核心。操作系统认为,由于操作系统已被告知调度线程就好像它是一个8核CPU,这使得对操作系统的超线程的支持更加简单。操作系统像以前一样继续管理线程,忽略了超线程的大部分内部工作,并让CPU在cpu部分可用时管理程序集的低级调度。

The reason that Java reports an 8 core CPU, rather than 4 is because the OS tells Java that the CPU has 8 cores. The OS believes that because the OS has been told to schedule threads as though it was an 8 core CPU, this made adding support of hyperthreading to OSes much simpler. The OS carries on managing threads as before, oblivious to much of the inner workings of hyperthreading and lets the CPU manage the low level scheduling of the assembly as and when parts of the cpu become available.

更详细的讨论,可以读取基准这里

A more detailed discussion, with benchmarks can be read here

这篇关于在Java中启用Intel超线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆