Here is a simple one that just keeps me confused.
If I want to get the number of cores in a CPU, I can write this
code(which works fine in user mode):
SYSTEM_INFO sysinfo;
GetSystemInfo( &sysinfo );
n_cores = sysinfo.dwNumberOfProcessors;
For some reason, this code does not compile for kernel and seems to want
winbase.h which then messes up the rest of my code.
Any ideas ?
xxxxx@emc.com wrote:
Here is a simple one that just keeps me confused.
If I want to get the number of cores in a CPU, I can write this
code(which works fine in user mode):
SYSTEM_INFO sysinfo;
GetSystemInfo( &sysinfo );
n_cores = sysinfo.dwNumberOfProcessors;
For some reason, this code does not compile for kernel and seems to
want winbase.h which then messes up the rest of my code.
Of course. That’s a user-mode API. User mode and kernel mode have
entirely different APIs. However, 60 seconds with Google should have
brought you to the answer
The kernel exports a variable called KeNumberProcessors that provides
this value, although it’s no longer a “blessed” solution in Windows
Server 2008 and beyond, because processors can come and go.
KeQueryActiveProcessors returns a bitmask showing which processors are
active.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
And KeQueryActiveProcessorCount returns a count so you don’t have to
count the bits yourself.
Mark Roddy
On Mon, Nov 8, 2010 at 3:09 PM, Tim Roberts wrote:
> xxxxx@emc.com wrote:
>>
>> Here is a simple one that just keeps me confused.
>>
>> If I want to get the number of cores in a CPU, I can write this
>> code(which works fine in user mode):
>>
>>
>>
>> SYSTEM_INFO sysinfo;
>>
>> GetSystemInfo( &sysinfo );
>>
>> n_cores = sysinfo.dwNumberOfProcessors;
>>
>>
>>
>> For some reason, this code does not compile for kernel and seems to
>> want winbase.h which then messes up the rest of my code.
>>
>
> Of course. ?That’s a user-mode API. ?User mode and kernel mode have
> entirely different APIs. ?However, 60 seconds with Google should have
> brought you to the answer
>
> The kernel exports a variable called KeNumberProcessors that provides
> this value, although it’s no longer a “blessed” solution in Windows
> Server 2008 and beyond, because processors can come and go.
> KeQueryActiveProcessors returns a bitmask showing which processors are
> active.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>