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