Re: GetCurrentProcessorNumber() for XP?



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: Linux compatible setaffinity.
    ... int cpuaffinity; ... Get or set affinity and fetch from or store into mask. ... If pid is specified on set all threads in the pid are set to the requested affinity. ... I can implement them in 4BSD but it will be very inefficient in some edge cases since each cpu doesn't have its own run queue. ...
    (freebsd-arch)
  • Re: [RFC] Correct behaviour of irq affinity?
    ... and both 32 and 64-bit did that anding whenever a cpu was unplugged. ... anding the affinity with cfg->domain. ... for phys flat will be one cpu set mask. ... for_each_cpu_and(cpu, cpumask, andmask) ...
    (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)
  • Re: 2.6.11-mm2
    ... Can cpu affinity really be changed for a running process? ... It works fine to bound a new process to a cpu set, ... pid 8277's current affinity list: ...
    (Linux-Kernel)