jack2 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.

122 lines
2.7KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  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. */
  16. #include "JackTime.h"
  17. #include "JackError.h"
  18. #ifdef __APPLE__
  19. double __jack_time_ratio;
  20. /* This should only be called ONCE per process. */
  21. void InitTime()
  22. {
  23. JackLog("InitTime\n");
  24. mach_timebase_info_data_t info;
  25. mach_timebase_info(&info);
  26. __jack_time_ratio = ((float)info.numer / info.denom) / 1000;
  27. }
  28. #endif
  29. #ifdef WIN32
  30. EXPORT LARGE_INTEGER _jack_freq;
  31. void InitTime()
  32. {
  33. QueryPerformanceFrequency(&_jack_freq);
  34. JackLog("InitTime freq = %ld %ld\n", _jack_freq.HighPart, _jack_freq.LowPart);
  35. _jack_freq.QuadPart = _jack_freq.QuadPart / 1000000; // by usec
  36. }
  37. jack_time_t GetMicroSeconds(void)
  38. {
  39. LARGE_INTEGER t1;
  40. QueryPerformanceCounter (&t1);
  41. return (jack_time_t)(((double)t1.QuadPart)/((double)_jack_freq.QuadPart));
  42. }
  43. // TODO
  44. #endif
  45. #ifdef linux
  46. #ifdef GETCYCLE_TIME
  47. #include <stdio.h>
  48. jack_time_t GetMhz(void)
  49. {
  50. FILE *f = fopen("/proc/cpuinfo", "r");
  51. if (f == 0)
  52. {
  53. perror("can't open /proc/cpuinfo\n");
  54. exit(1);
  55. }
  56. for ( ; ; )
  57. {
  58. jack_time_t mhz;
  59. int ret;
  60. char buf[1000];
  61. if (fgets(buf, sizeof(buf), f) == NULL) {
  62. jack_error ("FATAL: cannot locate cpu MHz in "
  63. "/proc/cpuinfo\n");
  64. exit(1);
  65. }
  66. #if defined(__powerpc__)
  67. ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
  68. #elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
  69. defined(__x86_64__)
  70. ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz);
  71. #elif defined( __sparc__ )
  72. ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz);
  73. #elif defined( __mc68000__ )
  74. ret = sscanf(buf, "Clocking: %" SCNu64, &mhz);
  75. #elif defined( __s390__ )
  76. ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
  77. #else /* MIPS, ARM, alpha */
  78. ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz);
  79. #endif
  80. if (ret == 1)
  81. {
  82. fclose(f);
  83. return (jack_time_t)mhz;
  84. }
  85. }
  86. }
  87. jack_time_t __jack_cpu_mhz;
  88. void InitTime()
  89. {
  90. __jack_cpu_mhz = GetMhz();
  91. }
  92. #else
  93. void InitTime()
  94. {}
  95. #endif
  96. #endif