Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
948 trimarchi 1
#include "kernel/kern.h"
2
#include "calibrate.h"
3
 
4
int cal_cycles=0;
5
 
6
/* Runtime Calibration */
7
int calibrate_cycle()
8
{
9
  long long i;
10
  struct timespec start,end,diff;
11
 
12
  if (cal_cycles != 0) return 0;
13
 
14
 
15
 
16
  kern_cli();
17
  __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
18
                          "cpuid\n\t"
19
                          :::"eax","ebx","ecx","edx");
20
  kern_gettime(&start);
21
  for (i=0;i<CALIBRATION_DELTA;i++)
22
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
23
                          "cpuid\n\t"
24
                          :::"eax","ebx","ecx","edx");
25
  __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
26
                          "cpuid\n\t"
27
                          :::"eax","ebx","ecx","edx");
28
  kern_gettime(&end);
29
  kern_sti();
30
 
31
  SUBTIMESPEC(&end,&start,&diff);
32
  cal_cycles = TIMESPEC2USEC(&diff);
33
 
34
  cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);
35
 
36
  return 0;
37
 
38
}
39
 
40
void eat(TIME wait) {
41
 
42
    int exec_cycles=0;
43
    int i=0;
44
 
45
    exec_cycles = (long long)(wait) * CALIBRATION_DELTA / cal_cycles;
46
 
47
    /* Execution delay */
48
    for (i=0;i<exec_cycles;i++)
49
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
50
                          "cpuid\n\t"
51
                          :::"eax","ebx","ecx","edx");
52
 
53
}