~ubuntu-branches/ubuntu/wily/libffado/wily

« back to all changes in this revision

Viewing changes to src/libutil/cycles.h

  • Committer: Package Import Robot
  • Author(s): Artem Popov
  • Date: 2013-01-26 14:55:38 UTC
  • mfrom: (8.1.11 experimental)
  • Revision ID: package-import@ubuntu.com-20130126145538-4we9vsu1ra1d7mgh
Tags: 2.1.0+svn2240-1ubuntu1
* Merge with Debian (LP: #1105818); remaining changes:
  - Build using dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2005-2008 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 2 of the License, or
12
 
 * (at your option) version 3 of the License.
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) version 3 of the License.
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__