service_thd_wait.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (c) 2010, 2011, 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 as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. #ifndef MYSQL_SERVICE_THD_WAIT_INCLUDED
  13. #define MYSQL_SERVICE_THD_WAIT_INCLUDED
  14. /**
  15. @file include/mysql/service_thd_wait.h
  16. This service provides functions for plugins and storage engines to report
  17. when they are going to sleep/stall.
  18. SYNOPSIS
  19. thd_wait_begin() - call just before a wait begins
  20. thd Thread object
  21. Use NULL if the thd is NOT known.
  22. wait_type Type of wait
  23. 1 -- short wait (e.g. for mutex)
  24. 2 -- medium wait (e.g. for disk io)
  25. 3 -- large wait (e.g. for locked row/table)
  26. NOTES
  27. This is used by the threadpool to have better knowledge of which
  28. threads that currently are actively running on CPUs. When a thread
  29. reports that it's going to sleep/stall, the threadpool scheduler is
  30. free to start another thread in the pool most likely. The expected wait
  31. time is simply an indication of how long the wait is expected to
  32. become, the real wait time could be very different.
  33. thd_wait_end() called immediately after the wait is complete
  34. thd_wait_end() MUST be called if thd_wait_begin() was called.
  35. Using thd_wait_...() service is optional but recommended. Using it will
  36. improve performance as the thread pool will be more active at managing the
  37. thread workload.
  38. */
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /*
  43. One should only report wait events that could potentially block for a
  44. long time. A mutex wait is too short of an event to report. The reason
  45. is that an event which is reported leads to a new thread starts
  46. executing a query and this has a negative impact of usage of CPU caches
  47. and thus the expected gain of starting a new thread must be higher than
  48. the expected cost of lost performance due to starting a new thread.
  49. Good examples of events that should be reported are waiting for row locks
  50. that could easily be for many milliseconds or even seconds and the same
  51. holds true for global read locks, table locks and other meta data locks.
  52. Another event of interest is going to sleep for an extended time.
  53. */
  54. typedef enum _thd_wait_type_e {
  55. THD_WAIT_SLEEP= 1,
  56. THD_WAIT_DISKIO= 2,
  57. THD_WAIT_ROW_LOCK= 3,
  58. THD_WAIT_GLOBAL_LOCK= 4,
  59. THD_WAIT_META_DATA_LOCK= 5,
  60. THD_WAIT_TABLE_LOCK= 6,
  61. THD_WAIT_USER_LOCK= 7,
  62. THD_WAIT_BINLOG= 8,
  63. THD_WAIT_GROUP_COMMIT= 9,
  64. THD_WAIT_SYNC= 10,
  65. THD_WAIT_NET= 11,
  66. THD_WAIT_LAST= 12
  67. } thd_wait_type;
  68. extern struct thd_wait_service_st {
  69. void (*thd_wait_begin_func)(MYSQL_THD, int);
  70. void (*thd_wait_end_func)(MYSQL_THD);
  71. } *thd_wait_service;
  72. #ifdef MYSQL_DYNAMIC_PLUGIN
  73. #define thd_wait_begin(_THD, _WAIT_TYPE) \
  74. thd_wait_service->thd_wait_begin_func(_THD, _WAIT_TYPE)
  75. #define thd_wait_end(_THD) thd_wait_service->thd_wait_end_func(_THD)
  76. #else
  77. void thd_wait_begin(MYSQL_THD thd, int wait_type);
  78. void thd_wait_end(MYSQL_THD thd);
  79. #endif
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif