Rev 948 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1063 | tullio | 1 | |
2 | /* |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
16 | * |
||
17 | */ |
||
18 | |||
948 | trimarchi | 19 | #include "kernel/kern.h" |
20 | #include "calibrate.h" |
||
21 | |||
22 | int cal_cycles=0; |
||
23 | |||
24 | /* Runtime Calibration */ |
||
25 | int calibrate_cycle() |
||
26 | { |
||
27 | long long i; |
||
28 | struct timespec start,end,diff; |
||
29 | |||
30 | if (cal_cycles != 0) return 0; |
||
31 | |||
32 | |||
33 | |||
34 | kern_cli(); |
||
35 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
36 | "cpuid\n\t" |
||
37 | :::"eax","ebx","ecx","edx"); |
||
38 | kern_gettime(&start); |
||
39 | for (i=0;i<CALIBRATION_DELTA;i++) |
||
40 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
41 | "cpuid\n\t" |
||
42 | :::"eax","ebx","ecx","edx"); |
||
43 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
44 | "cpuid\n\t" |
||
45 | :::"eax","ebx","ecx","edx"); |
||
46 | kern_gettime(&end); |
||
47 | kern_sti(); |
||
48 | |||
49 | SUBTIMESPEC(&end,&start,&diff); |
||
50 | cal_cycles = TIMESPEC2USEC(&diff); |
||
51 | |||
52 | cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles); |
||
53 | |||
54 | return 0; |
||
55 | |||
56 | } |
||
57 | |||
58 | void eat(TIME wait) { |
||
59 | |||
60 | int exec_cycles=0; |
||
61 | int i=0; |
||
62 | |||
63 | exec_cycles = (long long)(wait) * CALIBRATION_DELTA / cal_cycles; |
||
64 | |||
65 | /* Execution delay */ |
||
66 | for (i=0;i<exec_cycles;i++) |
||
67 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
68 | "cpuid\n\t" |
||
69 | :::"eax","ebx","ecx","edx"); |
||
70 | |||
71 | } |