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

Revision 742, 3.1 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

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