List:Commits« Previous MessageNext Message »
From:marko.makela Date:March 22 2011 11:39am
Subject:bzr commit into mysql-5.5-innodb branch (marko.makela:3350) Bug#11766305
View as plain text  
#At file:///home/marko/innobase/dev/mysql2a/5.5-innodb/ based on revid:marko.makela@strippedz7g8he5g4qcg

 3350 Marko Mäkelä	2011-03-22
      Bug#11766305 - 59392: Remove thr0loc.c and ibuf_inside() [part 3]
      Remove the slot_no member of struct thr_local_struct.
      
      enum srv_thread_type: Remove unused thread types.
      srv_get_thread_type(): Unused function, remove.
      
      thr_local_get_slot_no(), thr_local_set_slot_no(): Remove.
      
      srv_thread_type_validate(), srv_slot_get_type(): New functions, for debugging.
      
      srv_table_reserve_slot(): Return the srv_slot_t* directly. Do not create
      thread-local storage.
      
      srv_suspend_thread(): Get the srv_slot_t* as parameter. Return void;
      the caller knows slot->event already.
      
      srv_thread_has_reserved_slot(), srv_release_threads(): Assert
      srv_thread_type_validate(type).
      
      srv_init(): Use mem_zalloc() instead of mem_alloc(). Replace
      srv_table_get_nth_slot(), because it now asserts that the kernel_mutex
      is being held.
      
      srv_master_thread(), srv_purge_thread(): Remember the slot from
      srv_table_reserve_slot().
      
      rb:629 approved by Inaam Rana

    modified:
      storage/innobase/include/srv0srv.h
      storage/innobase/include/thr0loc.h
      storage/innobase/srv/srv0srv.c
      storage/innobase/thr/thr0loc.c
=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h	revid:marko.makela@oracle.com-20110321075638-u4i8z7g8he5g4qcg
+++ b/storage/innobase/include/srv0srv.h	revid:marko.makela@stripped0322113916-oricw02qg3tzvim8
@@ -442,16 +442,8 @@ typedef enum srv_stats_method_name_enum
 #ifndef UNIV_HOTBACKUP
 /** Types of threads existing in the system. */
 enum srv_thread_type {
-	SRV_COM = 1,	/**< threads serving communication and queries */
-	SRV_CONSOLE,	/**< thread serving console */
-	SRV_WORKER,	/**< threads serving parallelized queries and
+	SRV_WORKER = 0,	/**< threads serving parallelized queries and
 			queries released from lock wait */
-#if 0
-	/* Utility threads */
-	SRV_BUFFER,	/**< thread flushing dirty buffer blocks */
-	SRV_RECOVERY,	/**< threads finishing a recovery */
-	SRV_INSERT,	/**< thread flushing the insert buffer to disk */
-#endif
 	SRV_MASTER	/**< the master thread, (whose type number must
 			be biggest) */
 };
@@ -490,13 +482,6 @@ ulint
 srv_get_n_threads(void);
 /*===================*/
 /*********************************************************************//**
-Returns the calling thread type.
-@return	SRV_COM, ... */
-
-enum srv_thread_type
-srv_get_thread_type(void);
-/*=====================*/
-/*********************************************************************//**
 Check whether thread type has reserved a slot.
 @return	slot number or UNDEFINED if not found*/
 UNIV_INTERN

=== modified file 'storage/innobase/include/thr0loc.h'
--- a/storage/innobase/include/thr0loc.h	revid:marko.makela@stripped321075638-u4i8z7g8he5g4qcg
+++ b/storage/innobase/include/thr0loc.h	revid:marko.makela@strippedricw02qg3tzvim8
@@ -59,22 +59,6 @@ thr_local_free(
 /*===========*/
 	os_thread_id_t	id);	/*!< in: thread id */
 /*******************************************************************//**
-Gets the slot number in the thread table of a thread.
-@return	slot number */
-UNIV_INTERN
-ulint
-thr_local_get_slot_no(
-/*==================*/
-	os_thread_id_t	id);	/*!< in: thread id of the thread */
-/*******************************************************************//**
-Sets in the local storage the slot number in the thread table of a thread. */
-UNIV_INTERN
-void
-thr_local_set_slot_no(
-/*==================*/
-	os_thread_id_t	id,	/*!< in: thread id of the thread */
-	ulint		slot_no);/*!< in: slot number */
-/*******************************************************************//**
 Returns pointer to the 'in_ibuf' field within the current thread local
 storage.
 @return	pointer to the in_ibuf field */

