Skip to content

Commit

Permalink
fix perfschema for pool-of-threads
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Mar 10, 2020
1 parent a9b8131 commit 7180afa
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 31 deletions.
5 changes: 5 additions & 0 deletions mysql-test/include/maybe_pool_of_threads.combinations
@@ -0,0 +1,5 @@
[pot]
thread_handling=pool-of-threads

[1tpc]
thread_handling=one-thread-per-connection
1 change: 1 addition & 0 deletions mysql-test/include/maybe_pool_of_threads.inc
@@ -0,0 +1 @@
# run with and without threadpool
3 changes: 1 addition & 2 deletions mysql-test/include/not_threadpool.inc
@@ -1,5 +1,4 @@
if (`SELECT count(*) FROM information_schema.GLOBAL_VARIABLES WHERE
VARIABLE_NAME = 'THREAD_HANDLING' AND
VARIABLE_VALUE = 'loaded-dynamically'`){
VARIABLE_NAME = 'THREAD_HANDLING' AND VARIABLE_VALUE = 'pool-of-threads'`){
skip Test requires: 'not_threadpool';
}
1 change: 1 addition & 0 deletions mysql-test/suite/perfschema/t/show_aggregate.test
Expand Up @@ -12,6 +12,7 @@
--source include/have_innodb.inc
--source include/not_embedded.inc
--source include/no_protocol.inc
--source include/maybe_pool_of_threads.inc

--enable_connect_log

Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/perfschema/t/thread_cache.test
Expand Up @@ -2,6 +2,7 @@

--source include/not_embedded.inc
--source include/have_perfschema.inc
--source include/not_threadpool.inc

#
# Important note:
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/suite/perfschema/t/transaction_nested_events.test
Expand Up @@ -11,6 +11,8 @@
--source include/not_embedded.inc
--source include/have_innodb.inc
--source include/no_protocol.inc
--source include/maybe_pool_of_threads.inc

--disable_query_log
--source ../include/transaction_setup.inc
--enable_query_log
Expand Down
11 changes: 0 additions & 11 deletions sql/scheduler.h
Expand Up @@ -82,17 +82,6 @@ extern void post_kill_notification(THD *);
struct thd_scheduler
{
public:
/*
Thread instrumentation for the user job.
This member holds the instrumentation while the user job is not run
by a thread.
Note that this member is not conditionally declared
(ifdef HAVE_PSI_INTERFACE), because doing so will change the binary
layout of THD, which is exposed to plugin code that may be compiled
differently.
*/
PSI_thread *m_psi;
void *data; /* scheduler-specific data structure */
};

Expand Down
1 change: 0 additions & 1 deletion sql/sql_class.cc
Expand Up @@ -758,7 +758,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
thread_stack= 0;
scheduler= thread_scheduler; // Will be fixed later
event_scheduler.data= 0;
event_scheduler.m_psi= 0;
skip_wait_timeout= false;
catalog= (char*)"std"; // the only catalog we have for now
main_security_ctx.init();
Expand Down
18 changes: 3 additions & 15 deletions sql/threadpool_common.cc
Expand Up @@ -151,7 +151,7 @@ static void thread_attach(THD* thd)
pthread_setspecific(THR_KEY_mysys,thd->mysys_var);
thd->thread_stack=(char*)&thd;
thd->store_globals();
PSI_CALL_set_thread(thd->event_scheduler.m_psi);
PSI_CALL_set_thread(thd->get_psi());
mysql_socket_set_thread_owner(thd->net.vio->mysql_socket);
}

Expand Down Expand Up @@ -235,33 +235,20 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data)
pthread_setspecific(THR_KEY_mysys, 0);
my_thread_init();
st_my_thread_var* mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys);
PSI_CALL_set_thread(PSI_CALL_new_thread(key_thread_one_connection, connect, 0));
if (!mysys_var ||!(thd= connect->create_thd(NULL)))
{
/* Out of memory? */
connect->close_and_delete();
if (mysys_var)
{
#ifdef HAVE_PSI_INTERFACE
/*
current PSI is still from worker thread.
Set to 0, to avoid premature cleanup by my_thread_end
*/
if (PSI_server) PSI_server->set_thread(0);
#endif
my_thread_end();
}
return NULL;
}
delete connect;
server_threads.insert(thd);
thd->set_mysys_var(mysys_var);
thd->event_scheduler.data= scheduler_data;

/* Create new PSI thread for use with the THD. */
thd->event_scheduler.m_psi=
PSI_CALL_new_thread(key_thread_one_connection, thd, thd->thread_id);


/* Login. */
thread_attach(thd);
re_init_net_server_extension(thd);
Expand Down Expand Up @@ -301,6 +288,7 @@ static void threadpool_remove_connection(THD *thd)
end_connection(thd);
close_connection(thd, 0);
unlink_thd(thd);
PSI_CALL_delete_current_thread(); // before THD is destroyed
delete thd;

/*
Expand Down
9 changes: 8 additions & 1 deletion storage/perfschema/pfs.cc
Expand Up @@ -2168,7 +2168,6 @@ extern "C" void* pfs_spawn_thread(void *arg)
pfs= create_thread(klass, typed_arg->m_child_identity, 0);
if (likely(pfs != NULL))
{
pfs->m_thread_os_id= my_thread_os_id();
clear_thread_account(pfs);

pfs->m_parent_thread_internal_id= typed_arg->m_thread_internal_id;
Expand Down Expand Up @@ -2267,7 +2266,15 @@ pfs_new_thread_v1(PSI_thread_key key, const void *identity, ulonglong processlis

PFS_thread_class *klass= find_thread_class(key);
if (likely(klass != NULL))
{
pfs= create_thread(klass, identity, processlist_id);
if (pfs != NULL)
{
PFS_thread *parent= my_thread_get_THR_PFS();
if (parent != NULL)
pfs->m_parent_thread_internal_id= parent->m_parent_thread_internal_id;
}
}
else
pfs= NULL;

Expand Down
2 changes: 1 addition & 1 deletion storage/perfschema/pfs_instr.cc
Expand Up @@ -529,7 +529,7 @@ PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
PFS_atomic::add_u64(&thread_internal_id_counter.m_u64, 1);
pfs->m_parent_thread_internal_id= 0;
pfs->m_processlist_id= static_cast<ulong>(processlist_id);
pfs->m_thread_os_id= 0;
pfs->m_thread_os_id= my_thread_os_id();
pfs->m_event_id= 1;
pfs->m_stmt_lock.set_allocated();
pfs->m_session_lock.set_allocated();
Expand Down

0 comments on commit 7180afa

Please sign in to comment.