Google Gruppi non supporta più i nuovi post o le nuove iscrizioni Usenet. I contenuti storici continuano a essere visibili.

How to read the processor number?

5 visualizzazioni
Passa al primo messaggio da leggere

JF Larvoire

da leggere,
4 feb 2003, 11:00:4604/02/03
a
Hello,

I need to read the current processor number in a WIN32 program.
How can this be done?
Better still, is there a way to do it WITHOUT having to write an ad-hoc
device driver?
Thanks for any clue,

Jean-François

PS. The reason I need to know this number is because I'm reading the CPU
Time Stamp Counter register for measuring very short durations.
On my system (a bi-processor) it happens that both processors have almost
the same counts at the same time. But I'm not sure it's guarantied to be the
case in general.


Brad Staff

da leggere,
4 feb 2003, 17:23:4304/02/03
a
"JF Larvoire" <jean-francois.larvoire@remove_this.free.fr> wrote in message
news:3e3fe4fb$0$235$626a...@news.free.fr...

You can force your process to run on a particular processor using the Win32
API SetProcessAffinityMask().

Regards,

Brad


Maxim S. Shatskih

da leggere,
5 feb 2003, 13:09:1005/02/03
a
> PS. The reason I need to know this number is because I'm reading the
CPU
> Time Stamp Counter register for measuring very short durations.
> On my system (a bi-processor) it happens that both processors have
almost
> the same counts at the same time. But I'm not sure it's guarantied
to be the
> case in general.

This is not guaranteed, use the affinity mask to bind the thread to a
particular CPU to guarantee this.

Max


JF Larvoire

da leggere,
6 feb 2003, 05:17:1906/02/03
a
I know about SetProcessAffinityMask().
The problem is that there's no corresponding GetProcessAffinityMask()
But even if there were, what I actually need is a GetCurrentProcessor()!

JF

Leo Havmøller

da leggere,
6 feb 2003, 06:42:5906/02/03
a
"JF Larvoire" <jean-francois.larvoire@remove_this.free.fr> wrote in message
news:3e42377d$0$240$626a...@news.free.fr...

> I know about SetProcessAffinityMask().
> The problem is that there's no corresponding GetProcessAffinityMask()

Yes there is!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/getprocessaffinitymask.asp

> But even if there were, what I actually need is a GetCurrentProcessor()!

There is not GetCurrentProcessor, because that is not relevant for user-mode
apps. They cannot run at elevated IRQL.

Leo Havmøller.


EMP

da leggere,
6 feb 2003, 10:09:3706/02/03
a
"JF Larvoire" <jean-francois.larvoire@remove_this.free.fr> wrote in message news:<3e3fe4fb$0$235$626a...@news.free.fr>...

If you're running on a Pentium4 you can do CPUID (with eax = 1) and look at
the Local APIC ID in bits 31:24 of returned ebx. That will be unique for each
processor.
Don't know how to do it from user-mode on P5/P6 type processors.

Enio.

Brad Staff

da leggere,
6 feb 2003, 12:00:4006/02/03
a
> I know about SetProcessAffinityMask().
> The problem is that there's no corresponding GetProcessAffinityMask()

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/getprocessaffinitymask.asp

> But even if there were, what I actually need is a GetCurrentProcessor()!

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/multiple_processors.asp?frame=true.

The section on Thread Scheduling in "Inside Microsoft Windows 2000" (Solomon
and Russinovich) provides additional information.

Regards,

Brad


Don Burn

da leggere,
6 feb 2003, 20:07:5706/02/03
a

"JF Larvoire" <jean-francois.larvoire@remove_this.free.fr> wrote in message
news:3e3fe4fb$0$235$626a...@news.free.fr...
The OS takes care of making them very close since it is used for some
internal
calls and tracking. As long as you can handle a few counts difference don't
worry about the cpu.

Don Burn
Egenera, Inc

EMP

da leggere,
7 feb 2003, 22:17:0007/02/03
a
new...@yahoo.com (EMP) wrote in message news:<2bb86d68.03020...@posting.google.com>...

>
> If you're running on a Pentium4 you can do CPUID (with eax = 1) and look at
> the Local APIC ID in bits 31:24 of returned ebx. That will be unique for each
> processor.
> Don't know how to do it from user-mode on P5/P6 type processors.
>
Never mind! What I said about CPUID is OK but there's no guarantee
that the CPUID and the RDTSC will be executed on the same processor.
The thread can be time-sliced out between instructions or an interrupt
can occur and the thread can be re-dispatched on another processor.
0 nuovi messaggi