List:Commits« Previous MessageNext Message »
From:Marc Alff Date:November 1 2008 1:05am
Subject:bzr commit into mysql-6.0-perf branch (marc.alff:2723)
View as plain text  
#At file:///home/malff/BZR-TREE/mysql-6.0-perf/

 2723 Marc Alff	2008-10-31
      Instrumentation, continued
modified:
  include/mysql/mysql_mutex.h
  include/mysql/psi.h
  include/mysql/psi_abi_v1.h.pp
  mysql-test/suite/perfschema/t/schema.test
  storage/perfschema/pse_metadata.cc
  storage/perfschema/pse_metadata.h
  storage/perfschema/psm.cc
  storage/perfschema/psm_bootstrap.cc
  storage/perfschema/psm_global.cc
  storage/perfschema/psm_global.h
  storage/perfschema/psm_sync.cc

=== modified file 'include/mysql/mysql_mutex.h'
--- a/include/mysql/mysql_mutex.h	2008-10-31 02:26:32 +0000
+++ b/include/mysql/mysql_mutex.h	2008-11-01 01:05:08 +0000
@@ -335,7 +335,7 @@ static inline int mysql_mutex_lock(
 #endif
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_wait(locker, that->m_psi, 1, result);
+    PSI_server->end_wait(locker, that->m_psi, result);
 #endif
   return result;
 }
@@ -428,7 +428,7 @@ static inline int mysql_rwlock_rdlock(
   result= rw_rdlock(& that->m_rwlock);
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_rdwait(locker, that->m_psi, 1, result);
+    PSI_server->end_rdwait(locker, that->m_psi, result);
 #endif
   return result;
 }
@@ -446,7 +446,7 @@ static inline int mysql_rwlock_wrlock(
   result= rw_rdlock(& that->m_rwlock);
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_wrwait(locker, that->m_psi, 1, result);
+    PSI_server->end_wrwait(locker, that->m_psi, result);
 #endif
   return result;
 }
@@ -464,7 +464,7 @@ static inline int mysql_rwlock_tryrdlock
   result= rw_rdlock(& that->m_rwlock);
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_rdwait(locker, that->m_psi, 0, result);
+    PSI_server->end_rdwait(locker, that->m_psi, result);
 #endif
   return result;
 }
@@ -482,7 +482,7 @@ static inline int mysql_rwlock_trywrlock
   result= rw_rdlock(& that->m_rwlock);
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_wrwait(locker, that->m_psi, 0, result);
+    PSI_server->end_wrwait(locker, that->m_psi, result);
 #endif
   return result;
 }
@@ -558,14 +558,14 @@ static inline int mysql_cond_wait(
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_locker *locker= NULL;
-  if (PSI_server)
+  if (PSI_server && that->m_psi)
     if ((locker= PSI_server->get_thread_locker()))
       PSI_server->start_condwait(locker, that->m_psi, 1);
 #endif
   result= pthread_cond_wait(& that->m_cond, & mutex->m_mutex);
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_condwait(locker, that->m_psi, 1, result);
+    PSI_server->end_condwait(locker, that->m_psi, result);
 #endif
   return result;
 }
@@ -585,7 +585,7 @@ static inline int mysql_cond_timedwait(
   result= pthread_cond_timedwait(& that->m_cond, & mutex->m_mutex, abstime);
 #ifdef HAVE_PSI_INTERFACE
   if (locker)
-    PSI_server->end_condwait(locker, that->m_psi, 0, result);
+    PSI_server->end_condwait(locker, that->m_psi, result);
 #endif
   return result;
 }

=== modified file 'include/mysql/psi.h'
--- a/include/mysql/psi.h	2008-10-31 02:26:32 +0000
+++ b/include/mysql/psi.h	2008-11-01 01:05:08 +0000
@@ -403,7 +403,6 @@ struct PSI_v1
   */
   void (*end_wait)(struct PSI_locker *locker,
                    struct PSI_mutex *mutex,
-                   int must,
                    int rc);
 
   /**
@@ -424,7 +423,6 @@ struct PSI_v1
   */
   void (*end_rdwait)(struct PSI_locker *locker,
                      struct PSI_rwlock *rwlock,
-                     int must,
                      int rc);
 
   /**
@@ -445,7 +443,6 @@ struct PSI_v1
   */
   void (*end_wrwait)(struct PSI_locker *locker,
                      struct PSI_rwlock *rwlock,
-                     int must,
                      int rc);
 
   /**
@@ -466,7 +463,6 @@ struct PSI_v1
   */
   void (*end_condwait)(struct PSI_locker *locker,
                        struct PSI_cond *cond,
-                       int must,
                        int rc);
 };
 