=== modified file 'storage/innobase/srv/srv0srv.c'
--- a/storage/innobase/srv/srv0srv.c	revid:marko.makela@stripped20110321075638-u4i8z7g8he5g4qcg
+++ b/storage/innobase/srv/srv0srv.c	revid:marko.makela@strippedoricw02qg3tzvim8
@@ -690,7 +690,7 @@ Unix.*/
 struct srv_slot_struct{
 	os_thread_id_t	id;		/*!< thread id */
 	os_thread_t	handle;		/*!< thread handle */
-	unsigned	type:3;		/*!< thread type: user, utility etc. */
+	unsigned	type:1;		/*!< thread type: user, utility etc. */
 	unsigned	in_use:1;	/*!< TRUE if this slot is in use */
 	unsigned	suspended:1;	/*!< TRUE if the thread is waiting
 					for the event of this slot */
@@ -797,6 +797,7 @@ srv_table_get_nth_slot(
 /*===================*/
 	ulint	index)		/*!< in: index of the slot */
 {
+	ut_ad(mutex_own(&kernel_mutex));
 	ut_a(index < OS_THREAD_MAX_N);
 
 	return(srv_sys->threads + index);
@@ -815,7 +816,7 @@ srv_get_n_threads(void)
 
 	mutex_enter(&kernel_mutex);
 
-	for (i = SRV_COM; i < SRV_MASTER + 1; i++) {
+	for (i = 0; i < SRV_MASTER + 1; i++) {
 
 		n_threads += srv_n_threads[i];
 	}
@@ -825,13 +826,46 @@ srv_get_n_threads(void)
 	return(n_threads);
 }
 
+#ifdef UNIV_DEBUG
 /*********************************************************************//**
-Reserves a slot in the thread table for the current thread. Also creates the
-thread local storage struct for the current thread. NOTE! The server mutex
-has to be reserved by the caller!
-@return	reserved slot index */
+Validates the type of a thread table slot.
+@return TRUE if ok */
 static
-ulint
+ibool
+srv_thread_type_validate(
+/*=====================*/
+	enum srv_thread_type	type)	/*!< in: thread type */
+{
+	switch (type) {
+	case SRV_WORKER:
+	case SRV_MASTER:
+		return(TRUE);
+	}
+	ut_error;
+	return(FALSE);
+}
+#endif /* UNIV_DEBUG */
+
+/*********************************************************************//**
+Gets the type of a thread table slot.
+@return thread type */
+static
+enum srv_thread_type
+srv_slot_get_type(
+/*==============*/
+	const srv_slot_t*	slot)	/*!< in: thread slot */
+{
+	enum srv_thread_type	type	= (enum srv_thread_type) slot->type;
+	ut_ad(srv_thread_type_validate(type));
+	return(type);
+}
+
+/*********************************************************************//**
+Reserves a slot in the thread table for the current thread.
+NOTE! The server mutex has to be reserved by the caller!
+@return	reserved slot */
+static
+srv_slot_t*
 srv_table_reserve_slot(
 /*===================*/
 	enum srv_thread_type	type)	/*!< in: type of the thread */
@@ -839,8 +873,7 @@ srv_table_reserve_slot(
 	srv_slot_t*	slot;
 	ulint		i;
 
-	ut_a(type > 0);
-	ut_a(type <= SRV_MASTER);
+	ut_ad(srv_thread_type_validate(type));
 	ut_ad(mutex_own(&kernel_mutex));
 
 	i = 0;
@@ -851,53 +884,40 @@ srv_table_reserve_slot(
 		slot = srv_table_get_nth_slot(i);
 	}
 
-	ut_a(slot->in_use == FALSE);
-
 	slot->in_use = TRUE;
 	slot->suspended = FALSE;
 	slot->type = type;
+	ut_ad(srv_slot_get_type(slot) == type);
 	slot->id = os_thread_get_curr_id();
 	slot->handle = os_thread_get_curr();
 
-	thr_local_create();
-
-	thr_local_set_slot_no(os_thread_get_curr_id(), i);
-
-	return(i);
+	return(slot);
 }
 
 /*********************************************************************//**
 Suspends the calling thread to wait for the event in its thread slot.
-NOTE! The server mutex has to be reserved by the caller!
-@return	event for the calling thread to wait */
+NOTE! The server mutex has to be reserved by the caller! */
 static
-os_event_t
-srv_suspend_thread(void)
-/*====================*/
+void
+srv_suspend_thread(
+/*===============*/
+	srv_slot_t*	slot)	/*!< in/out: thread slot */
 {
-	srv_slot_t*		slot;
-	os_event_t		event;
-	ulint			slot_no;
 	enum srv_thread_type	type;
 
 	ut_ad(mutex_own(&kernel_mutex));
-
-	slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
+	ut_ad(slot->in_use);
+	ut_ad(!slot->suspended);
+	ut_ad(slot->id == os_thread_get_curr_id());
 
 	if (srv_print_thread_releases) {
 		fprintf(stderr,
 			"Suspending thread %lu to slot %lu\n",
-			(ulong) os_thread_get_curr_id(), (ulong) slot_no);
+			(ulong) os_thread_get_curr_id(),
+			(ulong) (slot - srv_sys->threads));
 	}
 
-	slot = srv_table_get_nth_slot(slot_no);
-
-	type = slot->type;
-
-	ut_ad(type >= SRV_WORKER);
-	ut_ad(type <= SRV_MASTER);
-
-	event = slot->event;
+	type = srv_slot_get_type(slot);
 
 	slot->suspended = TRUE;
 
@@ -905,9 +925,7 @@ srv_suspend_thread(void)
 
 	srv_n_threads_active[type]--;
 
-	os_event_reset(event);
-
-	return(event);
+	os_event_reset(slot->event);
 }
 
 /*********************************************************************//**
@@ -926,8 +944,7 @@ srv_release_threads(
 	ulint		i;
 	ulint		count	= 0;
 
-	ut_ad(type >= SRV_WORKER);
-	ut_ad(type <= SRV_MASTER);
+	ut_ad(srv_thread_type_validate(type));
 	ut_ad(n > 0);
 	ut_ad(mutex_own(&kernel_mutex));
 
@@ -935,7 +952,8 @@ srv_release_threads(
 
 		slot = srv_table_get_nth_slot(i);
 
-		if (slot->in_use && slot->type == type && slot->suspended) {
+		if (slot->in_use && slot->suspended
+		    && srv_slot_get_type(slot) == type) {
 
 			slot->suspended = FALSE;
 
@@ -963,34 +981,6 @@ srv_release_threads(
 }
 
 /*********************************************************************//**
-Returns the calling thread type.
-@return	SRV_COM, ... */
-UNIV_INTERN
-enum srv_thread_type
-srv_get_thread_type(void)
-/*=====================*/
-{
-	ulint			slot_no;
-	srv_slot_t*		slot;
-	enum srv_thread_type	type;
-
-	mutex_enter(&kernel_mutex);
-
-	slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
-
-	slot = srv_table_get_nth_slot(slot_no);
-
-	type = slot->type;
-
-	ut_ad(type >= SRV_WORKER);
-	ut_ad(type <= SRV_MASTER);
-
-	mutex_exit(&kernel_mutex);
-
-	return(type);
-}
-
-/*********************************************************************//**
 Check whether thread type has reserved a slot. Return the first slot that
 is found. This works because we currently have only 1 thread of each type.
 @return	slot number or ULINT_UNDEFINED if not found*/
@@ -1003,6 +993,7 @@ srv_thread_has_reserved_slot(
 	ulint			i;
 	ulint			slot_no = ULINT_UNDEFINED;
 
+	ut_ad(srv_thread_type_validate(type));
 	mutex_enter(&kernel_mutex);
 
 	for (i = 0; i < OS_THREAD_MAX_N; i++) {
@@ -1040,22 +1031,18 @@ srv_init(void)
 	mutex_create(srv_innodb_monitor_mutex_key,
 		     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
 
-	srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
+	srv_sys->threads = mem_zalloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
 
 	for (i = 0; i < OS_THREAD_MAX_N; i++) {
-		slot = srv_table_get_nth_slot(i);
-		slot->in_use = FALSE;
-		slot->type=0;	/* Avoid purify errors */
+		slot = srv_sys->threads + i;
 		slot->event = os_event_create(NULL);
 		ut_a(slot->event);
 	}
 
-	srv_mysql_table = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
+	srv_mysql_table = mem_zalloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
 
 	for (i = 0; i < OS_THREAD_MAX_N; i++) {
 		slot = srv_mysql_table + i;
-		slot->in_use = FALSE;
-		slot->type = 0;
 		slot->event = os_event_create(NULL);
 		ut_a(slot->event);
 	}
@@ -1501,7 +1488,7 @@ srv_table_reserve_slot_for_mysql(void)
 	while (slot->in_use) {
 		i++;
 
-		if (i >= OS_THREAD_MAX_N) {
+		if (UNIV_UNLIKELY(i >= OS_THREAD_MAX_N)) {
 
 			ut_print_timestamp(stderr);
 
@@ -2489,7 +2476,7 @@ srv_is_any_background_thread_active(void
 
 	mutex_enter(&kernel_mutex);
 
-	for (i = SRV_COM; i <= SRV_MASTER; ++i) {
+	for (i = 0; i <= SRV_MASTER; ++i) {
 		if (srv_n_threads_active[i] != 0) {
 			ret = TRUE;
 			break;
@@ -2643,7 +2630,7 @@ srv_master_thread(
 			os_thread_create */
 {
 	buf_pool_stat_t buf_stat;
-	os_event_t	event;
+	srv_slot_t*	slot;
 	ulint		old_activity_count;
 	ulint		n_pages_purged	= 0;
 	ulint		n_bytes_merged;
@@ -2671,7 +2658,7 @@ srv_master_thread(
 
 	mutex_enter(&kernel_mutex);
 
-	srv_table_reserve_slot(SRV_MASTER);
+	slot = srv_table_reserve_slot(SRV_MASTER);
 
 	srv_n_threads_active[SRV_MASTER]++;
 
@@ -3060,7 +3047,7 @@ suspend_thread:
 		goto loop;
 	}
 
-	event = srv_suspend_thread();
+	srv_suspend_thread(slot);
 
 	mutex_exit(&kernel_mutex);
 
@@ -3070,7 +3057,7 @@ suspend_thread:
 	manual also mentions this string in several places. */
 	srv_main_thread_op_info = "waiting for server activity";
 
-	os_event_wait(event);
+	os_event_wait(slot->event);
 
 	if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) {
 		/* This is only extra safety, the thread should exit
@@ -3100,7 +3087,6 @@ srv_purge_thread(
 {
 	srv_slot_t*	slot;
 	ulint		retries = 0;
-	ulint		slot_no = ULINT_UNDEFINED;
 	ulint		n_total_purged = ULINT_UNDEFINED;
 
 	ut_a(srv_n_purge_threads == 1);
@@ -3116,9 +3102,7 @@ srv_purge_thread(
 
 	mutex_enter(&kernel_mutex);
 
-	slot_no = srv_table_reserve_slot(SRV_WORKER);
-
-	slot = srv_table_get_nth_slot(slot_no);
+	slot = srv_table_reserve_slot(SRV_WORKER);
 
 	++srv_n_threads_active[SRV_WORKER];
 
@@ -3137,15 +3121,13 @@ srv_purge_thread(
 		    || (n_total_purged == 0
 			&& retries >= TRX_SYS_N_RSEGS)) {
 
-			os_event_t	event;
-
 			mutex_enter(&kernel_mutex);
 
-			event = srv_suspend_thread();
+			srv_suspend_thread(slot);
 
 			mutex_exit(&kernel_mutex);
 
-			os_event_wait(event);
+			os_event_wait(slot->event);
 
 			retries = 0;
 		}
@@ -3179,16 +3161,11 @@ srv_purge_thread(
 
 	mutex_enter(&kernel_mutex);
 
-	ut_ad(srv_table_get_nth_slot(slot_no) == slot);
-
 	/* Decrement the active count. */
-	srv_suspend_thread();
+	srv_suspend_thread(slot);
 
 	slot->in_use = FALSE;
 
-	/* Free the thread local memory. */
-	thr_local_free(os_thread_get_curr_id());
-
 	mutex_exit(&kernel_mutex);
 
 #ifdef UNIV_DEBUG_THREAD_CREATION

=== modified file 'storage/innobase/thr/thr0loc.c'
--- a/storage/innobase/thr/thr0loc.c	revid:marko.makela@stripped4qcg
+++ b/storage/innobase/thr/thr0loc.c	revid:marko.makela@stripped
@@ -65,8 +65,6 @@ for the field. */
 struct thr_local_struct{
 	os_thread_id_t	id;	/*!< id of the thread which owns this struct */
 	os_thread_t	handle;	/*!< operating system handle to the thread */
-	ulint		slot_no;/*!< the index of the slot in the thread table
-				for this thread */
 	ibool		in_ibuf;/*!< TRUE if the thread is doing an ibuf
 				operation */
 	hash_node_t	hash;	/*!< hash chain node */
@@ -87,8 +85,6 @@ thr_local_validate(
 	const thr_local_t*	local)	/*!< in: data to validate */
 {
 	ut_ad(local->magic_n == THR_LOCAL_MAGIC_N);
-	ut_ad(local->slot_no == ULINT_UNDEFINED
-	      || local->slot_no < OS_THREAD_MAX_N);
 	ut_ad(local->in_ibuf == FALSE || local->in_ibuf == TRUE);
 	return(TRUE);
 }
@@ -132,49 +128,6 @@ try_again:
 }
 
 /*******************************************************************//**
-Gets the slot number in the thread table of a thread.
-@return	slot number */
-UNIV_INTERN
-ulint
-thr_local_get_slot_no(
-/*==================*/
-	os_thread_id_t	id)	/*!< in: thread id of the thread */
-{
-	ulint		slot_no;
-	thr_local_t*	local;
-
-	mutex_enter(&thr_local_mutex);
-
-	local = thr_local_get(id);
-
-	slot_no = local->slot_no;
-
-	mutex_exit(&thr_local_mutex);
-
-	return(slot_no);
-}
-
-/*******************************************************************//**
-Sets the slot number in the thread table of a thread. */
-UNIV_INTERN
-void
-thr_local_set_slot_no(
-/*==================*/
-	os_thread_id_t	id,	/*!< in: thread id of the thread */
-	ulint		slot_no)/*!< in: slot number */
-{
-	thr_local_t*	local;
-
-	mutex_enter(&thr_local_mutex);
-
-	local = thr_local_get(id);
-
-	local->slot_no = slot_no;
-
-	mutex_exit(&thr_local_mutex);
-}
-
-/*******************************************************************//**
 Returns pointer to the 'in_ibuf' field within the current thread local
 storage.
 @return	pointer to the in_ibuf field */
@@ -212,7 +165,6 @@ thr_local_create(void)
 	local->id = os_thread_get_curr_id();
 	local->handle = os_thread_get_curr();
 	local->magic_n = THR_LOCAL_MAGIC_N;
-	local->slot_no = ULINT_UNDEFINED;
 	local->in_ibuf = FALSE;
 
 	mutex_enter(&thr_local_mutex);

Attachment: [text/bzr-bundle] bzr/marko.makela@oracle.com-20110322113916-oricw02qg3tzvim8.bundle
Thread
bzr commit into mysql-5.5-innodb branch (marko.makela:3350) Bug#11766305marko.makela22 Mar