]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/x86/lib/delay_32.c
2 * Precise Delay Loops for i386
4 * Copyright (C) 1993 Linus Torvalds
5 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
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.
13 #include <linux/module.h>
14 #include <linux/sched.h>
15 #include <linux/preempt.h>
16 #include <linux/delay.h>
18 #include <asm/processor.h>
19 #include <asm/delay.h>
20 #include <asm/timer.h>
26 /* simple loop based delay: */
27 static void delay_loop(unsigned long loops
)
36 "2:\tdecl %0\n\tjns 2b"
41 /* TSC based delay: */
42 static void delay_tsc(unsigned long loops
)
44 unsigned long bclock
, now
;
46 preempt_disable(); /* TSC's are per-cpu */
51 } while ((now
-bclock
) < loops
);
56 * Since we calibrate only once at boot, this
57 * function should be set once at boot and not changed
59 static void (*delay_fn
)(unsigned long) = delay_loop
;
61 void use_tsc_delay(void)
66 int read_current_timer(unsigned long *timer_val
)
68 if (delay_fn
== delay_tsc
) {
75 void __delay(unsigned long loops
)
80 inline void __const_udelay(unsigned long xloops
)
86 :"=d" (xloops
), "=&a" (d0
)
88 (cpu_data(raw_smp_processor_id()).loops_per_jiffy
* (HZ
/4)));
93 void __udelay(unsigned long usecs
)
95 __const_udelay(usecs
* 0x000010c7); /* 2**32 / 1000000 (rounded up) */
98 void __ndelay(unsigned long nsecs
)
100 __const_udelay(nsecs
* 0x00005); /* 2**32 / 1000000000 (rounded up) */
103 EXPORT_SYMBOL(__delay
);
104 EXPORT_SYMBOL(__const_udelay
);
105 EXPORT_SYMBOL(__udelay
);
106 EXPORT_SYMBOL(__ndelay
);