/root/src/xen/xen/arch/x86/delay.c
Line | Count | Source |
1 | | /* |
2 | | * Precise Delay Loops for i386 |
3 | | * |
4 | | * Copyright (C) 1993 Linus Torvalds |
5 | | * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
6 | | * |
7 | | * The __delay function must _NOT_ be inlined as its execution time |
8 | | * depends wildly on alignment on many x86 processors. The additional |
9 | | * jump magic is needed to get the timing stable on all the CPU's |
10 | | * we have to worry about. |
11 | | */ |
12 | | |
13 | | #include <xen/delay.h> |
14 | | #include <xen/time.h> |
15 | | #include <asm/msr.h> |
16 | | #include <asm/processor.h> |
17 | | |
18 | | void __udelay(unsigned long usecs) |
19 | 3.11k | { |
20 | 3.11k | unsigned long ticks = usecs * (cpu_khz / 1000); |
21 | 3.11k | unsigned long s, e; |
22 | 3.11k | |
23 | 3.11k | s = rdtsc_ordered(); |
24 | 3.11k | do |
25 | 180M | { |
26 | 180M | rep_nop(); |
27 | 180M | e = rdtsc_ordered(); |
28 | 180M | } while ((e-s) < ticks); |
29 | 3.11k | } |