[Commits] cfc135b: MDEV-8111 - remove "fast mutexes"

Sergey Vojtovich svoj at mariadb.org
Thu Nov 19 14:55:15 EET 2015


revision-id: cfc135b645db5fa78b9f63b1959ea3f2be137a26 (mariadb-10.1.8-57-gcfc135b)
parent(s): 232d9c1e5325d04f8c71095b5bf2d570de86939b
committer: Sergey Vojtovich
timestamp: 2015-11-19 16:54:45 +0400
message:

MDEV-8111 - remove "fast mutexes"

They aren't faster than normal mutexes. They're disabled by default for years,
so de facto it's dead code, never used.

---
 CMakeLists.txt                     |  7 ----
 include/my_pthread.h               | 20 ---------
 include/mysql/psi/mysql_thread.h   | 16 -------
 mysys/thr_mutex.c                  | 86 --------------------------------------
 plugin/server_audit/server_audit.c |  2 -
 5 files changed, 131 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 728cc62..994fd58 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -236,9 +236,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG(-ggdb3 DEBUG)
 OPTION(ENABLED_LOCAL_INFILE
  "If we should should enable LOAD DATA LOCAL by default" ${IF_WIN})
 
-OPTION(WITH_FAST_MUTEXES "Compile with fast mutexes" OFF)
-MARK_AS_ADVANCED(WITH_FAST_MUTEXES)
-
 OPTION(WITH_INNODB_DISALLOW_WRITES "InnoDB freeze writes patch from Google" ${WITH_WSREP})
 IF (WITH_INNODB_DISALLOW_WRITES)
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_INNODB_DISALLOW_WRITES")
@@ -253,10 +250,6 @@ FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
       SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE} 
        "${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF")
     ENDIF()
-    IF(WITH_FAST_MUTEXES)
-      SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE} 
-        "${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DMY_PTHREAD_FASTMUTEX=1")
-    ENDIF()
   ENDFOREACH()
 ENDFOREACH()
 
diff --git a/include/my_pthread.h b/include/my_pthread.h
index 1b7d289..7596ae0 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -443,30 +443,10 @@ void safe_mutex_free_deadlock_data(safe_mutex_t *mp);
 #define safe_mutex_assert_not_owner(mp) do {} while (0)
 #define safe_mutex_setflags(mp, F) do {} while (0)
 
-#if defined(MY_PTHREAD_FASTMUTEX)
-#define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A), &(B)->mutex, (C))
-#define my_cond_wait(A,B) pthread_cond_wait((A), &(B)->mutex)
-#else
 #define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A),(B),(C))
 #define my_cond_wait(A,B) pthread_cond_wait((A), (B))
-#endif /* MY_PTHREAD_FASTMUTEX */
 #endif /* !SAFE_MUTEX */
 
-#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
-typedef struct st_my_pthread_fastmutex_t
-{
-  pthread_mutex_t mutex;
-  uint spins;
-  uint rng_state;
-} my_pthread_fastmutex_t;
-void fastmutex_global_init(void);
-
-int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp, 
-                              const pthread_mutexattr_t *attr);
-int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp);
-
-#endif /* defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */
-
 	/* READ-WRITE thread locking */
 
 #if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS)
diff --git a/include/mysql/psi/mysql_thread.h b/include/mysql/psi/mysql_thread.h
index 08dfeac..0afbe60 100644
--- a/include/mysql/psi/mysql_thread.h
+++ b/include/mysql/psi/mysql_thread.h
@@ -71,8 +71,6 @@ struct st_mysql_mutex
   /** The real mutex. */
 #ifdef SAFE_MUTEX
   safe_mutex_t m_mutex;
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  my_pthread_fastmutex_t m_mutex;
 #else
   pthread_mutex_t m_mutex;
 #endif
