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.
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").
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...)
Just use the performance counter and a shedload of xor %eax,%eax operations.
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!)
JamesM wrote:Just use the performance counter and a shedload of xor %eax,%eax operations.
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.
"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 ]