root/trunk/libffado/src/libutil/cycles.h

Revision 445, 2.4 kB (checked in by pieterpalmers, 14 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

Line 
1 /* cycles.h
2
3 FFADO Streaming API
4 FFADO = Firewire (pro-)audio for linux
5
6 http://ffado.sf.net
7
8 Based upon cycles.h from the jackdmp package.
9 Original Copyright:
10
11   Copyright (C) 2001 Paul Davis
12   Code derived from various headers from the Linux kernel
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28 */
29
30 #ifndef __FFADO_CYCLES_H__
31 #define __FFADO_CYCLES_H__
32
33 /*
34  * Standard way to access the cycle timer on i586+ CPUs.
35  * Currently only used on SMP.
36  *
37  * If you really have a SMP machine with i486 chips or older,
38  * compile for that, and this will just always return zero.
39  * That's ok, it just means that the nicer scheduling heuristics
40  * won't work for you.
41  *
42  * We only use the low 32 bits, and we'd simply better make sure
43  * that we reschedule before that wraps. Scheduling at least every
44  * four billion cycles just basically sounds like a good idea,
45  * regardless of how fast the machine is.
46  */
47
48 #ifdef __linux__
49
50 #ifdef __PPC__
51
52 /* PowerPC */
53
54 #define CPU_FTR_601            0x00000100
55
56 typedef unsigned long cycles_t;
57
58 /* For the "cycle" counter we use the timebase lower half. */
59
60 extern cycles_t cacheflush_time;
61
62 static inline cycles_t get_cycles(void)
63 {
64     cycles_t ret = 0;
65
66     __asm__ __volatile__(
67         "98:    mftb %0\n"
68         "99:\n"
69         ".section __ftr_fixup,\"a\"\n"
70         "    .long %1\n"
71         "    .long 0\n"
72         "    .long 98b\n"
73         "    .long 99b\n"
74         ".previous"
75     : "=r" (ret) : "i" (CPU_FTR_601));
76     return ret;
77 }
78
79 #endif
80
81 #ifdef __i386__
82
83 typedef unsigned long long cycles_t;
84
85 extern cycles_t cacheflush_time;
86
87 #define rdtscll(val) \
88      __asm__ __volatile__("rdtsc" : "=A" (val))
89
90 static inline cycles_t get_cycles (void)
91 {
92     unsigned long long ret;
93
94     rdtscll(ret);
95     return ret;
96 }
97
98 #endif
99
100 #endif
101
102 #endif // __FFADO_CYCLES_H__
Note: See TracBrowser for help on using the browser.