=== modified file 'include/mysql/psi_abi_v1.h.pp'
--- a/include/mysql/psi_abi_v1.h.pp	2008-10-23 18:22:09 +0000
+++ b/include/mysql/psi_abi_v1.h.pp	2008-11-01 01:05:08 +0000
@@ -68,28 +68,24 @@ struct PSI_v1
                      int must);
   void (*end_wait)(struct PSI_locker *locker,
                    struct PSI_mutex *mutex,
-                   int must,
                    int rc);
   void (*start_rdwait)(struct PSI_locker *locker,
                        struct PSI_rwlock *rwlock,
                        int must);
   void (*end_rdwait)(struct PSI_locker *locker,
                      struct PSI_rwlock *rwlock,
-                     int must,
                      int rc);
   void (*start_wrwait)(struct PSI_locker *locker,
                        struct PSI_rwlock *rwlock,
                        int must);
   void (*end_wrwait)(struct PSI_locker *locker,
                      struct PSI_rwlock *rwlock,
-                     int must,
                      int rc);
   void (*start_condwait)(struct PSI_locker *locker,
                          struct PSI_cond *cond,
                          int must);
   void (*end_condwait)(struct PSI_locker *locker,
                        struct PSI_cond *cond,
-                       int must,
                        int rc);
 };
 typedef struct PSI_v1 PSI;

=== modified file 'mysql-test/suite/perfschema/t/schema.test'
--- a/mysql-test/suite/perfschema/t/schema.test	2008-10-30 00:41:16 +0000
+++ b/mysql-test/suite/perfschema/t/schema.test	2008-11-01 01:05:08 +0000
@@ -8,6 +8,6 @@ show tables;
 show create table performance_schema.setup_actors;
 show create table performance_schema.setup_instruments;
 show create table performance_schema.setup_consumers;
-show create table performance_schema.setup_timer;
-show create table performance_schema.performance_timer;
+show create table performance_schema.setup_timers;
+show create table performance_schema.performance_timers;
 

=== modified file 'storage/perfschema/pse_metadata.cc'
--- a/storage/perfschema/pse_metadata.cc	2008-10-30 04:49:42 +0000
+++ b/storage/perfschema/pse_metadata.cc	2008-11-01 01:05:08 +0000
@@ -36,11 +36,11 @@ LEX_STRING SETUP_INSTRUMENTS_str=
 LEX_STRING SETUP_CONSUMERS_str=
 { C_STRING_WITH_LEN("setup_consumers") };
 
-LEX_STRING SETUP_TIMER_str=
-{ C_STRING_WITH_LEN("setup_timer") };
+LEX_STRING SETUP_TIMERS_str=
+{ C_STRING_WITH_LEN("setup_timers") };
 
-LEX_STRING PERFORMANCE_TIMER_str=
-{ C_STRING_WITH_LEN("performance_timer") };
+LEX_STRING PERFORMANCE_TIMERS_str=
+{ C_STRING_WITH_LEN("performance_timers") };
 
 LEX_STRING SESSION_WAITS_str=
 { C_STRING_WITH_LEN("session_waits") };
