delay.c 1.4 KB

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