如何确定是否编程多核,超线程处理器或多处理器?多核、处理器、超线程、或多

2023-09-07 00:43:35 作者:罗密欧与猪过夜

我知道如何让处理器类型,也许这是唯一的办法,但实际上,我在寻找的的的方式从一个应用程序,以确定是否它在一个多核心处理器或运行超线程的单核处理器的

I know how to get the processor type, perhaps that's the only way, but I'm actually looking for a way to determine from an application whether it's running on a multi-core processor or on a hyper-threading single-core processor.

(背景:我的一些客户的托管服务提供商是非常模糊的什么资源,他们做可以通过VMware映像此应用程序应该在多内核上运行,但已经看到了自上次移动有损性能。通常情况下,在多核心,一个核心的尖峰上一个线程,而不是其他。在这个多核心,这两种处理器秒杀,即使是在单线程应用程序。)

(background: the hosting providers of some of my clients are very vague about what resources they make available through VMWare images. This application is supposed to run on multi-core, but has seen detrimental performance since its last "move". Normally, on multi-core, one core spikes on one thread, and not the other. On this "multi-core", both processors spike, even on single-threaded applications.)

推荐答案

System.Environment.ProcessorCount其中也将包括超线程处理器。了VMware可能会或可能不会暴露。机会是较高的,如果启用了该处理器的VT将被曝光,使用的是baremetal启用管理程序技术。

System.Environment.ProcessorCount Which will also include hyperthreaded processors. Which Vmware may or may not expose. Chances are higher that it will be exposed if the the processor is VT enabled AND you are using a baremetal enabled hypervisor technology.

如果您有XP的SP3 / WIN2K3或以上,您可以使用WMI拔出:

If you have XP-SP3/WIN2k3 or above You can use WMI to pull out:

Win32_ComputerSystem.NumberOfProcessors returns physical count

Win32_ComputerSystem.NumberOfLogicalProcessors returns logical count

如果值是相同的,那么很有可能你的系统没有HT或者没有启用它。

If the values are the same then chances are your system does not have HT or does not have it enabled.

您可以开始探索如何从本教程

You can start exploring how to pull out WMI info in .NET from this tutorial.