@@ -72,13 +72,13 @@ pse_table_metadata pse_all_tables[]=
     HA_POS_ERROR
   },
   {
-    SETUP_TIMER_str.str,
+    SETUP_TIMERS_str.str,
     NULL,
     NULL,
     HA_POS_ERROR
   },
   {
-    PERFORMANCE_TIMER_str.str,
+    PERFORMANCE_TIMERS_str.str,
     NULL,
     NULL,
     HA_POS_ERROR

=== modified file 'storage/perfschema/pse_metadata.h'
--- a/storage/perfschema/pse_metadata.h	2008-10-30 00:41:16 +0000
+++ b/storage/perfschema/pse_metadata.h	2008-11-01 01:05:08 +0000
@@ -54,8 +54,8 @@ extern LEX_STRING PERFORMANCE_SCHEMA_str
 extern LEX_STRING SETUP_ACTORS_str;
 extern LEX_STRING SETUP_INSTRUMENTS_str;
 extern LEX_STRING SETUP_CONSUMERS_str;
-extern LEX_STRING SETUP_TIMER_str;
-extern LEX_STRING PERFORMANCE_TIMER_str;
+extern LEX_STRING SETUP_TIMERS_str;
+extern LEX_STRING PERFORMANCE_TIMERS_str;
 extern LEX_STRING SESSION_WAITS_str;
 extern LEX_STRING SESSION_WAIT_HISTORIES_str;
 extern LEX_STRING SESSION_WAIT_LONG_HISTORIES_str;

=== modified file 'storage/perfschema/psm.cc'
--- a/storage/perfschema/psm.cc	2008-10-30 04:49:42 +0000
+++ b/storage/perfschema/psm.cc	2008-11-01 01:05:08 +0000
@@ -188,9 +188,15 @@ static void delete_thread_v1(PSI_thread 
 
 static PSI_locker* get_thread_locker_v1()
 {
-  PSM_locker dummy;
-  PSM_locker *psm= & dummy;
-  return (PSI_locker*) psm;
+  PSM_thread *psm;
+  psm= my_pthread_getspecific_ptr(PSM_thread*, THR_PSM);
+  if (psm)
+  {
+    PSM_locker dummy;
+    PSM_locker *psm= & dummy;
+    return (PSI_locker*) psm;
+  }
+  return NULL;
 }
 
 static PSI_locker* get_locker_v1(PSI_thread *thread)
@@ -202,50 +208,113 @@ static PSI_locker* get_locker_v1(PSI_thr
 
 static void unlock_mutex_v1(PSI_thread *thread, PSI_mutex* mutex)
 {
+  PSM_thread *psm_thread= (PSM_thread*) thread;
+  PSM_mutex *psm_mutex= (PSM_mutex*) mutex;
+  DBUG_ASSERT(psm_thread != NULL);
+  DBUG_ASSERT(psm_mutex != NULL);
+  psm_mutex->m_stat.m_unlock_count++;
+  psm_mutex->m_owner= NULL;
 }
 
 static void unlock_rwlock_v1(PSI_thread *thread, PSI_rwlock* rwlock)
 {
+  PSM_thread *psm_thread= (PSM_thread*) thread;
+  PSM_rwlock *psm_rwlock= (PSM_rwlock*) rwlock;
+  DBUG_ASSERT(psm_thread != NULL);
+  DBUG_ASSERT(psm_rwlock != NULL);
+  psm_rwlock->m_stat.m_unlock_count++;
+  if (psm_rwlock->m_writer == psm_thread)
+    psm_rwlock->m_writer= NULL;
 }
 
 static void signal_cond_v1(PSI_thread *thread, PSI_cond* cond)
 {
+  PSM_thread *psm_thread= (PSM_thread*) thread;
+  PSM_cond *psm_cond= (PSM_cond*) cond;
+  DBUG_ASSERT(psm_thread != NULL);
+  DBUG_ASSERT(psm_cond != NULL);
+  psm_cond->m_stat.m_signal_count++;
 }
 
 static void broadcast_cond_v1(PSI_thread *thread, PSI_cond* cond)
 {
+  PSM_thread *psm_thread= (PSM_thread*) thread;
+  PSM_cond *psm_cond= (PSM_cond*) cond;
+  DBUG_ASSERT(psm_thread != NULL);
+  DBUG_ASSERT(psm_cond != NULL);
+  psm_cond->m_stat.m_broadcast_count++;
 }
 
 static void start_wait_v1(PSI_locker* locker, PSI_mutex* mutex, int must)
 {
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_mutex *psm_mutex= (PSM_mutex*) mutex;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_mutex != NULL);
 }
 
-static void end_wait_v1(PSI_locker* locker, PSI_mutex* mutex, int must, int rc)
-{
+static void end_wait_v1(PSI_locker* locker, PSI_mutex* mutex, int rc)
+{
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_mutex *psm_mutex= (PSM_mutex*) mutex;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_mutex != NULL);
+  if (rc == 0)
+    psm_mutex->m_stat.m_lock_count++;
 }
 
 static void start_rdwait_v1(PSI_locker* locker, PSI_rwlock *rwlock, int must)
 {
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_rwlock *psm_rwlock= (PSM_rwlock*) rwlock;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_rwlock != NULL);
 }
 
-static void end_rdwait_v1(PSI_locker* locker, PSI_rwlock *rwlock, int must, int rc)
-{
+static void end_rdwait_v1(PSI_locker* locker, PSI_rwlock *rwlock, int rc)
+{
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_rwlock *psm_rwlock= (PSM_rwlock*) rwlock;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_rwlock != NULL);
+  if (rc == 0)
+    psm_rwlock->m_stat.m_read_count++;
 }
 
 static void start_wrwait_v1(PSI_locker* locker, PSI_rwlock *rwlock, int must)
 {
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_rwlock *psm_rwlock= (PSM_rwlock*) rwlock;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_rwlock != NULL);
 }
 
