ASM CPUID Processor Speed

Programming, for all ages and all languages.
Post Reply
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

ASM CPUID Processor Speed

Post by Bobalandi »

Is there I way to use CPUID to get the processor speed (frequency).?
I've used the following code to get the vendor name. If it's not possible with CPUID, please give me and idea what to use. Thanks.

Code: Select all

      xor   EAX,EAX
      cpuid
      mov   DWORD [VendorSign],     EBX
      mov   DWORD [VendorSign+4],   EDX
      mov   DWORD [VendorSign+8], ECX
      mov   BYTE  [VendorSign+12],0x00
ps. I'm using nasm by the way if it's important.
NULL
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Post by Hangin10 »

The Intel manuals have an entire page on this. Try the listing for the CPUID instruction, if I remember correctly it has a nice chart on how to calculate processor clock speed from the processor name (something like "Intel Pentium(R)4 3.06GHz").
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post by xyzzy »

I've done that in my OS, however, IIRC support for it was only introduced in the Pentium 4. So, on earlier processors you have to get the info a different way (I think through ACPI or something...)
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Post by Bobalandi »

So, I'm looking at the intel documentation for this (here) but I'm not sure which value to put into EAX, would I put in 0H or 1H, or neither.?
NULL
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Just use the performance counter and a shedload of xor %eax,%eax operations. 8)

the fact that the xor uses the same register each time means the pipelining that can be done on it is negligible (i.e. the xors can't go into different ALU's in parallel, as it would yield a different result) so you *should* get a half-decent reading of the cycles-per-second.

That's the Real Man's way (have to do it on some other more archaic archs!) 8)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

JamesM wrote:Just use the performance counter and a shedload of xor %eax,%eax operations. 8)

the fact that the xor uses the same register each time means the pipelining that can be done on it is negligible (i.e. the xors can't go into different ALU's in parallel, as it would yield a different result) so you *should* get a half-decent reading of the cycles-per-second.
Actually, they can - recent processors decode xor reg,reg as mov reg, 0, which is not pipeline hostile at all, and with register renaming can fill up all ALUs every cycle.

the proper sequence is more like

Code: Select all

xor ecx, edx
xor edx, ecx
xor ecx, edx
xor edx, ecx
etc
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Post by Bobalandi »

So, I'm supposed to manually do it by causing a bunch of cycles and evaluating the time.?
NULL
Post Reply