52
52
typedef byte lock_word_t;
55
#if defined UNIV_PFS_MUTEX || defined UNIV_PFS_RWLOCK
56
/* There are mutexes/rwlocks that we want to exclude from
57
instrumentation even if their corresponding performance schema
58
define is set. And this PFS_NOT_INSTRUMENTED is used
59
as the key value to dentify those objects that would
60
be excluded from instrumentation. */
61
# define PFS_NOT_INSTRUMENTED ULINT32_UNDEFINED
63
# define PFS_IS_INSTRUMENTED(key) ((key) != PFS_NOT_INSTRUMENTED)
65
/* By default, buffer mutexes and rwlocks will be excluded from
66
instrumentation due to their large number of instances. */
67
# define PFS_SKIP_BUFFER_MUTEX_RWLOCK
69
#endif /* UNIV_PFS_MUTEX || UNIV_PFS_RWLOCK */
72
/* Key defines to register InnoDB mutexes with performance schema */
73
extern mysql_pfs_key_t autoinc_mutex_key;
74
extern mysql_pfs_key_t btr_search_enabled_mutex_key;
75
extern mysql_pfs_key_t buffer_block_mutex_key;
76
extern mysql_pfs_key_t buf_pool_mutex_key;
77
extern mysql_pfs_key_t buf_pool_zip_mutex_key;
78
extern mysql_pfs_key_t cache_last_read_mutex_key;
79
extern mysql_pfs_key_t dict_foreign_err_mutex_key;
80
extern mysql_pfs_key_t dict_sys_mutex_key;
81
extern mysql_pfs_key_t file_format_max_mutex_key;
82
extern mysql_pfs_key_t fil_system_mutex_key;
83
extern mysql_pfs_key_t flush_list_mutex_key;
84
extern mysql_pfs_key_t hash_table_mutex_key;
85
extern mysql_pfs_key_t ibuf_bitmap_mutex_key;
86
extern mysql_pfs_key_t ibuf_mutex_key;
87
extern mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key;
88
extern mysql_pfs_key_t ios_mutex_key;
89
extern mysql_pfs_key_t log_sys_mutex_key;
90
extern mysql_pfs_key_t log_flush_order_mutex_key;
91
extern mysql_pfs_key_t kernel_mutex_key;
92
# ifdef UNIV_MEM_DEBUG
93
extern mysql_pfs_key_t mem_hash_mutex_key;
94
# endif /* UNIV_MEM_DEBUG */
95
extern mysql_pfs_key_t mem_pool_mutex_key;
96
extern mysql_pfs_key_t mutex_list_mutex_key;
97
extern mysql_pfs_key_t purge_sys_mutex_key;
98
extern mysql_pfs_key_t recv_sys_mutex_key;
99
extern mysql_pfs_key_t rseg_mutex_key;
100
# ifdef UNIV_SYNC_DEBUG
101
extern mysql_pfs_key_t rw_lock_debug_mutex_key;
102
# endif /* UNIV_SYNC_DEBUG */
103
extern mysql_pfs_key_t rw_lock_list_mutex_key;
104
extern mysql_pfs_key_t rw_lock_mutex_key;
105
extern mysql_pfs_key_t srv_dict_tmpfile_mutex_key;
106
extern mysql_pfs_key_t srv_innodb_monitor_mutex_key;
107
extern mysql_pfs_key_t srv_misc_tmpfile_mutex_key;
108
extern mysql_pfs_key_t srv_monitor_file_mutex_key;
109
extern mysql_pfs_key_t syn_arr_mutex_key;
110
# ifdef UNIV_SYNC_DEBUG
111
extern mysql_pfs_key_t sync_thread_mutex_key;
112
# endif /* UNIV_SYNC_DEBUG */
113
extern mysql_pfs_key_t trx_doublewrite_mutex_key;
114
extern mysql_pfs_key_t thr_local_mutex_key;
115
extern mysql_pfs_key_t trx_undo_mutex_key;
116
#endif /* UNIV_PFS_MUTEX */
55
118
/******************************************************************//**
56
119
Initializes the synchronization data structures. */
131
#undef mutex_free /* Fix for MacOS X */
133
#ifdef UNIV_PFS_MUTEX
134
/**********************************************************************
135
Following mutex APIs would be performance schema instrumented
136
if "UNIV_PFS_MUTEX" is defined:
144
These mutex APIs will point to corresponding wrapper functions that contain
145
the performance schema instrumentation if "UNIV_PFS_MUTEX" is defined.
146
The instrumented wrapper functions have the prefix of "innodb_".
148
NOTE! The following macro should be used in mutex operation, not the
149
corresponding function. */
67
151
/******************************************************************//**
68
152
Creates, or rather, initializes a mutex object to a specified memory
69
153
location (which must be appropriately aligned). The mutex is initialized
70
154
in the reset state. Explicit freeing of the mutex with mutex_free is
71
155
necessary only if the memory block containing it is freed. */
74
# ifdef UNIV_SYNC_DEBUG
75
# define mutex_create(M, level) \
157
# ifdef UNIV_SYNC_DEBUG
158
# define mutex_create(K, M, level) \
159
pfs_mutex_create_func((K), (M), #M, (level), __FILE__, __LINE__)
161
# define mutex_create(K, M, level) \
162
pfs_mutex_create_func((K), (M), #M, __FILE__, __LINE__)
163
# endif/* UNIV_SYNC_DEBUG */
165
# define mutex_create(K, M, level) \
166
pfs_mutex_create_func((K), (M), __FILE__, __LINE__)
167
# endif /* UNIV_DEBUG */
169
# define mutex_enter(M) \
170
pfs_mutex_enter_func((M), __FILE__, __LINE__)
172
# define mutex_enter_nowait(M) \
173
pfs_mutex_enter_nowait_func((M), __FILE__, __LINE__)
175
# define mutex_exit(M) pfs_mutex_exit_func(M)
177
# define mutex_free(M) pfs_mutex_free_func(M)
179
#else /* UNIV_PFS_MUTEX */
181
/* If "UNIV_PFS_MUTEX" is not defined, the mutex APIs point to
182
original non-instrumented functions */
184
# ifdef UNIV_SYNC_DEBUG
185
# define mutex_create(K, M, level) \
76
186
mutex_create_func((M), #M, (level), __FILE__, __LINE__)
78
# define mutex_create(M, level) \
187
# else /* UNIV_SYNC_DEBUG */
188
# define mutex_create(K, M, level) \
79
189
mutex_create_func((M), #M, __FILE__, __LINE__)
82
# define mutex_create(M, level) \
190
# endif /* UNIV_SYNC_DEBUG */
191
# else /* UNIV_DEBUG */
192
# define mutex_create(K, M, level) \
83
193
mutex_create_func((M), __FILE__, __LINE__)
194
# endif /* UNIV_DEBUG */
196
# define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)
198
# define mutex_enter_nowait(M) \
199
mutex_enter_nowait_func((M), __FILE__, __LINE__)
201
# define mutex_exit(M) mutex_exit_func(M)
203
# define mutex_free(M) mutex_free_func(M)
205
#endif /* UNIV_PFS_MUTEX */
86
207
/******************************************************************//**
87
208
Creates, or rather, initializes a mutex object in a specified memory
102
223
const char* cfile_name, /*!< in: file name where created */
103
224
ulint cline); /*!< in: file line where created */
105
#undef mutex_free /* Fix for MacOS X */
107
226
/******************************************************************//**
227
NOTE! Use the corresponding macro mutex_free(), not directly this function!
108
228
Calling this function is obligatory only if the memory buffer containing
109
229
the mutex is freed. Removes a mutex object from the mutex list. The mutex
110
230
is checked to be in the reset state. */
115
235
mutex_t* mutex); /*!< in: mutex */
116
236
/**************************************************************//**
117
237
NOTE! The following macro should be used in mutex locking, not the
118
238
corresponding function. */
120
#define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)
121
/**************************************************************//**
122
NOTE! The following macro should be used in mutex locking, not the
123
corresponding function. */
125
240
/* NOTE! currently same as mutex_enter! */
127
242
#define mutex_enter_fast(M) mutex_enter_func((M), __FILE__, __LINE__)
137
252
mutex_t* mutex, /*!< in: pointer to mutex */
138
253
const char* file_name, /*!< in: file name where locked */
139
254
ulint line); /*!< in: line where locked */
140
/**************************************************************//**
141
NOTE! The following macro should be used in mutex locking, not the
142
corresponding function. */
144
#define mutex_enter_nowait(M) \
145
mutex_enter_nowait_func((M), __FILE__, __LINE__)
146
255
/********************************************************************//**
147
256
NOTE! Use the corresponding macro in the header file, not this function
148
257
directly. Tries to lock the mutex for the current thread. If the lock is not
158
267
ulint line); /*!< in: line where requested */
159
268
/******************************************************************//**
160
Unlocks a mutex owned by the current thread. */
165
mutex_t* mutex); /*!< in: pointer to mutex */
269
NOTE! Use the corresponding macro mutex_exit(), not directly this function!
270
Unlocks a mutex owned by the current thread. */
275
mutex_t* mutex); /*!< in: pointer to mutex */
278
#ifdef UNIV_PFS_MUTEX
279
/******************************************************************//**
280
NOTE! Please use the corresponding macro mutex_create(), not directly
282
A wrapper function for mutex_create_func(), registers the mutex
283
with peformance schema if "UNIV_PFS_MUTEX" is defined when
284
creating the mutex */
287
pfs_mutex_create_func(
288
/*==================*/
289
PSI_mutex_key key, /*!< in: Performance Schema key */
290
mutex_t* mutex, /*!< in: pointer to memory */
292
const char* cmutex_name, /*!< in: mutex name */
293
# ifdef UNIV_SYNC_DEBUG
294
ulint level, /*!< in: level */
295
# endif /* UNIV_SYNC_DEBUG */
296
# endif /* UNIV_DEBUG */
297
const char* cfile_name, /*!< in: file name where created */
298
ulint cline); /*!< in: file line where created */
299
/******************************************************************//**
300
NOTE! Please use the corresponding macro mutex_enter(), not directly
302
This is a performance schema instrumented wrapper function for
303
mutex_enter_func(). */
306
pfs_mutex_enter_func(
307
/*=================*/
308
mutex_t* mutex, /*!< in: pointer to mutex */
309
const char* file_name, /*!< in: file name where locked */
310
ulint line); /*!< in: line where locked */
311
/********************************************************************//**
312
NOTE! Please use the corresponding macro mutex_enter_nowait(), not directly
314
This is a performance schema instrumented wrapper function for
315
mutex_enter_nowait_func.
316
@return 0 if succeed, 1 if not */
319
pfs_mutex_enter_nowait_func(
320
/*========================*/
321
mutex_t* mutex, /*!< in: pointer to mutex */
322
const char* file_name, /*!< in: file name where mutex
324
ulint line); /*!< in: line where requested */
325
/******************************************************************//**
326
NOTE! Please use the corresponding macro mutex_exit(), not directly
328
A wrap function of mutex_exit_func() with peformance schema instrumentation.
329
Unlocks a mutex owned by the current thread. */
334
mutex_t* mutex); /*!< in: pointer to mutex */
336
/******************************************************************//**
337
NOTE! Please use the corresponding macro mutex_free(), not directly
339
Wrapper function for mutex_free_func(). Also destroys the performance
340
schema probes when freeing the mutex */
345
mutex_t* mutex); /*!< in: mutex */
347
#endif /* UNIV_PFS_MUTEX */
166
349
#ifdef UNIV_SYNC_DEBUG
167
350
/******************************************************************//**
168
351
Returns TRUE if no mutex or rw-lock is currently locked.
487
671
SYNC_SEARCH_SYS, as memory allocation
488
672
can call routines there! Otherwise
489
673
the level is SYNC_MEM_HASH. */
490
#define SYNC_BUF_POOL 150
491
#define SYNC_BUF_BLOCK 149
674
#define SYNC_BUF_POOL 150 /* Buffer pool mutex */
675
#define SYNC_BUF_BLOCK 146 /* Block mutex */
676
#define SYNC_BUF_FLUSH_LIST 145 /* Buffer flush list mutex */
492
677
#define SYNC_DOUBLEWRITE 140
493
678
#define SYNC_ANY_LATCH 135
494
679
#define SYNC_THR_LOCAL 133