Implementing KeGetCurrentProcessorNumberEx using cpuid instruction...

Hello,

I see that KeGetCurrentProcessorNumberEx(NULL) returns KPRCB->Number field. So operating system has already setup the KPRCB and KeGetCurrentProcessorNumberEx is just an accessor to fetch KPRCB->Number.

Is it possible to implement the same function using cpuid instruction? I read cpuid documentation at various places, however, it’s still unclear to me as to how to arrive at current logical CPU using the cpuid instruction. Any suggestions?

Thanks.
-Prasad

CPUID on x86 and x86-64 reports the current core capabilities, it has nothing to do with a core number perceived by Windows kernel. Nothing prevents you from developing your own algorithm for cores identification but you should not expect that these numbers will be the same as reported by KeGetCurrentProcessorNumberEx unless you disassemble the current Windows kernel/HAL.

I would advise you to search Linux kernel for cpu_core_id if you want to know how real world kernel infer CPU core numbers for x86/amd64 architecture.

What bigger problem are you trying to solve?

On Tue, Aug 16, 2016 at 2:01 AM -0700, “xxxxx@icloud.com” > wrote:

Hello,

I see that KeGetCurrentProcessorNumberEx(NULL) returns KPRCB->Number field. So operating system has already setup the KPRCB and KeGetCurrentProcessorNumberEx is just an accessor to fetch KPRCB->Number.

Is it possible to implement the same function using cpuid instruction? I read cpuid documentation at various places, however, it’s still unclear to me as to how to arrive at current logical CPU using the cpuid instruction. Any suggestions?

Thanks.
-Prasad


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

@prasad I think you can use local apicid as a hint. It can be queried with
cpuid as well. I am curious though :slight_smile:

On Tue, Aug 16, 2016 at 5:14 PM, wrote:

> CPUID on x86 and x86-64 reports the current core capabilities, it has
> nothing to do with a core number perceived by Windows kernel. Nothing
> prevents you from developing your own algorithm for cores identification
> but you should not expect that these numbers will be the same as reported
> by KeGetCurrentProcessorNumberEx unless you disassemble the current Windows
> kernel/HAL.
>
> I would advise you to search Linux kernel for cpu_core_id if you want to
> know how real world kernel infer CPU core numbers for x86/amd64
> architecture.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:> showlists.cfm?list=ntdev>
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

Thanks Slava for the suggestion.

Doron, I have a piece of a self contained library code (no external Windows kernel or any references). This code needs to to maintain a data structure on a per logical CPU basis. On the public interface of this code, I can pass the CPU number that is returned by KeGetCurrentProcesssNumberEx function. However, I was looking for something that is implicitly available. Hence my question.

Thanks.
-Prasad

Amritanshu, I guess you are referring to the one to returned in EBX register (24-31 bits). That value doesn’t match. It returns me 2 on logical processor 1. In one of the reference I saw that it needs to masked with a value returned in 4 bits in another call to arrive at logical CPU ID. However, I am not sure about it and as Slava mentioned, it’s probably just an OS representation.

Thanks.
-Prasad

If you don’t want to pass it in, have your portable library call MyPlatformProcNum() and then have each platform supply an implementation that calls the supported API and not assume an implementation detail

Get Outlook for Androidhttps:

On Tue, Aug 16, 2016 at 7:01 AM -0700, “xxxxx@icloud.com” > wrote:

Thanks Slava for the suggestion.

Doron, I have a piece of a self contained library code (no external Windows kernel or any references). This code needs to to maintain a data structure on a per logical CPU basis. On the public interface of this code, I can pass the CPU number that is returned by KeGetCurrentProcesssNumberEx function. However, I was looking for something that is implicitly available. Hence my question.

Thanks.
-Prasad


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></https:>