Getting number of CPU

Hi All,

How can I get number of CPUs on machine from kernel mode?
If Hyperthreading is enabled, how can I get the number of “physical” CPUs?

Thanks,
Ronen.

Getting number of CPU KeNumberProcessors for the first question.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: Ronen Ochman
To: Windows System Software Devs Interest List
Sent: Wednesday, August 11, 2004 5:30 PM
Subject: [ntdev] Getting number of CPU

Hi All,

How can I get number of CPUs on machine from kernel mode?
If Hyperthreading is enabled, how can I get the number of “physical” CPUs?

Thanks,
Ronen.


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Ronen Ochman wrote:
>

How can I get number of CPUs on machine from kernel mode?
If Hyperthreading is enabled, how can I get the number of “physical” CPUs?

The number of logical CPUs (that is, hyperthreaded or “multicore” CPUs
count at 2) is returned by the value KeNumberProcessors, as in:

if (KeNumberProcessors > 2) {
DbgPrint(“Gee, more than two.\n”);
}

In terms of physical versus logical processors, I’d suggest checking the
processor type information (from the registry) or (if you’re desparate,
and knowing that this is not really supported) checking the CPU ID register.

Peter
OSR

Just curious: why do you *care* whether the multiple CPUs are physical
or logical? I shudder to think…

Ronen Ochman wrote:

Hi All,

How can I get number of CPUs on machine from kernel mode?
If Hyperthreading is enabled, how can I get the number of “physical” CPUs?

Thanks,
Ronen.


…/ray..

Please remove “.spamblock” from my email address if you need to contact
me outside the newsgroup.

> From: Ray Trent [mailto:xxxxx@synaptics.spamblock.com]

Just curious: why do you *care* whether the multiple CPUs are
physical
or logical? I shudder to think…

Software licensing is usually done per physical CPU.

Having logical and physical CPUs creates a “NUMA” system
with regards to L2 caches, so there are performance reasons to know the
mapping
between logical and physical CPUs.

In user mode one can use GetLogicalProcessorInformation().

In kernel mode one can use the modified Intel’s code:
http://www.intel.com/cd/ids/developer/asmo-na/eng/microprocessors/ia32/pentiu
m4/hyperthreading/20438.htm
or make an user mode app pass this info to your driver.

Dmitriy Budko, VMware

Ronen Ochman wrote:

> Hi All,
>
> How can I get number of CPUs on machine from kernel mode?
> If Hyperthreading is enabled, how can I get the number of
“physical” CPUs?
>
> Thanks,
> Ronen.
>


…/ray..

Please remove “.spamblock” from my email address if you need
to contact
me outside the newsgroup.

>

In user mode one can use GetLogicalProcessorInformation().

Present is Server 03 and later only, though, right?

Peter
OSR

> > In user mode one can use GetLogicalProcessorInformation().

>

Present is Server 03 and later only, though, right?

Peter
OSR

Yes, it is one of the reasons why we don’t use it.

Also it’s semi-broken on AMD64 Windows beta for Win32 apps:
If the buffer is too small it will NOT update the ReturnLength arg with
the buffer length required to contain all of the data. A thunking bug?

Dmitriy Budko, VMware