-static void end_wrwait_v1(PSI_locker* locker, PSI_rwlock *rwlock, int must, int rc)
-{
+static void end_wrwait_v1(PSI_locker* locker, PSI_rwlock *rwlock, int rc)
+{
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_rwlock *psm_rwlock= (PSM_rwlock*) rwlock;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_rwlock != NULL);
+  if (rc == 0)
+    psm_rwlock->m_stat.m_write_count++;
 }
 
 static void start_condwait_v1(PSI_locker* locker, PSI_cond* cond, int must)
 {
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_cond *psm_cond= (PSM_cond*) cond;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_cond != NULL);
 }
 
-static void end_condwait_v1(PSI_locker* locker, PSI_cond* cond, int must, int rc)
-{
+static void end_condwait_v1(PSI_locker* locker, PSI_cond* cond, int rc)
+{
+  PSM_locker *psm_locker= (PSM_locker*) locker;
+  PSM_cond *psm_cond= (PSM_cond*) cond;
+  DBUG_ASSERT(psm_locker != NULL);
+  DBUG_ASSERT(psm_cond != NULL);
+  if (rc == 0)
+    psm_cond->m_stat.m_wait_count++;
 }
 
 struct PSI_v1 PSM_v1=

=== modified file 'storage/perfschema/psm_bootstrap.cc'
--- a/storage/perfschema/psm_bootstrap.cc	2008-10-30 00:41:16 +0000
+++ b/storage/perfschema/psm_bootstrap.cc	2008-11-01 01:05:08 +0000
@@ -43,22 +43,22 @@ const char* psm_bootstrap_queries[]=
     "NUMBER_OF_ROWS_FILLED INTEGER UNSIGNED"
   ") ENGINE=PERFORMANCE_SCHEMA;"
   ,
-  "DROP TABLE IF EXISTS performance_schema.setup_timer;"
+  "DROP TABLE IF EXISTS performance_schema.setup_timers;"
   ,
-  "CREATE TABLE performance_schema.setup_timer("
+  "CREATE TABLE performance_schema.setup_timers("
     "NAME VARCHAR(64) character set utf8 collate utf8_unicode_ci not null, "
     "TIMER_NAME ENUM ('CYCLE', 'NANOSECOND', 'MICROSECOND', "
                      "'MILLISECOND', 'TICK') not null"
   ") ENGINE=PERFORMANCE_SCHEMA;"
   ,
-  "DROP TABLE IF EXISTS performance_schema.performance_timer;"
+  "DROP TABLE IF EXISTS performance_schema.performance_timers;"
   ,
-  "CREATE TABLE performance_schema.performance_timer("
+  "CREATE TABLE performance_schema.performance_timers("
     "TIMER_NAME ENUM ('CYCLE', 'NANOSECOND', 'MICROSECOND', "
                      "'MILLISECOND', 'TICK') not null, "
-    "TIMER_FREQUENCY BIGINT, "
-    "TIMER_RESOLUTION BIGINT, "
-    "TIMER_OVERHEAD BIGINT"
+    "TIMER_FREQUENCY BIGINT not null, "
+    "TIMER_INTERVAL BIGINT not null, "
+    "TIMER_OVERHEAD BIGINT not null"
   ") ENGINE=PERFORMANCE_SCHEMA;"
   ,
   0

=== modified file 'storage/perfschema/psm_global.cc'
--- a/storage/perfschema/psm_global.cc	2008-10-30 00:41:16 +0000
+++ b/storage/perfschema/psm_global.cc	2008-11-01 01:05:08 +0000
@@ -43,3 +43,20 @@ void psm_free(void *ptr)
     free(ptr);
 }
 
+uint randomized_index(void *ptr, uint max_size)
+{
+  ulonglong index;
+
+  /*
+    ptr is typically an aligned structure,
+    so the last bits are not really random, but this has no effect.
+    Apply a linear (A*x + B) function to spread
+    close values of ptr further apart (which helps with arrays),
+    and to spread values way beyond a typical max_size.
+    Then, apply a modulo to end within [0, max_size-1].
+    A and B are big prime numbers, to avoid resonating with max_size.
+  */
+  index= (((intptr) ptr) * 121001 + 46279);
+  return (uint) index % max_size;
+}
+

