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.

119 lines
2.6KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2008 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. jack_log("InitTime");
  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. jack_log("InitTime freq = %ld %ld", _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. perror("can't open /proc/cpuinfo\n");
  53. exit(1);
  54. }
  55. for (;;) {
  56. jack_time_t mhz;
  57. int ret;
  58. char buf[1000];
  59. if (fgets(buf, sizeof(buf), f) == NULL) {
  60. jack_error ("FATAL: cannot locate cpu MHz in "
  61. "/proc/cpuinfo\n");
  62. exit(1);
  63. }
  64. #if defined(__powerpc__)
  65. ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
  66. #elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
  67. defined(__x86_64__)
  68. ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz);
  69. #elif defined( __sparc__ )
  70. ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz);
  71. #elif defined( __mc68000__ )
  72. ret = sscanf(buf, "Clocking: %" SCNu64, &mhz);
  73. #elif defined( __s390__ )
  74. ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
  75. #else /* MIPS, ARM, alpha */
  76. ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz);
  77. #endif
  78. if (ret == 1) {
  79. fclose(f);
  80. return (jack_time_t)mhz;
  81. }
  82. }
  83. }
  84. jack_time_t __jack_cpu_mhz;
  85. void InitTime()
  86. {
  87. __jack_cpu_mhz = GetMhz();
  88. }
  89. #else
  90. void InitTime()
  91. {}
  92. #endif
  93. #endif