1 /* Copyright (c) 2008 MySQL AB, 2009 Sun Microsystems, Inc.
2    Use is subject to license terms.
3 
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2.0,
6   as published by the Free Software Foundation.
7 
8   This program is also distributed with certain software (including
9   but not limited to OpenSSL) that is licensed under separate terms,
10   as designated in a particular file or component or in included license
11   documentation.  The authors of MySQL hereby grant you an additional
12   permission to link the program and your derivative works with the
13   separately licensed software that they have included with MySQL.
14 
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License, version 2.0, for more details.
19 
20   You should have received a copy of the GNU General Public License
21   along with this program; if not, write to the Free Software
22   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
23 
24 /*
25   rdtsc3 -- multi-platform timer code
26   pgulutzan@mysql.com, 2005-08-29
27   modified 2008-11-02
28 */
29 
30 #ifndef MY_RDTSC_H
31 #define MY_RDTSC_H
32 
33 /**
34   Characteristics of a timer.
35 */
36 struct my_timer_unit_info
37 {
38   /** Routine used for the timer. */
39   ulonglong routine;
40   /** Overhead of the timer. */
41   ulonglong overhead;
42   /** Frequency of the  timer. */
43   ulonglong frequency;
44   /** Resolution of the timer. */
45   ulonglong resolution;
46 };
47 
48 /**
49   Characteristics of all the supported timers.
50   @sa my_timer_init().
51 */
52 struct my_timer_info
53 {
54   /** Characteristics of the cycle timer. */
55   struct my_timer_unit_info cycles;
56   /** Characteristics of the nanosecond timer. */
57   struct my_timer_unit_info nanoseconds;
58   /** Characteristics of the microsecond timer. */
59   struct my_timer_unit_info microseconds;
60   /** Characteristics of the millisecond timer. */
61   struct my_timer_unit_info milliseconds;
62   /** Characteristics of the tick timer. */
63   struct my_timer_unit_info ticks;
64 };
65 
66 typedef struct my_timer_info MY_TIMER_INFO;
67 
68 C_MODE_START
69 
70 /**
71   A cycle timer.
72   @return the current timer value, in cycles.
73 */
74 ulonglong my_timer_cycles(void);
75 
76 /**
77   A namoseconds timer.
78   @return the current timer value, in nanoseconds.
79 */
80 ulonglong my_timer_nanoseconds(void);
81 
82 /**
83   A microseconds timer.
84   @return the current timer value, in microseconds.
85 */
86 ulonglong my_timer_microseconds(void);
87 
88 /**
89   A millisecond timer.
90   @return the current timer value, in milliseconds.
91 */
92 ulonglong my_timer_milliseconds(void);
93 
94 /**
95   A ticks timer.
96   @return the current timer value, in ticks.
97 */
98 ulonglong my_timer_ticks(void);
99 
100 /**
101   Timer initialization function.
102   @param [out] mti the timer characteristics.
103 */
104 void my_timer_init(MY_TIMER_INFO *mti);
105 
106 C_MODE_END
107 
108 #define MY_TIMER_ROUTINE_ASM_X86                  1
109 #define MY_TIMER_ROUTINE_ASM_X86_64               2
110 #define MY_TIMER_ROUTINE_RDTSCLL                  3
111 #define MY_TIMER_ROUTINE_ASM_X86_WIN              4
112 #define MY_TIMER_ROUTINE_RDTSC                    5
113 #define MY_TIMER_ROUTINE_ASM_IA64                 6
114 #define MY_TIMER_ROUTINE_ASM_PPC                  7
115 #define MY_TIMER_ROUTINE_SGI_CYCLE                8
116 #define MY_TIMER_ROUTINE_GETHRTIME                9
117 #define MY_TIMER_ROUTINE_READ_REAL_TIME          10
118 #define MY_TIMER_ROUTINE_CLOCK_GETTIME           11
119 #define MY_TIMER_ROUTINE_NXGETTIME               12
120 #define MY_TIMER_ROUTINE_GETTIMEOFDAY            13
121 #define MY_TIMER_ROUTINE_QUERYPERFORMANCECOUNTER 14
122 #define MY_TIMER_ROUTINE_GETTICKCOUNT            15
123 #define MY_TIMER_ROUTINE_TIME                    16
124 #define MY_TIMER_ROUTINE_TIMES                   17
125 #define MY_TIMER_ROUTINE_FTIME                   18
126 #define MY_TIMER_ROUTINE_ASM_PPC64               19
127 #define MY_TIMER_ROUTINE_ASM_SUNPRO_SPARC64      20
128 #define MY_TIMER_ROUTINE_ASM_SUNPRO_SPARC32      21
129 #define MY_TIMER_ROUTINE_ASM_SUNPRO_I386         22
130 #define MY_TIMER_ROUTINE_ASM_GCC_SPARC64         23
131 #define MY_TIMER_ROUTINE_ASM_GCC_SPARC32         24
132 #define MY_TIMER_ROUTINE_MACH_ABSOLUTE_TIME      25
133 #define MY_TIMER_ROUTINE_GETSYSTEMTIMEASFILETIME 26
134 #define MY_TIMER_ROUTINE_ASM_SUNPRO_X86_64       27
135 
136 #endif
137 
138