Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "kernel/kern.h"
#include "calibrate.h"
int cal_cycles=0;
/* Runtime Calibration */
int calibrate_cycle()
{
long long i;
struct timespec start,end,diff;
if (cal_cycles != 0) return 0;
kern_cli();
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
kern_gettime(&start);
for (i=0;i<CALIBRATION_DELTA;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
kern_gettime(&end);
kern_sti();
SUBTIMESPEC(&end,&start,&diff);
cal_cycles = TIMESPEC2USEC(&diff);
cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);
return 0;
}
void eat(TIME wait) {
int exec_cycles=0;
int i=0;
exec_cycles = (long long)(wait) * CALIBRATION_DELTA / cal_cycles;
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
}