delay.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  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. #include <linux/config.h>
  14. #include <linux/sched.h>
  15. #include <linux/delay.h>
  16. #ifdef CONFIG_SMP
  17. #include <asm/smp.h>
  18. #endif
  19. void __delay(unsigned long loops)
  20. {
  21. /*
  22. * To end the bloody studid and useless discussion about the
  23. * BogoMips number I took the liberty to define the __delay
  24. * function in a way that that resulting BogoMips number will
  25. * yield the megahertz number of the cpu. The important function
  26. * is udelay and that is done using the tod clock. -- martin.
  27. */
  28. __asm__ __volatile__(
  29. "0: brct %0,0b"
  30. : /* no outputs */ : "r" ((loops/2) + 1));
  31. }
  32. /*
  33. * Waits for 'usecs' microseconds using the tod clock, giving up the time slice
  34. * of the virtual PU inbetween to avoid congestion.
  35. */
  36. void __udelay(unsigned long usecs)
  37. {
  38. uint64_t start_cc, end_cc;
  39. if (usecs == 0)
  40. return;
  41. asm volatile ("STCK %0" : "=m" (start_cc));
  42. do {
  43. cpu_relax();
  44. asm volatile ("STCK %0" : "=m" (end_cc));
  45. } while (((end_cc - start_cc)/4096) < usecs);
  46. }