1 |
/* |
---|
2 |
* Copyright (C) 2005-2007 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 3 of the License, or |
---|
12 |
* (at your option) any later version. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
/* |
---|
25 |
* Copied from the jackd/jackdmp sources |
---|
26 |
* function names changed in order to avoid naming problems when using this in |
---|
27 |
* a jackd backend. |
---|
28 |
*/ |
---|
29 |
|
---|
30 |
/* Original license: |
---|
31 |
* |
---|
32 |
* Copyright (C) 2001 Paul Davis |
---|
33 |
* Copyright (C) 2004-2006 Grame |
---|
34 |
* |
---|
35 |
* This program is free software; you can redistribute it and/or modify |
---|
36 |
* it under the terms of the GNU General Public License as published by |
---|
37 |
* the Free Software Foundation; either version 2 of the License, or |
---|
38 |
* (at your option) any later version. |
---|
39 |
* |
---|
40 |
* This program is distributed in the hope that it will be useful, |
---|
41 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
42 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
43 |
* GNU General Public License for more details. |
---|
44 |
* |
---|
45 |
* You should have received a copy of the GNU General Public License |
---|
46 |
* along with this program; if not, write to the Free Software |
---|
47 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
48 |
* |
---|
49 |
*/ |
---|
50 |
#include "Time.h" |
---|
51 |
|
---|
52 |
#ifdef GETCYCLE_TIME |
---|
53 |
|
---|
54 |
#include <stdio.h> |
---|
55 |
freebob_microsecs_t GetMhz(void) |
---|
56 |
{ |
---|
57 |
FILE *f = fopen("/proc/cpuinfo", "r"); |
---|
58 |
if (f == 0) |
---|
59 |
{ |
---|
60 |
perror("can't open /proc/cpuinfo\n"); |
---|
61 |
exit(1); |
---|
62 |
} |
---|
63 |
|
---|
64 |
for ( ; ; ) |
---|
65 |
{ |
---|
66 |
freebob_microsecs_t mhz; |
---|
67 |
int ret; |
---|
68 |
char buf[1000]; |
---|
69 |
|
---|
70 |
if (fgets(buf, sizeof(buf), f) == NULL) { |
---|
71 |
fprintf (stderr,"FATAL: cannot locate cpu MHz in " |
---|
72 |
"/proc/cpuinfo\n"); |
---|
73 |
exit(1); |
---|
74 |
} |
---|
75 |
|
---|
76 |
#if defined(__powerpc__) |
---|
77 |
ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz); |
---|
78 |
#elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \ |
---|
79 |
defined(__x86_64__) |
---|
80 |
ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz); |
---|
81 |
#elif defined( __sparc__ ) |
---|
82 |
ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz); |
---|
83 |
#elif defined( __mc68000__ ) |
---|
84 |
ret = sscanf(buf, "Clocking: %" SCNu64, &mhz); |
---|
85 |
#elif defined( __s390__ ) |
---|
86 |
ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz); |
---|
87 |
#else /* MIPS, ARM, alpha */ |
---|
88 |
ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz); |
---|
89 |
#endif |
---|
90 |
if (ret == 1) |
---|
91 |
{ |
---|
92 |
fclose(f); |
---|
93 |
return (freebob_microsecs_t)mhz; |
---|
94 |
} |
---|
95 |
} |
---|
96 |
} |
---|
97 |
|
---|
98 |
freebob_microsecs_t __freebob_cpu_mhz; |
---|
99 |
|
---|
100 |
void InitTime() |
---|
101 |
{ |
---|
102 |
__freebob_cpu_mhz = GetMhz(); |
---|
103 |
} |
---|
104 |
|
---|
105 |
#else |
---|
106 |
void InitTime() |
---|
107 |
{} |
---|
108 |
|
---|
109 |
#endif |
---|
110 |
|
---|