I'm trying to measure CPU frequency using AT&T assembler. My algorithm is:
t0 = rdtsc
sleep(1)
t1 = rdtsc
f = t1-t0 [Hz]
(And I cannot do it using rdmsr
as I'm not in ring 0)
Code:
.data
t0: .long 0
t1: .long 0
.text
.globl main
.type main, @function
main:
rdtsc
movl %eax, t0
mov $1, %eax
push %eax
call sleep
rdtsc
sub %eax, t0
#printeax
movl $1, %eax
movl $0, %ebx
int $0x80
.size main, . - main
I wonder if this algorithm is a correct one. If so, what am I doing wrong because my results confuse me: they can vary e.g. from 4121650118
to 86456722
Hz.
lscpu | grep MHz
returns:
CPU max MHz: 2300,0000
CPU min MHz: 800,0000
I'm also interested, if it is possible to get CPU frequency with AT&T the other way, like, using some syscall or something.
Comments
Post a Comment