@@ -619,8 +617,6 @@ static inline int inline_mysql_mutex_init(
 #endif
 #ifdef SAFE_MUTEX
   return safe_mutex_init(&that->m_mutex, attr, src_name, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  return my_pthread_fastmutex_init(&that->m_mutex, attr);
 #else
   return pthread_mutex_init(&that->m_mutex, attr);
 #endif
@@ -642,8 +638,6 @@ static inline int inline_mysql_mutex_destroy(
 #endif
 #ifdef SAFE_MUTEX
   return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  return pthread_mutex_destroy(&that->m_mutex.mutex);
 #else
   return pthread_mutex_destroy(&that->m_mutex);
 #endif
@@ -670,8 +664,6 @@ static inline int inline_mysql_mutex_lock(
     /* Instrumented code */
 #ifdef SAFE_MUTEX
     result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-    result= my_pthread_fastmutex_lock(&that->m_mutex);
 #else
     result= pthread_mutex_lock(&that->m_mutex);
 #endif
@@ -687,8 +679,6 @@ static inline int inline_mysql_mutex_lock(
   /* Non instrumented code */
 #ifdef SAFE_MUTEX
   result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  result= my_pthread_fastmutex_lock(&that->m_mutex);
 #else
   result= pthread_mutex_lock(&that->m_mutex);
 #endif
@@ -717,8 +707,6 @@ static inline int inline_mysql_mutex_trylock(
     /* Instrumented code */
 #ifdef SAFE_MUTEX
     result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-    result= pthread_mutex_trylock(&that->m_mutex.mutex);
 #else
     result= pthread_mutex_trylock(&that->m_mutex);
 #endif
@@ -734,8 +722,6 @@ static inline int inline_mysql_mutex_trylock(
   /* Non instrumented code */
 #ifdef SAFE_MUTEX
   result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  result= pthread_mutex_trylock(&that->m_mutex.mutex);
 #else
   result= pthread_mutex_trylock(&that->m_mutex);
 #endif
@@ -759,8 +745,6 @@ static inline int inline_mysql_mutex_unlock(
 
 #ifdef SAFE_MUTEX
   result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  result= pthread_mutex_unlock(&that->m_mutex.mutex);
 #else
   result= pthread_mutex_unlock(&that->m_mutex);
 #endif
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 18af5f4..4d6abd4 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -105,8 +105,6 @@ void my_mutex_init()
 
 #if defined(SAFE_MUTEX_DEFINED)
   safe_mutex_global_init();
-#elif defined(MY_PTHREAD_FASTMUTEX)
-  fastmutex_global_init();
 #endif
 }
 
@@ -838,88 +836,4 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex,
   DBUG_VOID_RETURN;
 }
 
-#elif defined(MY_PTHREAD_FASTMUTEX) /* !SAFE_MUTEX_DEFINED */
-
-static ulong mutex_delay(ulong delayloops)
-{
-  ulong	i;
-  volatile ulong j;
-
-  j = 0;
-
-  for (i = 0; i < delayloops * 50; i++)
-    j += i;
-
-  return(j); 
-}	
-
-#define MY_PTHREAD_FASTMUTEX_SPINS 8
-#define MY_PTHREAD_FASTMUTEX_DELAY 4
-
-static int cpu_count= 0;
-
-int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp,
-                              const pthread_mutexattr_t *attr)
-{
-  if ((cpu_count > 1) && (attr == MY_MUTEX_INIT_FAST))
-    mp->spins= MY_PTHREAD_FASTMUTEX_SPINS; 
-  else
-    mp->spins= 0;
-  mp->rng_state= 1;
-  return pthread_mutex_init(&mp->mutex, attr); 
-}
-
-/**
-  Park-Miller random number generator. A simple linear congruential
-  generator that operates in multiplicative group of integers modulo n.
-
-  x_{k+1} = (x_k g) mod n
-
-  Popular pair of parameters: n = 2^32 − 5 = 4294967291 and g = 279470273.
-  The period of the generator is about 2^31.
-  Largest value that can be returned: 2147483646 (RAND_MAX)
-
-  Reference:
-
-  S. K. Park and K. W. Miller
-  "Random number generators: good ones are hard to find"
-  Commun. ACM, October 1988, Volume 31, No 10, pages 1192-1201.
-*/
-
-static double park_rng(my_pthread_fastmutex_t *mp)
-{
-  mp->rng_state= ((my_ulonglong)mp->rng_state * 279470273U) % 4294967291U;
-  return (mp->rng_state / 2147483647.0);
-}
-
-int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp)
-{
-  int   res;
-  uint  i;
-  uint  maxdelay= MY_PTHREAD_FASTMUTEX_DELAY;
-
-  for (i= 0; i < mp->spins; i++)
-  {
-    res= pthread_mutex_trylock(&mp->mutex);
-
-    if (res == 0)
-      return 0;
-
-    if (res != EBUSY)
-      return res;
-
-    mutex_delay(maxdelay);
-    maxdelay += park_rng(mp) * MY_PTHREAD_FASTMUTEX_DELAY + 1;
-  }
-  return pthread_mutex_lock(&mp->mutex);
-}
-
-
-void fastmutex_global_init(void)
-{
-#ifdef _SC_NPROCESSORS_CONF
-  cpu_count= sysconf(_SC_NPROCESSORS_CONF);
 #endif
-}
-
-#endif /* defined(MY_PTHREAD_FASTMUTEX) && defined(SAFE_MUTEX_DEFINED) */
diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c
index 1c91c66..f7e18c8 100644
--- a/plugin/server_audit/server_audit.c
+++ b/plugin/server_audit/server_audit.c
@@ -140,8 +140,6 @@ static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)),
 /* How to access the pthread_mutex in mysql_mutex_t */
 #ifdef SAFE_MUTEX
 #define mysql_mutex_real_mutex(A) &(A)->m_mutex.mutex
-#elif defined(MY_PTHREAD_FASTMUTEX)
-#define mysql_mutex_real_mutex(A) &(A)->m_mutex.mutex
 #else
 #define mysql_mutex_real_mutex(A) &(A)->m_mutex
 #endif


More information about the commits mailing list