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