=== modified file 'storage/perfschema/psm_global.h'
--- a/storage/perfschema/psm_global.h	2008-10-30 00:41:16 +0000
+++ b/storage/perfschema/psm_global.h	2008-11-01 01:05:08 +0000
@@ -22,5 +22,7 @@ void *psm_malloc(size_t size, myf flags)
 #define PSM_MALLOC_ARRAY(n,T,f) (T*) psm_malloc((n) * sizeof(T), (f))
 void psm_free(void *ptr);
 
+uint randomized_index(void *ptr, uint max_size);
+
 #endif
 

=== modified file 'storage/perfschema/psm_sync.cc'
--- a/storage/perfschema/psm_sync.cc	2008-10-30 00:41:16 +0000
+++ b/storage/perfschema/psm_sync.cc	2008-11-01 01:05:08 +0000
@@ -57,6 +57,33 @@ void cleanup_sync()
 
 PSM_mutex* create_mutex(PSM_sync_info *info, void *identity)
 {
+  int pass;
+  PSM_mutex *psm;
+  uint i= randomized_index(identity, mutex_max);
+
+  /*
+    Pass 1: [random, mutex_max-1]
+    Pass 2: [0, mutex_max-1]
+  */
+  for (pass= 1; pass <= 2; i=0, pass++)
+  {
+    for ( ; i < mutex_max; i++)
+    {
+      psm= & mutex_array[i];
+      if (! psm->m_allocated)
+      {
+        // TODO: atomic here
+        psm->m_allocated= true;
+        psm->m_identity= identity;
+        psm->m_info= info;
+        psm->m_stat.m_lock_count= 0;
+        psm->m_stat.m_unlock_count= 0;
+        psm->m_owner= NULL;
+        return psm;
+      }
+    }
+  }
+
   mutex_lost++;
   return NULL;
 }
@@ -64,10 +91,39 @@ PSM_mutex* create_mutex(PSM_sync_info *i
 void destroy_mutex(PSM_mutex *psm)
 {
   DBUG_ASSERT(psm != NULL);
+  psm->m_allocated= false;
 }
 
 PSM_rwlock* create_rwlock(PSM_sync_info *info, void *identity)
 {
+  int pass;
+  PSM_rwlock *psm;
+  uint i= randomized_index(identity, rwlock_max);
+
+  /*
+    Pass 1: [random, rwlock_max-1]
+    Pass 2: [0, rwlock_max-1]
+  */
+  for (pass= 1; pass <= 2; i=0, pass++)
+  {
+    for ( ; i < rwlock_max; i++)
+    {
+      psm= & rwlock_array[i];
+      if (! psm->m_allocated)
+      {
+        // TODO: atomic here
+        psm->m_allocated= true;
+        psm->m_identity= identity;
+        psm->m_info= info;
+        psm->m_stat.m_read_count= 0;
+        psm->m_stat.m_write_count= 0;
+        psm->m_stat.m_unlock_count= 0;
+        psm->m_writer= NULL;
+        return psm;
+      }
+    }
+  }
+
   rwlock_lost++;
   return NULL;
 }
@@ -75,10 +131,38 @@ PSM_rwlock* create_rwlock(PSM_sync_info 
 void destroy_rwlock(PSM_rwlock *psm)
 {
   DBUG_ASSERT(psm != NULL);
+  psm->m_allocated= false;
 }
 
 PSM_cond* create_cond(PSM_sync_info *info, void *identity)
 {
+  int pass;
+  PSM_cond *psm;
+  uint i= randomized_index(identity, cond_max);
+
+  /*
+    Pass 1: [random, cond_max-1]
+    Pass 2: [0  cond_max-1]
+  */
+  for (pass= 1; pass <= 2; i=0, pass++)
+  {
+    for ( ; i < cond_max; i++)
+    {
+      psm= & cond_array[i];
+      if (! psm->m_allocated)
+      {
+        // TODO: atomic here
+        psm->m_allocated= true;
+        psm->m_identity= identity;
+        psm->m_info= info;
+        psm->m_stat.m_wait_count= 0;
+        psm->m_stat.m_signal_count= 0;
+        psm->m_stat.m_broadcast_count= 0;
+        return psm;
+      }
+    }
+  }
+
   cond_lost++;
   return NULL;
 }
@@ -86,5 +170,6 @@ PSM_cond* create_cond(PSM_sync_info *inf
 void destroy_cond(PSM_cond *psm)
 {
   DBUG_ASSERT(psm != NULL);
+  psm->m_allocated= false;
 }
 

Thread
bzr commit into mysql-6.0-perf branch (marc.alff:2723) Marc Alff1 Nov