True, but my argument would be that the code being executed between the two readings doesn't actually matter.
The rdtsc counter ticks at a constant rate no matter what is happening (Aside from clock speed alterations due to power saving, but I'll ignore that for the time being). So if I take one rdtsc reading at T[sub]0[/sub] and another at T[sub]1[/sub] then so long as I disable interrupts for the short period the readings actually take place I'll come up with a reasonable result so long as T[sub]1[/sub] - T[sub]0[/sub] is suitably large.
IE
Code: Select all
Do some boring setup stuff
...
Stop interrupts
Read/store CMOS clock and rdtsc values
Start interrupts
...
Do whatever needs to be done for installation
...
Stop interrupts
Read/store CMOS clock and rdtsc values
Start interrupts
...
Calculate and store permanent setting for clock frequency
What I'm suggesting is that since installation is going to take a while anyway it can be used to provide a large enough difference in CMOS time to get half-decent accuracy, which can be improved by rounding up/down to the nearest existing clock frequency.
In my example I suggested installation might take 5 minutes.
With a 1 second resolution on the clock, the max error for T[sub]1[/sub] - T[sub]0[/sub] is going to be +/- 2 seconds.
Error calculation has never been a particular strong suit of mine, but if I take an example of a 500Mhz processor over a 5 minute installation we get something like:
Delta(rdtsc) = (500,000,000 * 300) -> Assume negligible error
Delta(CMOS time) = 300 +/- 2
Delta(rdtsc)/Delta(CMOS time) = Frequency
Roll the dice and we get a freqency of 500Mhz +/- 4Mhz which is well within the error limit I defined.
In fact it would hold within my desired errors even beyond 2Ghz, at which point I'd be rounding to the nearest 100Mhz anyway.
I'd agree that this is a pretty crude way of getting the clock frequency, but since the opportunity is there at installation time, and people don't change processor very often, I just don't see why it should be done at boot time.
Nobody, IMHO, changes hardware so often that they require constant boot-time detection. I'm quite confident that I can get away with a policy of one-time detection, whilst relying on the user/administrator to perform redection as required.