How can an application get CPU (only Core 2 Duo) frequency ? I tried the method with __rtdsc but the results are different every time I run the application. Reading frequency from Brand String is not satisfactory for me --I assume that user's CPU can be overclocked. Is there an MSR register or other way for getting current CPU frequency or FSB frequency?
You don't indicate what OS you want to do this under. If the answer is Windows, try using QueryPerformanceFrequency (see http://msdn2.microsoft.com/en-us/library/bb173458.aspx).
On Linux, try looking in /proc/cpuinfo (see http://lwn.net/Articles/162548/).
I am seeing a possibly related problem with performance measurement by rdtsc on Core 2 Duo. When running a short benchmark, starting with an idle machine (CPU speed throttled way back), the number of "clock ticks" reported by rdtsc comes out significantly lower. If anything, the actual elapsed time has to be higher, but I can't measure it accurately. If the test is repeated 5 seconds later, it comes out normal.
When Demand Based Switching was introduced on Pentium D, we were sometimes advised to disable DBS (possibly a BIOS setup option) in order to avoid these anomalous results, by keeping CPU at full speed regardless of load. I wouldn't want to do that on a machine as hot as a full speed Pentiurm D.