OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Aug 04, 2020 11:17 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: RDTSC on Corei5
PostPosted: Thu Dec 29, 2011 9:31 am 
Offline

Joined: Thu Nov 24, 2011 8:54 am
Posts: 13
2 quick questions regarding RDTSC :)

a) Does RDTSC return the number of CPU clock-ticks since boot?

b) If so -
On my Core i5 (520M), I have tried to use RDTSC to calculate the CPU speed.
I read the TSC, wait for 100ms, read again and take the difference.
For some reason, it is telling me the difference is ~2.1 billion ticks.

I know the timing loop is correct as I also use it to calculate the FSB (which is coming back as 1066Mhz).

I was about to multiply the TSC diff by 10 (to get seconds) when I noticed it was already huge :). I have checked the start and end TSC readings, and manually calculated the difference = 2 billion.

Am I getting 10 ticks per clock cycle or is something else weird going on?


Top
 Profile  
 
 Post subject: Re: RDTSC on Corei5
PostPosted: Thu Dec 29, 2011 9:50 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
sentientnz wrote:
Does RDTSC return the number of CPU clock-ticks since boot?


No, the number may not related to ticks upon boot, btw it may be paused for inactive processors, or accordingly the the manual:
Quote:
The processor monotonically increments the time-stamp counter MSR every clock cycle and resets it to 0 whenever the processor is reset.


sentientnz wrote:
Am I getting 10 ticks per clock cycle or is something else weird going on?

There is always rounding errors and interrupts/SMM/hidden tasks. The only way to increase accuracy is enlarge sample.


Top
 Profile  
 
 Post subject: Re: RDTSC on Corei5
PostPosted: Thu Dec 29, 2011 12:50 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

sentientnz wrote:
a) Does RDTSC return the number of CPU clock-ticks since boot?


For Core i5, TSC should measure "nominal clock ticks" since the CPU was started last (e.g. including reset, etc); as long as nobody messed with the MSR to change the TSC.

Note that for Core i5, "nominal clock ticks" has nothing to do with the speed that the CPU is actually running at, and may not have anything to do with any speed the CPU could ever run at. I'm not too sure exactly what the TSC in Core i5 measures - I'd guess the maximum turbo-boost speed (e.g. 2.933 GHz for a Core i5 520M), but that's only a guess, and it could just multiply the bus speed by an arbitrary "large enough" number (like 18).

sentientnz wrote:
On my Core i5 (520M), I have tried to use RDTSC to calculate the CPU speed.


You can't estimate CPU speed using RDTSC on any recent CPU (you can only determine what speed the TSC runs at).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group