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