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