Merge branch 'netone-fixes'
[jack2.git] / linux / cycles.h
blob51be192f5b51e785b7149003a3bbc0bcd7df8c4b
1 /*
2 Copyright (C) 2001 Paul Davis
3 Code derived from various headers from the Linux kernel
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.
19 $Id: cycles.h,v 1.4.2.1 2006/06/20 14:44:00 letz Exp $
22 #ifndef __jack_cycles_h__
23 #define __jack_cycles_h__
26 * Standard way to access the cycle counter on i586+ CPUs.
27 * Currently only used on SMP.
29 * If you really have a SMP machine with i486 chips or older,
30 * compile for that, and this will just always return zero.
31 * That's ok, it just means that the nicer scheduling heuristics
32 * won't work for you.
34 * We only use the low 32 bits, and we'd simply better make sure
35 * that we reschedule before that wraps. Scheduling at least every
36 * four billion cycles just basically sounds like a good idea,
37 * regardless of how fast the machine is.
40 #ifdef __linux__
42 #ifdef __x86_64__
44 typedef unsigned long cycles_t;
45 extern cycles_t cacheflush_time;
47 static inline unsigned long get_cycles(void)
49 unsigned int hi, lo;
50 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
51 return (((unsigned long)hi)<<32) | ((unsigned long)lo);
54 #endif
56 #ifdef __PPC__
58 /* PowerPC */
60 #define CPU_FTR_601 0x00000100
62 typedef unsigned long cycles_t;
64 /* For the "cycle" counter we use the timebase lower half. */
66 extern cycles_t cacheflush_time;
68 static inline cycles_t get_cycles(void)
70 cycles_t ret = 0;
72 __asm__ __volatile__(
73 "98: mftb %0\n"
74 "99:\n"
75 ".section __ftr_fixup,\"a\"\n"
76 " .long %1\n"
77 " .long 0\n"
78 " .long 98b\n"
79 " .long 99b\n"
80 ".previous"
81 : "=r" (ret) : "i" (CPU_FTR_601));
82 return ret;
85 #endif
87 #ifdef __i386__
89 typedef unsigned long long cycles_t;
91 extern cycles_t cacheflush_time;
93 #define rdtscll(val) \
94 __asm__ __volatile__("rdtsc" : "=A" (val))
96 static inline cycles_t get_cycles (void)
98 unsigned long long ret;
100 rdtscll(ret);
101 return ret;
104 #endif
106 #endif
108 #endif /* __jack_cycles_h__ */