소스 검색

Remove spinlocks

Spinlocks are now removed, because even spinlock can improve
speed is some special cases, in most cases it makes corosync CPU usage
much more intensive and less responsive then if only mutexes are used.

What we were doing is:
pthread_mutex_lock
pthread_spin_lock
pthread_spin_unlock
pthread_mutex_unlock

what is not safe.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
(backported from commit 8c717c22b2f137f81ac5ae1a3437d73b62bb451d)
Jan Friesse 14 년 전
부모
커밋
9f032cab5e
4개의 변경된 파일1개의 추가작업 그리고 88개의 파일을 삭제
  1. 1 2
      configure.ac
  2. 0 40
      exec/logsys.c
  3. 0 20
      exec/main.c
  4. 0 26
      include/corosync/hdb.h

+ 1 - 2
configure.ac

@@ -112,8 +112,7 @@ AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([alarm alphasort atexit bzero dup2 endgrent endpwent fcntl \
 AC_CHECK_FUNCS([alarm alphasort atexit bzero dup2 endgrent endpwent fcntl \
 		getcwd getpeerucred getpeereid gettimeofday inet_ntoa memmove \
 		getcwd getpeerucred getpeereid gettimeofday inet_ntoa memmove \
 		memset mkdir scandir select socket strcasecmp strchr strdup \
 		memset mkdir scandir select socket strcasecmp strchr strdup \
-		strerror strrchr strspn strstr pthread_spin_lock \
-		pthread_spin_unlock pthread_setschedparam \
+		strerror strrchr strspn strstr pthread_setschedparam \
 		sched_get_priority_max sched_setscheduler])
 		sched_get_priority_max sched_setscheduler])
 
 
 AC_CONFIG_FILES([Makefile
 AC_CONFIG_FILES([Makefile

+ 0 - 40
exec/logsys.c

@@ -192,17 +192,9 @@ static sem_t logsys_thread_start;
 
 
 static sem_t logsys_print_finished;
 static sem_t logsys_print_finished;
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static pthread_spinlock_t logsys_flt_spinlock;
-#else
 static pthread_mutex_t logsys_flt_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t logsys_flt_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static pthread_spinlock_t logsys_wthread_spinlock;
-#else
 static pthread_mutex_t logsys_wthread_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t logsys_wthread_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
 
 
 static int logsys_buffer_full = 0;
 static int logsys_buffer_full = 0;
 
 
@@ -309,16 +301,6 @@ error_exit:
 	return (error_return);
 	return (error_return);
 }
 }
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static void logsys_flt_lock (void)
-{
-	pthread_spin_lock (&logsys_flt_spinlock);
-}
-static void logsys_flt_unlock (void)
-{
-	pthread_spin_unlock (&logsys_flt_spinlock);
-}
-#else
 static void logsys_flt_lock (void)
 static void logsys_flt_lock (void)
 {
 {
 	pthread_mutex_lock (&logsys_flt_mutex);
 	pthread_mutex_lock (&logsys_flt_mutex);
@@ -327,18 +309,7 @@ static void logsys_flt_unlock (void)
 {
 {
 	pthread_mutex_unlock (&logsys_flt_mutex);
 	pthread_mutex_unlock (&logsys_flt_mutex);
 }
 }
-#endif
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static void logsys_wthread_lock (void)
-{
-	pthread_spin_lock (&logsys_wthread_spinlock);
-}
-static void logsys_wthread_unlock (void)
-{
-	pthread_spin_unlock (&logsys_wthread_spinlock);
-}
-#else
 static void logsys_wthread_lock (void)
 static void logsys_wthread_lock (void)
 {
 {
 	pthread_mutex_lock (&logsys_wthread_mutex);
 	pthread_mutex_lock (&logsys_wthread_mutex);
@@ -347,7 +318,6 @@ static void logsys_wthread_unlock (void)
 {
 {
 	pthread_mutex_unlock (&logsys_wthread_mutex);
 	pthread_mutex_unlock (&logsys_wthread_mutex);
 }
 }
-#endif
 
 
 /*
 /*
  * Before any write operation, a reclaim on the buffer area must be executed
  * Before any write operation, a reclaim on the buffer area must be executed
@@ -1068,11 +1038,6 @@ int _logsys_rec_init (unsigned int fltsize)
 
 
 	sem_init (&logsys_print_finished, 0, 0);
 	sem_init (&logsys_print_finished, 0, 0);
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-	pthread_spin_init (&logsys_flt_spinlock, 1);
-	pthread_spin_init (&logsys_wthread_spinlock, 1);
-#endif
-
 	/*
 	/*
 	 * XXX: kill me for 1.1 because I am a dirty hack
 	 * XXX: kill me for 1.1 because I am a dirty hack
 	 * temporary workaround that will be replaced by supporting
 	 * temporary workaround that will be replaced by supporting
@@ -1090,11 +1055,6 @@ int _logsys_rec_init (unsigned int fltsize)
 	if (res == -1) {
 	if (res == -1) {
 		sem_destroy (&logsys_thread_start);
 		sem_destroy (&logsys_thread_start);
 		sem_destroy (&logsys_print_finished);
 		sem_destroy (&logsys_print_finished);
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-		pthread_spin_destroy (&logsys_flt_spinlock);
-		pthread_spin_destroy (&logsys_wthread_spinlock);
-#endif
-		return (-1);
 	}
 	}
 
 
 	memset (flt_data, 0, flt_real_size * 2);
 	memset (flt_data, 0, flt_real_size * 2);

+ 0 - 20
exec/main.c

@@ -111,11 +111,7 @@ static int sched_priority = 0;
 
 
 static unsigned int service_count = 32;
 static unsigned int service_count = 32;
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static pthread_spinlock_t serialize_spin;
-#else
 static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
 
 
 static struct totem_logging_configuration totem_logging_configuration;
 static struct totem_logging_configuration totem_logging_configuration;
 
 
@@ -258,17 +254,6 @@ static struct totempg_group corosync_group = {
 
 
 
 
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static void serialize_lock (void)
-{
-	pthread_spin_lock (&serialize_spin);
-}
-
-static void serialize_unlock (void)
-{
-	pthread_spin_unlock (&serialize_spin);
-}
-#else
 static void serialize_lock (void)
 static void serialize_lock (void)
 {
 {
 	pthread_mutex_lock (&serialize_mutex);
 	pthread_mutex_lock (&serialize_mutex);
@@ -278,7 +263,6 @@ static void serialize_unlock (void)
 {
 {
 	pthread_mutex_unlock (&serialize_mutex);
 	pthread_mutex_unlock (&serialize_mutex);
 }
 }
-#endif
 
 
 static void corosync_sync_completed (void)
 static void corosync_sync_completed (void)
 {
 {
@@ -1512,10 +1496,6 @@ int main (int argc, char **argv, char **envp)
 	hdb_handle_t object_runtime_handle;
 	hdb_handle_t object_runtime_handle;
 	enum e_ais_done flock_err;
 	enum e_ais_done flock_err;
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-	pthread_spin_init (&serialize_spin, 0);
-#endif
-
  	/* default configuration
  	/* default configuration
 	 */
 	 */
 	background = 1;
 	background = 1;

+ 0 - 26
include/corosync/hdb.h

@@ -74,35 +74,10 @@ struct hdb_handle_database {
 	struct hdb_handle *handles;
 	struct hdb_handle *handles;
 	unsigned int iterator;
 	unsigned int iterator;
         void (*destructor) (void *);
         void (*destructor) (void *);
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-	pthread_spinlock_t lock;
-#else
 	pthread_mutex_t lock;
 	pthread_mutex_t lock;
-#endif
 	unsigned int first_run;
 	unsigned int first_run;
 };
 };
 
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static inline void hdb_database_lock (pthread_spinlock_t *spinlock)
-{
-	pthread_spin_lock (spinlock);
-}
-
-static inline void hdb_database_unlock (pthread_spinlock_t *spinlock)
-{
-	pthread_spin_unlock (spinlock);
-}
-static inline void hdb_database_lock_init (pthread_spinlock_t *spinlock)
-{
-	pthread_spin_init (spinlock, 0);
-}
-
-static inline void hdb_database_lock_destroy (pthread_spinlock_t *spinlock)
-{
-	pthread_spin_destroy (spinlock);
-}
-
-#else
 static inline void hdb_database_lock (pthread_mutex_t *mutex)
 static inline void hdb_database_lock (pthread_mutex_t *mutex)
 {
 {
 	pthread_mutex_lock (mutex);
 	pthread_mutex_lock (mutex);
@@ -121,7 +96,6 @@ static inline void hdb_database_lock_destroy (pthread_mutex_t *mutex)
 {
 {
 	pthread_mutex_destroy (mutex);
 	pthread_mutex_destroy (mutex);
 }
 }
-#endif
 
 
 #define DECLARE_HDB_DATABASE(database_name,destructor_function)		\
 #define DECLARE_HDB_DATABASE(database_name,destructor_function)		\
 static struct hdb_handle_database (database_name) = {			\
 static struct hdb_handle_database (database_name) = {			\