** Warning: Cannot open xref database.
1 /*
2 Copyright (C) 2001 Paul Davis
3 Code derived from various headers from the Linux kernel
4
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.
9
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.
14
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.
18
19 $Id: cycles.h,v 1.4 2003/08/09 18:02:10 joq Exp $
20 */
21
22 #ifndef __jack_cycles_h__
23 #define __jack_cycles_h__
24
25 #if defined(__i386__) || defined(__x86_64__)
26
27 /*
28 * Standard way to access the cycle counter on i586+ CPUs.
29 * Currently only used on SMP.
30 *
31 * If you really have a SMP machine with i486 chips or older,
32 * compile for that, and this will just always return zero.
33 * That's ok, it just means that the nicer scheduling heuristics
34 * won't work for you.
35 *
36 * We only use the low 32 bits, and we'd simply better make sure
37 * that we reschedule before that wraps. Scheduling at least every
38 * four billion cycles just basically sounds like a good idea,
39 * regardless of how fast the machine is.
40 */
41 typedef unsigned long long cycles_t;
42
43 extern cycles_t cacheflush_time;
44
45 #define rdtscll(val) \
46 __asm__ __volatile__("rdtsc" : "=A" (val))
47
48 static inline cycles_t get_cycles (void)
49 {
50 unsigned long long ret;
51
52 rdtscll(ret);
53 return ret;
54 }
55
56 #elif defined(__powerpc__)
57
58 #define CPU_FTR_601 0x00000100
59
60 typedef unsigned long cycles_t;
61
62 /*
63 * For the "cycle" counter we use the timebase lower half.
64 * Currently only used on SMP.
65 */
66
67 extern cycles_t cacheflush_time;
68
69 static inline cycles_t get_cycles(void)
70 {
71 cycles_t ret = 0;
72
73 __asm__ __volatile__(
74 "98: mftb %0\n"
75 "99:\n"
76 ".section __ftr_fixup,\"a\"\n"
77 " .long %1\n"
78 " .long 0\n"
79 " .long 98b\n"
80 " .long 99b\n"
81 ".previous"
82 : "=r" (ret) : "i" (CPU_FTR_601));
83 return ret;
84 }
85
86 #elif defined(__ia64__)
87 /* ia64 */
88
89 typedef unsigned long cycles_t;
90 static inline cycles_t
91 get_cycles (void)
92 {
93 cycles_t ret;
94 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
95 return ret;
96 }
97
98 #elif defined(__alpha__)
99 /* alpha */
100
101 typedef unsigned int cycles_t;
102 static inline cycles_t get_cycles (void)
103 {
104 cycles_t ret;
105 __asm__ __volatile__ ("rpcc %0" : "=r"(ret));
106 return ret;
107 }
108
109 #else
110 /* generic solution */
111
112 #warning You are compiling JACK on a platform for which jack/cycles.h needs work
113 #include <sys/time.h>
114
115 typedef long cycles_t;
116 extern cycles_t cacheflush_time;
117
118 static inline cycles_t get_cycles(void)
119 {
120 struct timeval tv;
121 gettimeofday (&tv, NULL);
122
123 return tv.tv_usec;
124 }
125
126 #endif
127
128 #endif /* __jack_cycles_h__ */
129
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.