Question about Calculating Processor Frequency

Question about Calculating Processor Frequency

Hi,

I am currently making a timer for a project I am working on based on RDTSC and I need to calculate the CPU's frequancy to determain how much time has elapsed. I have read the CPUID doc that show you how to calculate the CPU's freqency but I can get this to work for me so my question is it possible to get this method to work on Windows since we dont have access to Ring 0. I have been told it is possible using the 8254 timer 2 but I dont know how to implment this into inline assembly. Can someone please give me some information on how to implement this or point me to a doc that provides more information on this.

Please note I am just starting on learning assembly but I do understand the logic behind the algorithm that was shown in the CPUID doc I just dont know how to impment it using Windows (I tried to impment it using inline assembly but I couldnt get it to compile in the form shown in the CPUID doc for some reason and I get access violations when i did get it to compile). Any help will be appricatied.

Thanks in advance

PS: Here is the doc I am refering to - ftp://download.intel.com/design/Xeon/applnots/24161823.pdf

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello,

Did you see that Intel provides CPUID software, at http://www.intel.com/support/processors/tools/frequencyid/index.htm?

Hope that helps.

-Paul

Hi, thanks for the link but I actualy need some help with the code to detect the CPU's frequancy using the PIT timer and RDTSC, I know the logic on how to do it but I dont know how to implment accessing the pit timer in Windows using C++ inline assembly. Basicly I am trying to make a high resolution timer class using RDTSC but I would first have to know the CPU's frequancy.

Does anyone have any info that can help me in this regard?

Thanks

A common method for calibrating clock speed is to run a loop for a few seconds, and compare the time in the date/time API call against the difference in RDTSC counter. You should be able to find an API which returns clock speed.

How accurate is the clock that is calculated using these date/time api's. I am trying to get a as acurate as possible clock frequancy calculation to insure that the times produced using the RDTSC method are accurate.

I currently have a method using sleeps and RDTSC that seemed to work but then when I used it on Pentium 4's I would get inaccurate results (but close). Any ideas how to improve on this?

I believe the largest sources of error are
1. the resolution of the date clock (1 ms)
2. variation in CPU clock rate (could be large with thermal throttling)

1. is the reason for calibrating over several seconds.

Leave a Comment

Please sign in to add a comment. Not a member? Join today