Re: GetCurrentProcessorNumber() for XP?



You would set the affinity for each processor in sequence to build a mapping
of apic id to cpu number.

Then, later, when you execute cpuid on a thread with multiprocessor
affinity, you can map the returned id to say processor 0, processor 1, etc.

"Alexander Grigoriev" <alegr@xxxxxxxxxxxxx> wrote in message
news:el$Cz71dGHA.1320@xxxxxxxxxxxxxxxxxxxxxxx
Well, if you set the affinity, you know on what process you'll be running
and then there's no point whatsoever to query the processor number!

On the other hand, I think the problem being discussed (custom CPU meter
of an multimedia app) is not worth bothering. That's one of bells and
whistles without real return on investment, other than bragging rights of
the programmer.

"Skywing" <skywing_NO_SPAM_@xxxxxxxxxxxxxxxxxxx> wrote in message
news:O5suzsvdGHA.1204@xxxxxxxxxxxxxxxxxxxxxxx
The former can be easily solved by taking the process affinity mask and
then in sequence setting a thread to be assigned to only one processor,
executing the appropriate cpuid instruction, then changing the affinity
to the next processor.

"Steve Dispensa" <dispensa@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:C08BBADB.AC51%dispensa@xxxxxxxxxxxxxxxxxxxxxxx
On 5/12/06 12:34 PM, in article
D203BD13-2430-4A4B-9321-D0E8076B1A71@xxxxxxxxxxxxx, "Ron Kuper"
<RonKuper@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Thanks for the help, everyone. I figured out a way to do it.

The CPUID instruction, called with EAX=1, returns the APIC ID in the
upper 8
bits of EBX. This isn't the processor number, but it is unique for
each
logical CPU. I simply take that number and use a tiny map (implemented
as
256 byte array) to map APIC ID -> processor number, i.e., if I don't
see an
APIC ID in the map I increment a processor number counter and assign it
to
the APIC ID. Does the trick, all in user mode, and quite efficient.

I'm sure you understand this already, but just for the record, the
results
of your CPUID call can be wrong by the very next CPU instruction. There
is
nothing stopping the OS from context switching away and scheduling you
elsewhere next time you come up for cycles. This will probably be right
a
lot of the time, but it will be wrong some of the time.

Also, this is obviously not terribly portable or easy to maintain (no
inline
ASM on x64, etc).

Otherwise, interesting solution.

-Steve







.



Relevant Pages

  • Re: [Lse-tech] [PATCH] cpusets - big numa cpu and memory placement
    ... > replacement/modification to the CPU affinity mechanism basically adding ... > affinity mask). ... Then when you want to do something like take a CPU away ...
    (Linux-Kernel)
  • Re: 2.6.28 boot fails on Cyrix 6x86
    ... Enabling CPUID on Cyrix processor. ... 45680k/49152k available (1557k kernel code, 3084k reserved, ... CPU: Cyrix 6x86 2x Core/Bus Clock stepping 05 ...
    (Linux-Kernel)
  • 2.6.28 boot fails on Cyrix 6x86
    ... UMC UMC UMC UMC ... Enabling CPUID on Cyrix processor. ... CPU: Cyrix 6x86 2x Core/Bus Clock stepping 05 ...
    (Linux-Kernel)
  • Re: 2.6.28 boot fails on Cyrix 6x86
    ... UMC UMC UMC UMC ... Enabling CPUID on Cyrix processor. ... CPU: Cyrix 6x86 2x Core/Bus Clock stepping 05 ...
    (Linux-Kernel)
  • Re: Hyper Threading Issues
    ... Open Task Manager by pressing Control+Alt+Delete then right click on the ... process, then set affinity. ... Now check which CPU you want it to use;) ... >>>>I flash bios with latest version, Enabled Ht from Bios, ...
    (microsoft.public.windowsxp.hardware)