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.

123 lines
2.7KB

  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 Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #if defined(HAVE_CONFIG_H)
  17. #include "config.h"
  18. #endif
  19. #include "JackTime.h"
  20. #include "JackError.h"
  21. #ifdef __APPLE__
  22. double __jack_time_ratio;
  23. /* This should only be called ONCE per process. */
  24. void InitTime()
  25. {
  26. jack_log("InitTime");
  27. mach_timebase_info_data_t info;
  28. mach_timebase_info(&info);
  29. __jack_time_ratio = ((float)info.numer / info.denom) / 1000;
  30. }
  31. #endif
  32. #ifdef WIN32
  33. SERVER_EXPORT LARGE_INTEGER _jack_freq;
  34. void InitTime()
  35. {
  36. QueryPerformanceFrequency(&_jack_freq);
  37. jack_log("InitTime freq = %ld %ld", _jack_freq.HighPart, _jack_freq.LowPart);
  38. _jack_freq.QuadPart = _jack_freq.QuadPart / 1000000; // by usec
  39. }
  40. jack_time_t GetMicroSeconds(void)
  41. {
  42. LARGE_INTEGER t1;
  43. QueryPerformanceCounter (&t1);
  44. return (jack_time_t)(((double)t1.QuadPart)/((double)_jack_freq.QuadPart));
  45. }
  46. // TODO
  47. #endif
  48. #ifdef linux
  49. #ifdef GETCYCLE_TIME
  50. #include <stdio.h>
  51. jack_time_t GetMhz(void)
  52. {
  53. FILE *f = fopen("/proc/cpuinfo", "r");
  54. if (f == 0) {
  55. perror("can't open /proc/cpuinfo\n");
  56. exit(1);
  57. }
  58. for (;;) {
  59. jack_time_t mhz;
  60. int ret;
  61. char buf[1000];
  62. if (fgets(buf, sizeof(buf), f) == NULL) {
  63. jack_error ("FATAL: cannot locate cpu MHz in "
  64. "/proc/cpuinfo\n");
  65. exit(1);
  66. }
  67. #if defined(__powerpc__)
  68. ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
  69. #elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
  70. defined(__x86_64__)
  71. ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz);
  72. #elif defined( __sparc__ )
  73. ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz);
  74. #elif defined( __mc68000__ )
  75. ret = sscanf(buf, "Clocking: %" SCNu64, &mhz);
  76. #elif defined( __s390__ )
  77. ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
  78. #else /* MIPS, ARM, alpha */
  79. ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz);
  80. #endif
  81. if (ret == 1) {
  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