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