jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
2.9KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Code derived from various headers from the Linux kernel
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. $Id$
  16. */
  17. #ifndef __jack_cycles_h__
  18. #define __jack_cycles_h__
  19. #if defined(__i386__) || defined(__x86_64__)
  20. /*
  21. * Standard way to access the cycle counter on i586+ CPUs.
  22. * Currently only used on SMP.
  23. *
  24. * If you really have a SMP machine with i486 chips or older,
  25. * compile for that, and this will just always return zero.
  26. * That's ok, it just means that the nicer scheduling heuristics
  27. * won't work for you.
  28. *
  29. * We only use the low 32 bits, and we'd simply better make sure
  30. * that we reschedule before that wraps. Scheduling at least every
  31. * four billion cycles just basically sounds like a good idea,
  32. * regardless of how fast the machine is.
  33. */
  34. typedef unsigned long long cycles_t;
  35. extern cycles_t cacheflush_time;
  36. #define rdtscll(val) \
  37. __asm__ __volatile__("rdtsc" : "=A" (val))
  38. static inline cycles_t get_cycles (void)
  39. {
  40. unsigned long long ret;
  41. rdtscll(ret);
  42. return ret;
  43. }
  44. #elif defined(__powerpc__)
  45. #define CPU_FTR_601 0x00000100
  46. typedef unsigned long cycles_t;
  47. /*
  48. * For the "cycle" counter we use the timebase lower half.
  49. * Currently only used on SMP.
  50. */
  51. extern cycles_t cacheflush_time;
  52. static inline cycles_t get_cycles(void)
  53. {
  54. cycles_t ret = 0;
  55. __asm__ __volatile__(
  56. "98: mftb %0\n"
  57. "99:\n"
  58. ".section __ftr_fixup,\"a\"\n"
  59. " .long %1\n"
  60. " .long 0\n"
  61. " .long 98b\n"
  62. " .long 99b\n"
  63. ".previous"
  64. : "=r" (ret) : "i" (CPU_FTR_601));
  65. return ret;
  66. }
  67. #elif defined(__ia64__)
  68. /* ia64 */
  69. typedef unsigned long cycles_t;
  70. static inline cycles_t
  71. get_cycles (void)
  72. {
  73. cycles_t ret;
  74. __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
  75. return ret;
  76. }
  77. #elif defined(__alpha__)
  78. /* alpha */
  79. typedef unsigned int cycles_t;
  80. static inline cycles_t get_cycles (void)
  81. {
  82. cycles_t ret;
  83. __asm__ __volatile__ ("rpcc %0" : "=r"(ret));
  84. return ret;
  85. }
  86. #else
  87. /* generic solution */
  88. #warning You are compiling JACK on a platform for which jack/cycles.h needs work
  89. #include <sys/time.h>
  90. typedef long cycles_t;
  91. extern cycles_t cacheflush_time;
  92. static inline cycles_t get_cycles(void)
  93. {
  94. struct timeval tv;
  95. gettimeofday (&tv, NULL);
  96. return tv.tv_usec;
  97. }
  98. #endif
  99. #endif /* __jack_cycles_h__ */