2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2006 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "JackError.h"
26 double __jack_time_ratio
;
28 /* This should only be called ONCE per process. */
31 JackLog("InitTime\n");
32 mach_timebase_info_data_t info
;
33 mach_timebase_info(&info
);
34 __jack_time_ratio
= ((float)info
.numer
/ info
.denom
) / 1000;
41 EXPORT LARGE_INTEGER _jack_freq
;
45 QueryPerformanceFrequency(&_jack_freq
);
46 JackLog("InitTime freq = %ld %ld\n", _jack_freq
.HighPart
, _jack_freq
.LowPart
);
47 _jack_freq
.QuadPart
= _jack_freq
.QuadPart
/ 1000000; // by usec
50 jack_time_t
GetMicroSeconds(void)
53 QueryPerformanceCounter (&t1
);
54 return (jack_time_t
)(((double)t1
.QuadPart
)/((double)_jack_freq
.QuadPart
));
65 jack_time_t
GetMhz(void)
67 FILE *f
= fopen("/proc/cpuinfo", "r");
70 perror("can't open /proc/cpuinfo\n");
80 if (fgets(buf
, sizeof(buf
), f
) == NULL
) {
81 jack_error ("FATAL: cannot locate cpu MHz in "
86 #if defined(__powerpc__)
87 ret
= sscanf(buf
, "clock\t: %" SCNu64
"MHz", &mhz
);
88 #elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
90 ret
= sscanf(buf
, "cpu MHz : %" SCNu64
, &mhz
);
91 #elif defined( __sparc__ )
92 ret
= sscanf(buf
, "Cpu0Bogo : %" SCNu64
, &mhz
);
93 #elif defined( __mc68000__ )
94 ret
= sscanf(buf
, "Clocking: %" SCNu64
, &mhz
);
95 #elif defined( __s390__ )
96 ret
= sscanf(buf
, "bogomips per cpu: %" SCNu64
, &mhz
);
97 #else /* MIPS, ARM, alpha */
98 ret
= sscanf(buf
, "BogoMIPS : %" SCNu64
, &mhz
);
103 return (jack_time_t
)mhz
;
108 jack_time_t __jack_cpu_mhz
;
112 __jack_cpu_mhz
= GetMhz();