my_rdtsc.h 4.2 KB

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