Browse Source
WL#5363: Thread Pool Service Interface
WL#5363: Thread Pool Service Interface
In order to allow thread schedulers to be dynamically loaded, it is necessary to make the following changes to the server: - Two new service interfaces - Modifications to InnoDB to inform the thread scheduler of state changes. - Changes to the VIO subsystem for checking if data is available on a socket. - Elimination of remains of the old thread pool implementation. The two new service interfaces introduces are: my_thread_scheduler A service interface to register a thread scheduler. thd_wait A service interface to inform thread scheduler that the thread is about to start waiting. In addition, the patch adds code that: - Add a call to thd_wait for table locks in mysys thd_lock.c by introducing a set function that can be used to set a callback to be used when waiting on a lock and resuming from waiting. - Calling the mysys set function from the server to set the callbacks correctly.pull/73/head
37 changed files with 646 additions and 128 deletions
-
4.bzr-mysql/default.conf
-
2include/Makefile.am
-
7include/config-win.h
-
2include/mysql/plugin.h
-
21include/mysql/plugin.h.pp
-
83include/mysql/service_thd_wait.h
-
65include/mysql/service_thread_scheduler.h
-
2include/mysql/services.h
-
3include/service_versions.h
-
2include/thr_lock.h
-
1include/violite.h
-
6libservices/CMakeLists.txt
-
4libservices/Makefile.am
-
21libservices/my_thread_scheduler_service.c
-
19libservices/thd_wait_service.c
-
2mysys/my_init.c
-
31mysys/thr_lock.c
-
1sql/authors.h
-
51sql/mysqld.cc
-
3sql/mysqld.h
-
162sql/scheduler.cc
-
61sql/scheduler.h
-
43sql/sql_callback.h
-
75sql/sql_class.cc
-
7sql/sql_class.h
-
15sql/sql_connect.cc
-
4sql/sql_connect.h
-
16sql/sql_plugin_services.h
-
6sql/sql_show.cc
-
19sql/sys_vars.cc
-
4storage/innobase/buf/buf0flu.c
-
4storage/innobase/buf/buf0rea.c
-
6storage/innobase/srv/srv0srv.c
-
10vio/vio.c
-
3vio/vio_priv.h
-
4vio/viosocket.c
-
5vio/viossl.c
@ -1,4 +1,4 @@ |
|||
[MYSQL] |
|||
post_commit_to = "commits@lists.mysql.com" |
|||
post_push_to = "commits@lists.mysql.com" |
|||
# post_commit_to = "commits@lists.mysql.com" |
|||
# post_push_to = "commits@lists.mysql.com" |
|||
tree_name = "mysql-trunk" |
|||
@ -0,0 +1,83 @@ |
|||
/* Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; version 2 of the License. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
|||
|
|||
#ifndef MYSQL_SERVICE_THD_WAIT_INCLUDED |
|||
#define MYSQL_SERVICE_THD_WAIT_INCLUDED |
|||
|
|||
/** |
|||
@file include/mysql/service_thd_wait.h |
|||
This service provides functions for plugins and storage engines to report |
|||
when they are going to sleep/stall. |
|||
|
|||
SYNOPSIS |
|||
thd_wait_begin() - call just before a wait begins |
|||
thd Thread object |
|||
Use NULL if the thd is NOT known. |
|||
wait_type Type of wait |
|||
1 -- short wait (e.g. for mutex) |
|||
2 -- medium wait (e.g. for disk io) |
|||
3 -- large wait (e.g. for locked row/table) |
|||
NOTES |
|||
This is used by the threadpool to have better knowledge of which |
|||
threads that currently are actively running on CPUs. When a thread |
|||
reports that it's going to sleep/stall, the threadpool scheduler is |
|||
free to start another thread in the pool most likely. The expected wait |
|||
time is simply an indication of how long the wait is expected to |
|||
become, the real wait time could be very different. |
|||
|
|||
thd_wait_end() called immediately after the wait is complete |
|||
|
|||
thd_wait_end() MUST be called if thd_wait_begin() was called. |
|||
|
|||
Using thd_wait_...() service is optional but recommended. Using it will |
|||
improve performance as the thread pool will be more active at managing the |
|||
thread workload. |
|||
*/ |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
typedef enum _thd_wait_type_e { |
|||
THD_WAIT_MUTEX= 1, |
|||
THD_WAIT_DISKIO= 2, |
|||
THD_WAIT_ROW_TABLE_LOCK= 3, |
|||
THD_WAIT_GLOBAL_LOCK= 4 |
|||
} thd_wait_type; |
|||
|
|||
extern struct thd_wait_service_st { |
|||
void (*thd_wait_begin_func)(MYSQL_THD, thd_wait_type); |
|||
void (*thd_wait_end_func)(MYSQL_THD); |
|||
} *thd_wait_service; |
|||
|
|||
#ifdef MYSQL_DYNAMIC_PLUGIN |
|||
|
|||
#define thd_wait_begin(_THD, _WAIT_TYPE) \ |
|||
thd_wait_service->thd_wait_begin_func(_THD, _WAIT_TYPE) |
|||
#define thd_wait_end(_THD) thd_wait_service->thd_wait_end_func(_THD) |
|||
|
|||
#else |
|||
|
|||
void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type); |
|||
void thd_wait_end(MYSQL_THD thd); |
|||
|
|||
#endif |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,65 @@ |
|||
/* |
|||
Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; version 2 of the License. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifndef SERVICE_THREAD_SCHEDULER_INCLUDED |
|||
#define SERVICE_THREAD_SCHEDULER_INCLUDED |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
struct scheduler_functions; |
|||
|
|||
extern struct my_thread_scheduler_service { |
|||
int (*set)(struct scheduler_functions *scheduler); |
|||
int (*reset)(); |
|||
} *my_thread_scheduler_service; |
|||
|
|||
#ifdef MYSQL_DYNAMIC_PLUGIN |
|||
|
|||
#define my_thread_scheduler_set(F) my_thread_scheduler_service->set((F)) |
|||
#define my_thread_scheduler_reset() my_thread_scheduler_service->reset() |
|||
|
|||
#else |
|||
|
|||
/** |
|||
Set the thread scheduler to use for the server. |
|||
|
|||
@param scheduler Pointer to scheduler callbacks to use. |
|||
@retval 0 Scheduler installed correctly. |
|||
@retval 1 Invalid value (NULL) used for scheduler. |
|||
*/ |
|||
int my_thread_scheduler_set(struct scheduler_functions *scheduler); |
|||
|
|||
/** |
|||
Restore the previous thread scheduler. |
|||
|
|||
@note If no thread scheduler was installed previously with |
|||
thd_set_thread_scheduler, this function will report an error. |
|||
|
|||
@retval 0 Scheduler installed correctly. |
|||
@retval 1 No scheduler installed. |
|||
*/ |
|||
int my_thread_scheduler_reset(); |
|||
|
|||
#endif |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* SERVICE_THREAD_SCHEDULER_INCLUDED */ |
|||
@ -0,0 +1,21 @@ |
|||
/* |
|||
Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; version 2 of the License. |
|||
|
|||
This program is distributed in the hope that it will be useful, but |
|||
WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|||
USA |
|||
*/ |
|||
|
|||
#include <service_versions.h> |
|||
SERVICE_VERSION my_thread_scheduler_service= |
|||
(void*)VERSION_my_thread_scheduler; |
|||
@ -0,0 +1,19 @@ |
|||
/* |
|||
Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; version 2 of the License. |
|||
|
|||
This program is distributed in the hope that it will be useful, but |
|||
WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#include <service_versions.h> |
|||
SERVICE_VERSION *thd_wait_service= (void*)VERSION_thd_wait; |
|||
@ -0,0 +1,43 @@ |
|||
/* |
|||
Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; version 2 of the License. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifndef SQL_CALLBACK_INCLUDED |
|||
#define SQL_CALLBACK_INCLUDED |
|||
|
|||
/** |
|||
Macro used for an internal callback. |
|||
|
|||
The macro will check that the object exists and that the function |
|||
is defined. If that is the case, it will call the function with the |
|||
given parameters. |
|||
|
|||
If the object or the function is not defined, the callback will be |
|||
considered successful (nothing needed to be done) and will |
|||
therefore return no error. |
|||
*/ |
|||
|
|||
#define MYSQL_CALLBACK(OBJ, FUNC, PARAMS) \ |
|||
do { \ |
|||
if ((OBJ) && ((OBJ)->FUNC)) \ |
|||
(OBJ)->FUNC PARAMS; \ |
|||
} while (0) |
|||
|
|||
#define MYSQL_CALLBACK_ELSE(OBJ, FUNC, PARAMS, ELSE) \ |
|||
(((OBJ) && ((OBJ)->FUNC)) ? (OBJ)->FUNC PARAMS : (ELSE)) |
|||
|
|||
|
|||
#endif /* SQL_CALLBACK_INCLUDED */ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue