※ 引述《[email protected] (~ 沒有永遠的永說n之銘言:
> 已經測試過底下的程式可以在 FreeBSD 上取得 physical memory
用 rdtsc 指令測量.
以下是本人的白爛流 program:
#include <unistd.h>
#include <stdio.h>
#include <inttypes.h>
int main()
{
double f;
uint64_t t1,t2;
uint64_t a1,d1,a2,d2;
long k;
asm("rdtsc");
asm("movl %0,%%eax":"=r"(a1));
asm("movl %0,%%edx":"=r"(d1));
sleep(1);
asm("rdtsc");
asm("movl %0,%%eax":"=r"(a2));
asm("movl %0,%%edx":"=r"(d2));
t2=((uint64_t)d2<<32)+a2;
t1=((uint64_t)d1<<32)+a1;
k=(t2-t1);
f=(double)k/1000000.0;
printf("CPU Clock:%.2fMHz\n",f);
return 0;
}
--
# Origin # 高應科大 楓城 bbs.kuas.edu.tw
# Author # 218-164-53-189.hinet-ip.hinet.net