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