Are there any ways (peferably in integer arithmetics):
0) what is the possible maximum resloution of TSC?
1) to determine the ratio of TSC (if supported) to PIT ticks (at any possible HZ rates, for instance 100 ticks per second)?
2) to detecet the CPU speed by, so to say, "direct probing"?
And also how to account for the CPU's with power determined internal clock speeed (or just volatile) (for instance my notebook CPU speeed is degraded when the battery is low)?
Can the follownig code be used for the item #1 of the list above?
Code: Select all
%define FREQ ( 1000 / 50 )
%define CLATCH ( ( 1193180 + FREQ / 2 ) / FREQ ) ;; initializet to the PIT channel 0 for calibration
%define ITICKS ( 40 )
%define SCALE ( ( 1000000 / FREQ ) * ITICKS )
...
calibrate_RDTSC:
;; So our CPU is either 486 with CPUID (newer 486)
;; or 586+ with definite CUPID support (Pentiums and higher)
;; anyway check if RDTSC is supported
mov eax, 0x00000001
cpuid
test dl, 000010000b ;; test TSC bit(4)
jnz calibrate_RDTSC_present
jmp calibrate_RDTSC_END
calibrate_RDTSC_present:
;; wait for a new PIT tick
mov ebx, dword [gs:GS_timestamp]
@RDTSC1:
cmp ebx, dword [gs:GS_timestamp]
je @RDTSC1
:: START
rdtsc
mov dword [ebp + calibrate_RDTSC_low], eax
mov dword [ebp + calibrate_RDTSC_high], edx
;; TICKS interval
add ebx, ( ITICKS + 1 )
@RDTSC2:
cmp ebx, dword [gs:GS_timestamp]
jne @RDTSC2
:: END
rdtsc
sub eax, dword [ebp + calibrate_RDTSC_low]
sbb edx, dword [ebp + calibrate_RDTSC_high]
mov ebx, SCALE
div ebx
mov dword [gs:GS_TSC_COUNT], eax
calibrate_RDTSC_END:
...