blob: 027c4742a0017a2cdef12b51a4dd282709dc59b9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/delay.c
3 * Precise Delay Loops for S390
4 *
5 * S390 version
6 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 *
9 * Derived from "arch/i386/lib/delay.c"
10 * Copyright (C) 1993 Linus Torvalds
11 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sched.h>
15#include <linux/delay.h>
16
17#ifdef CONFIG_SMP
18#include <asm/smp.h>
19#endif
20
21void __delay(unsigned long loops)
22{
23 /*
24 * To end the bloody studid and useless discussion about the
25 * BogoMips number I took the liberty to define the __delay
26 * function in a way that that resulting BogoMips number will
27 * yield the megahertz number of the cpu. The important function
28 * is udelay and that is done using the tod clock. -- martin.
29 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020030 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
32
33/*
34 * Waits for 'usecs' microseconds using the tod clock, giving up the time slice
35 * of the virtual PU inbetween to avoid congestion.
36 */
37void __udelay(unsigned long usecs)
38{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020039 uint64_t start_cc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 if (usecs == 0)
42 return;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020043 start_cc = get_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 do {
45 cpu_relax();
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020046 } while (((get_clock() - start_cc)/4096) < usecs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}