From: Marc Alff Date: May 4 2011 9:20pm Subject: bzr push into mysql-trunk-pfs-tuning branch (marc.alff:3371 to 3372) List-Archive: http://lists.mysql.com/commits/136695 Message-Id: <201105042120.p44LKAJe017896@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3372 Marc Alff 2011-05-04 PERFORMANCE SCHEMA performance optimizations Prototyping making static calls to the instrumentation, with PSI_CALL(). modified: include/my_global.h include/my_pthread.h include/my_sys.h include/mysql/psi/psi.h include/mysql/psi/psi_abi_v1.h.pp include/mysql/psi/psi_abi_v2.h.pp mysys/lf_alloc-pin.c sql/CMakeLists.txt sql/mysqld.cc storage/innobase/CMakeLists.txt storage/perfschema/pfs.cc storage/perfschema/pfs_instr_class.cc storage/perfschema/pfs_server.cc 3371 Marc Alff 2011-05-04 Code cleanup, fixed the build without P_S modified: include/my_global.h include/mysql/psi/mysql_thread.h include/mysql/psi/psi.h mysys/psi_noop.cc sql/CMakeLists.txt storage/perfschema/pfs_api.h === modified file 'include/my_global.h' --- a/include/my_global.h 2011-05-04 17:55:09 +0000 +++ b/include/my_global.h 2011-05-04 21:19:21 +0000 @@ -1488,13 +1488,4 @@ enum loglevel { INFORMATION_LEVEL= 2 }; -#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE - -/* EXPERIMENTAL, DO NOT USE */ -/* #define USE_PSI_V1 */ -/* #define PSI_CALL(API) pfs_ ## API ## _v1 */ -/* #include <../storage/perfschema/pfs_api.h> */ - -#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ - #endif /* my_global_h */ === modified file 'include/my_pthread.h' --- a/include/my_pthread.h 2011-03-08 19:14:42 +0000 +++ b/include/my_pthread.h 2011-05-04 21:19:21 +0000 @@ -818,6 +818,7 @@ extern int pthread_dummy(int); #endif #endif +#include #include #define INSTRUMENT_ME 0 === modified file 'include/my_sys.h' --- a/include/my_sys.h 2011-05-04 11:13:49 +0000 +++ b/include/my_sys.h 2011-05-04 21:19:21 +0000 @@ -955,6 +955,7 @@ void my_win_console_vfprintf(const CHARS int my_win_translate_command_line_args(const CHARSET_INFO *cs, int *ac, char ***av); #endif /* __WIN__ */ +#include #include #ifdef HAVE_PSI_INTERFACE === modified file 'include/mysql/psi/psi.h' --- a/include/mysql/psi/psi.h 2011-05-04 17:55:09 +0000 +++ b/include/mysql/psi/psi.h 2011-05-04 21:19:21 +0000 @@ -1966,8 +1966,7 @@ typedef struct PSI_stage_info_none PSI_s #endif /* HAVE_PSI_INTERFACE */ #ifndef PSI_CALL -extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; -#define PSI_CALL(API) PSI_server->API +#error "Someone should define PSI_CALL." #endif /** @} */ === modified file 'include/mysql/psi/psi_abi_v1.h.pp' --- a/include/mysql/psi/psi_abi_v1.h.pp 2011-02-14 14:23:55 +0000 +++ b/include/mysql/psi/psi_abi_v1.h.pp 2011-05-04 21:19:21 +0000 @@ -483,5 +483,4 @@ typedef struct PSI_cond_locker_state_v1 typedef struct PSI_file_locker_state_v1 PSI_file_locker_state; typedef struct PSI_table_locker_state_v1 PSI_table_locker_state; typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state; -extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; C_MODE_END === modified file 'include/mysql/psi/psi_abi_v2.h.pp' --- a/include/mysql/psi/psi_abi_v2.h.pp 2011-04-18 23:05:27 +0000 +++ b/include/mysql/psi/psi_abi_v2.h.pp 2011-05-04 21:19:21 +0000 @@ -144,5 +144,4 @@ typedef struct PSI_cond_locker_state_v2 typedef struct PSI_file_locker_state_v2 PSI_file_locker_state; typedef struct PSI_table_locker_state_v2 PSI_table_locker_state; typedef struct PSI_statement_locker_state_v2 PSI_statement_locker_state; -extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; C_MODE_END === modified file 'mysys/lf_alloc-pin.c' --- a/mysys/lf_alloc-pin.c 2010-07-23 20:59:42 +0000 +++ b/mysys/lf_alloc-pin.c 2011-05-04 21:19:21 +0000 @@ -146,6 +146,7 @@ void lf_pinbox_destroy(LF_PINBOX *pinbox */ LF_PINS *_lf_pinbox_get_pins(LF_PINBOX *pinbox) { + struct st_my_thread_var *var; uint32 pins, next, top_ver; LF_PINS *el; /* @@ -188,7 +189,12 @@ LF_PINS *_lf_pinbox_get_pins(LF_PINBOX * el->link= pins; el->purgatory_count= 0; el->pinbox= pinbox; - el->stack_ends_here= & my_thread_var->stack_ends_here; + var= my_thread_var; + /* + Threads that do not call my_thread_init() should still be + able to use the LF_HASH. + */ + el->stack_ends_here= (var ? & var->stack_ends_here : NULL); return el; } @@ -327,34 +333,37 @@ static int match_pins(LF_PINS *el, void */ static void _lf_pinbox_real_free(LF_PINS *pins) { - int npins, alloca_size; - void *list, **addr; + int npins; + void *list; + void **addr= NULL; void *first= NULL, *last= NULL; LF_PINBOX *pinbox= pins->pinbox; npins= pinbox->pins_in_array+1; #ifdef HAVE_ALLOCA - alloca_size= sizeof(void *)*LF_PINBOX_PINS*npins; - /* create a sorted list of pinned addresses, to speed up searches */ - if (available_stack_size(&pinbox, *pins->stack_ends_here) > alloca_size) + if (pins->stack_ends_here != NULL) { - struct st_harvester hv; - addr= (void **) alloca(alloca_size); - hv.granary= addr; - hv.npins= npins; - /* scan the dynarray and accumulate all pinned addresses */ - _lf_dynarray_iterate(&pinbox->pinarray, - (lf_dynarray_func)harvest_pins, &hv); - - npins= hv.granary-addr; - /* and sort them */ - if (npins) - qsort(addr, npins, sizeof(void *), (qsort_cmp)ptr_cmp); + int alloca_size; + alloca_size= sizeof(void *)*LF_PINBOX_PINS*npins; + /* create a sorted list of pinned addresses, to speed up searches */ + if (available_stack_size(&pinbox, *pins->stack_ends_here) > alloca_size) + { + struct st_harvester hv; + addr= (void **) alloca(alloca_size); + hv.granary= addr; + hv.npins= npins; + /* scan the dynarray and accumulate all pinned addresses */ + _lf_dynarray_iterate(&pinbox->pinarray, + (lf_dynarray_func)harvest_pins, &hv); + + npins= hv.granary-addr; + /* and sort them */ + if (npins) + qsort(addr, npins, sizeof(void *), (qsort_cmp)ptr_cmp); + } } - else #endif - addr= 0; list= pins->purgatory; pins->purgatory= 0; === modified file 'sql/CMakeLists.txt' --- a/sql/CMakeLists.txt 2011-05-04 17:55:09 +0000 +++ b/sql/CMakeLists.txt 2011-05-04 21:19:21 +0000 @@ -32,6 +32,7 @@ SET(GEN_SOURCES SET_SOURCE_FILES_PROPERTIES(${GEN_SOURCES} PROPERTIES GENERATED 1) ADD_DEFINITIONS(-DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER) +ADD_DEFINITIONS(-DWANT_STATIC_PSI_CALL) IF(SSL_DEFINES) ADD_DEFINITIONS(${SSL_DEFINES}) ENDIF() @@ -309,7 +310,7 @@ ADD_CUSTOM_COMMAND( ) MYSQL_ADD_EXECUTABLE(mysql_tzinfo_to_sql tztime.cc) -SET_TARGET_PROPERTIES(mysql_tzinfo_to_sql PROPERTIES COMPILE_FLAGS "-DTZINFO2SQL") +SET_TARGET_PROPERTIES(mysql_tzinfo_to_sql PROPERTIES COMPILE_FLAGS "-DTZINFO2SQL -DDISABLE_PSI_FILE") TARGET_LINK_LIBRARIES(mysql_tzinfo_to_sql mysys) ADD_CUSTOM_TARGET( === modified file 'sql/mysqld.cc' --- a/sql/mysqld.cc 2011-05-04 11:13:49 +0000 +++ b/sql/mysqld.cc 2011-05-04 21:19:21 +0000 @@ -4526,6 +4526,25 @@ int win_main(int argc, char **argv) int mysqld_main(int argc, char **argv) #endif { + /* STATE 0: PSI_server points to the noop instrumentation. */ + +#ifdef LATER + /* STATE 1: Install a raw performance schema instrumentation. */ + +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + struct PSI_bootstrap *psi_hook= initialize_performance_schema_1(); + if (psi_hook) + { + PSI *psi_server= (PSI*) psi_hook->get_interface(PSI_CURRENT_VERSION); + if (likely(psi_server != NULL)) + { + PSI_hook= psi_hook; + set_psi_server(psi_server); + } + } +#endif +#endif + /* Perform basic thread library and malloc initialization, to be able to read defaults files and parse options. === modified file 'storage/innobase/CMakeLists.txt' --- a/storage/innobase/CMakeLists.txt 2011-04-18 02:17:16 +0000 +++ b/storage/innobase/CMakeLists.txt 2011-05-04 21:19:21 +0000 @@ -19,6 +19,9 @@ INCLUDE(CheckFunctionExists) INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceRuns) +# Built in performance schema instrumentation +ADD_DEFINITIONS("-DWANT_STATIC_PSI_CALL") + # OS tests IF(UNIX) IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") === modified file 'storage/perfschema/pfs.cc' --- a/storage/perfschema/pfs.cc 2011-05-04 11:13:49 +0000 +++ b/storage/perfschema/pfs.cc 2011-05-04 21:19:21 +0000 @@ -1000,6 +1000,14 @@ static inline int mysql_mutex_lock(...) pthread_key(PFS_thread*, THR_PFS); bool THR_PFS_initialized= false; +PFS_thread* get_pfs_thread() +{ + if (unlikely(! THR_PFS_initialized)) + return NULL; + PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + return pfs; +} + /** Conversion map from PSI_mutex_operation to enum_operation_type. Indexed by enum PSI_mutex_operation. @@ -1419,7 +1427,7 @@ pfs_get_table_share_v1(my_bool temporary if (! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled) return NULL; /* An instrumented thread is required, for LF_PINS. */ - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; PFS_table_share* pfs_share; @@ -1449,7 +1457,7 @@ void pfs_drop_table_share_v1(const char *schema_name, int schema_name_length, const char *table_name, int table_name_length) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return; /* TODO: temporary tables */ @@ -1469,7 +1477,7 @@ pfs_open_table_v1(PSI_table_share *share if (unlikely(pfs_table_share == NULL)) return NULL; - PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *thread= get_pfs_thread(); if (unlikely(thread == NULL)) return NULL; PFS_table *pfs_table= create_table(pfs_table_share, thread, identity); @@ -1509,7 +1517,7 @@ void pfs_create_file_v1(PSI_file_key key return; /* A thread is needed for LF_PINS */ - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return; @@ -1576,7 +1584,8 @@ void* pfs_spawn_thread(void *arg) { pfs= NULL; } - my_pthread_setspecific_ptr(THR_PFS, pfs); + if (THR_PFS_initialized) + my_pthread_setspecific_ptr(THR_PFS, pfs); /* Secondly, free the memory allocated in spawn_thread_v1(). @@ -1610,7 +1619,7 @@ int pfs_spawn_thread_v1(PSI_thread_key k if (unlikely(psi_arg == NULL)) return EAGAIN; - psi_arg->m_parent_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + psi_arg->m_parent_thread= get_pfs_thread(); psi_arg->m_child_key= key; psi_arg->m_child_identity= (arg ? arg : thread); psi_arg->m_user_start_routine= start_routine; @@ -1658,6 +1667,8 @@ void pfs_set_thread_id_v1(PSI_thread *th PSI_thread* pfs_get_thread_v1(void) { + if (unlikely(! THR_PFS_initialized)) + return NULL; PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); return reinterpret_cast (pfs); } @@ -1668,7 +1679,7 @@ pfs_get_thread_v1(void) */ void pfs_set_thread_user_v1(const char *user, int user_len) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); DBUG_ASSERT((user != NULL) || (user_len == 0)); DBUG_ASSERT(user_len >= 0); @@ -1715,7 +1726,7 @@ void pfs_set_thread_user_v1(const char * void pfs_set_thread_user_host_v1(const char *user, int user_len, const char *host, int host_len) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); DBUG_ASSERT((user != NULL) || (user_len == 0)); DBUG_ASSERT(user_len >= 0); @@ -1765,7 +1776,7 @@ void pfs_set_thread_user_host_v1(const c */ void pfs_set_thread_db_v1(const char* db, int db_len) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); DBUG_ASSERT((db != NULL) || (db_len == 0)); DBUG_ASSERT(db_len >= 0); @@ -1787,7 +1798,7 @@ void pfs_set_thread_db_v1(const char* db */ void pfs_set_thread_command_v1(int command) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); DBUG_ASSERT(command >= 0); DBUG_ASSERT(command <= (int) COM_END); @@ -1806,7 +1817,7 @@ void pfs_set_thread_command_v1(int comma */ void pfs_set_thread_start_time_v1(time_t start_time) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); if (likely(pfs != NULL)) { @@ -1822,7 +1833,7 @@ void pfs_set_thread_start_time_v1(time_t */ void pfs_set_thread_state_v1(const char* state) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); if (likely(pfs != NULL)) { @@ -1841,7 +1852,7 @@ void pfs_set_thread_state_v1(const char* */ void pfs_set_thread_info_v1(const char* info, int info_len) { - PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs= get_pfs_thread(); if (likely(pfs != NULL)) { @@ -1859,7 +1870,8 @@ void pfs_set_thread_info_v1(const char* void pfs_set_thread_v1(PSI_thread* thread) { PFS_thread *pfs= reinterpret_cast (thread); - my_pthread_setspecific_ptr(THR_PFS, pfs); + if (THR_PFS_initialized) + my_pthread_setspecific_ptr(THR_PFS, pfs); } /** @@ -1868,11 +1880,12 @@ void pfs_set_thread_v1(PSI_thread* threa */ void pfs_delete_current_thread_v1(void) { - PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *thread= get_pfs_thread(); if (thread != NULL) { aggregate_thread(thread); - my_pthread_setspecific_ptr(THR_PFS, NULL); + if (THR_PFS_initialized) + my_pthread_setspecific_ptr(THR_PFS, NULL); destroy_thread(thread); } } @@ -1921,7 +1934,7 @@ pfs_get_thread_mutex_locker_v1(PSI_mutex if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -2013,7 +2026,7 @@ pfs_get_thread_rwlock_locker_v1(PSI_rwlo if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -2122,7 +2135,7 @@ pfs_get_thread_cond_locker_v1(PSI_cond_l if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -2255,7 +2268,7 @@ pfs_get_thread_table_io_locker_v1(PSI_ta PFS_table_share *share= pfs_table->m_share; if (unlikely(setup_objects_version != share->m_setup_objects_version)) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; /* Refresh the enabled and timed flags from SETUP_OBJECTS */ @@ -2279,7 +2292,7 @@ pfs_get_thread_table_io_locker_v1(PSI_ta if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -2366,7 +2379,7 @@ pfs_get_thread_table_lock_locker_v1(PSI_ PFS_table_share *share= pfs_table->m_share; if (unlikely(setup_objects_version != share->m_setup_objects_version)) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; /* Refresh the enabled and timed flags from SETUP_OBJECTS */ @@ -2412,7 +2425,7 @@ pfs_get_thread_table_lock_locker_v1(PSI_ if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -2494,7 +2507,7 @@ pfs_get_thread_file_name_locker_v1(PSI_f return NULL; /* Needed for the LF_HASH */ - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; @@ -2579,7 +2592,7 @@ pfs_get_thread_file_stream_locker_v1(PSI if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -2683,7 +2696,7 @@ pfs_get_thread_file_descriptor_locker_v1 if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) @@ -3657,7 +3670,7 @@ void pfs_start_stage_v1(PSI_stage_key ke if (! flag_global_instrumentation) return; - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return; @@ -3750,7 +3763,7 @@ void pfs_end_stage_v1() if (! flag_global_instrumentation) return; - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return; @@ -3818,7 +3831,7 @@ pfs_get_thread_statement_locker_v1(PSI_s if (flag_thread_instrumentation) { - PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + PFS_thread *pfs_thread= get_pfs_thread(); if (unlikely(pfs_thread == NULL)) return NULL; if (! pfs_thread->m_enabled) === modified file 'storage/perfschema/pfs_instr_class.cc' --- a/storage/perfschema/pfs_instr_class.cc 2011-05-04 11:13:49 +0000 +++ b/storage/perfschema/pfs_instr_class.cc 2011-05-04 21:19:21 +0000 @@ -170,14 +170,14 @@ void init_event_name_sizing(const PFS_gl memcpy(global_table_io_class.m_name, "wait/io/table/sql/handler", 25); global_table_io_class.m_name_length= 25; global_table_io_class.m_flags= 0; - global_table_io_class.m_enabled= true; + global_table_io_class.m_enabled= false; global_table_io_class.m_timed= true; global_table_io_class.m_event_name_index= table_class_start; memcpy(global_table_lock_class.m_name, "wait/lock/table/sql/handler", 27); global_table_lock_class.m_name_length= 27; global_table_lock_class.m_flags= 0; - global_table_lock_class.m_enabled= true; + global_table_lock_class.m_enabled= false; global_table_lock_class.m_timed= true; global_table_lock_class.m_event_name_index= table_class_start + 1; } === modified file 'storage/perfschema/pfs_server.cc' --- a/storage/perfschema/pfs_server.cc 2011-05-04 11:13:49 +0000 +++ b/storage/perfschema/pfs_server.cc 2011-05-04 21:19:21 +0000 @@ -108,6 +108,8 @@ initialize_performance_schema(const PFS_ flag_events_statements_current= true; flag_events_statements_history= true; flag_events_statements_history_long= true; + global_table_io_class.m_enabled= true; + global_table_lock_class.m_enabled= true; install_default_setup(&PFS_bootstrap); return &PFS_bootstrap; No bundle (reason: useless for push emails).