Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using RDTSC - when is the timestamp register incrimented?

Status
Not open for further replies.

skorman00

Programmer
Jan 20, 2006
3
0
0
US
I'm trying to write some code that will keep track of how many ticks my proc has gone through from a given point in time. This is the most useful documentation I've been able to find on the RDTSC op:

After reading this, I still have some questions

1) if my proc is waiting for memory or HDD access, the timestamp counter will still be incrimented, correct? I would expect it to be

2) That above url says that RDTSC is not serialized. Because of this, would RDMSR 10h be a better choice?
 
rewording of question 2) would it be better to use RDMSR with 10h in the ecx register?
 
What happens if you set ecx to 10h? I don't see any reference to 10h at that URL or in the Intel IA-32 manual.
 
> 1) if my proc is waiting for memory or HDD access, the timestamp counter will still be incrimented, correct?
Seems about right to me.

> RDTSC is not serialized.
Does the lack of serialisation matter to you?
All it means is your count is going to be off (at most) by the time it takes to execute a few instructions. Most instructions take a variable number of ticks to execute anyway (even RDTSC is listed as 6-7 ticks), so even your measurement overhead isn't constant.

Also read "2.6.2 Serializing Operations" of this, but this in itself will also affect the overall timings.

> Because of this, would RDMSR 10h be a better choice?
RDTSC is usually readable by all, unless disabled, whereas RDMSR is listed as a ring-0 instruction only.
It also takes longer, and is more variable (20-24 ticks).

--
 
@cpjust RDMSR uses the value in ecx to determine what to look at.


@Salem
much obliged for the input. The doc I read made it sound like RDTSC is quite unreliable (at least that's what I got from it).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top