[asterisk-commits] murf: branch murf/threadpool r151318 - in /team/murf/threadpool: ./ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 20 11:22:40 CDT 2008


Author: murf
Date: Mon Oct 20 11:22:39 2008
New Revision: 151318

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151318
Log:
These tweaks allow threadpool to work, but...

At about 100 calls/sec, I get crashes. I can process
thousands of calls at slower rates with no problem,
but at this level, I get crashes.

So, I guess, when I get time, I'll check to see
what trunk's max call/sec rate is, to see if the
problem is in the threadpool, or in chan_sip.

It appears to be mem corruption, so I suspect
the locking is at issue.



Modified:
    team/murf/threadpool/Makefile
    team/murf/threadpool/main/threadpool.c

Modified: team/murf/threadpool/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/threadpool/Makefile?view=diff&rev=151318&r1=151317&r2=151318
==============================================================================
--- team/murf/threadpool/Makefile (original)
+++ team/murf/threadpool/Makefile Mon Oct 20 11:22:39 2008
@@ -36,6 +36,8 @@
 #
 # You can add the path of local module subdirs from the command line with
 #   make LOCAL_MOD_SUBDIRS= ....
+#
+
 
 export ASTTOPDIR		# Top level dir, used in subdirs' Makefiles
 export ASTERISKVERSION
@@ -106,7 +108,7 @@
 ASTLDFLAGS+=$(LDOPTS)
 
 #Uncomment this to see all build commands instead of 'quiet' output
-#NOISY_BUILD=yes
+NOISY_BUILD=yes
 
 empty:=
 space:=$(empty) $(empty)

Modified: team/murf/threadpool/main/threadpool.c
URL: http://svn.digium.com/view/asterisk/team/murf/threadpool/main/threadpool.c?view=diff&rev=151318&r1=151317&r2=151318
==============================================================================
--- team/murf/threadpool/main/threadpool.c (original)
+++ team/murf/threadpool/main/threadpool.c Mon Oct 20 11:22:39 2008
@@ -101,10 +101,9 @@
 	return;
 }
 
-static struct ast_pooledthread *find_idle_thread(void)
+static struct ast_pooledthread *find_idle_thread(struct ast_threadpool *pool)
 {
 	struct ast_pooledthread *thread = NULL;
-	struct ast_threadpool *pool = thread->owning_pool;
 
 	/* Pop the head of the idle list off */
 	AST_LIST_LOCK(&pool->idle_list);
@@ -173,6 +172,11 @@
 	int put_into_idle = 0;
 	struct ast_threadpool *pool = thread->owning_pool;
 
+	if (!pool) {
+		ast_log(LOG_NOTICE, "Huh? a null pool ptr?\n");
+		return NULL;
+	}
+	
 	ast_atomic_fetchadd_int(&pool->activethreadcount,1);
 	pthread_cleanup_push(threadpool_process_thread_cleanup, data);
 	for(;;) {
@@ -247,10 +251,11 @@
 			thread->iostate = THREADPOOL_IOSTATE_PROCESSING;
 
 			/* call out func now */
-			if (thread->func)
+			if (thread->func) {
 				(*thread->func)(thread->funcdata);
-			else
+			} else {
 				(*pool->func)(thread->funcdata);
+			}
 			break;
 		default:
 			break;
@@ -265,7 +270,6 @@
 		AST_LIST_LOCK(&pool->active_list);
 		AST_LIST_REMOVE(&pool->active_list, thread, list);
 		AST_LIST_UNLOCK(&pool->active_list);
-
 	}
 
 	/*!\note For some reason, idle threads are exiting without being removed
@@ -301,6 +305,8 @@
 	pool->max_threads = max_threads;
 	pool->dynamic_msec = dynamic_msec;
 	pool->func = def_func_to_run;
+	pool->funcname = funcname; /* DO NOT FREE THIS (it's almost a quoted constant! */
+	
 	/* put this struct in the list of pools so we can list them from the cli */
 	
 	/* start up the non-dynamic threads */
@@ -353,12 +359,12 @@
 	static time_t lasterror;
 	static time_t t;
 
-	thread = find_idle_thread();
+	thread = find_idle_thread(pool);
 
 	if (thread != NULL) {
 		thread->func = pool->func;
 		thread->funcdata = data;
-		thread->iostate = THREADPOOL_IOSTATE_SCHEDREADY;
+		thread->iostate = THREADPOOL_IOSTATE_READY;
 		ast_copy_string(thread->curfunc, pool->funcname, sizeof(thread->curfunc));
 		signal_condition(&thread->lock, &thread->cond);
 		return 0;
@@ -378,13 +384,13 @@
 	static time_t lasterror;
 	static time_t t;
 
-	thread = find_idle_thread();
+	thread = find_idle_thread(pool);
 
 	if (thread != NULL) {
 		thread->func = func;
 		thread->funcdata = data;
 		ast_copy_string(thread->curfunc, funcname, sizeof(thread->curfunc));
-		thread->iostate = THREADPOOL_IOSTATE_SCHEDREADY;
+		thread->iostate = THREADPOOL_IOSTATE_READY;
 		signal_condition(&thread->lock, &thread->cond);
 		return 0;
 	}
@@ -422,48 +428,70 @@
 		
 	AST_LIST_LOCK(&pool_list);
 	AST_LIST_TRAVERSE(&pool_list, pool, list) {
+		
 		ast_cli(a->fd, "Information for the %s ThreadPool\n", pool->name);
 		time(&t);
 		ast_cli(a->fd, "Idle Threads:\n");
 		AST_LIST_LOCK(&pool->idle_list);
 		AST_LIST_TRAVERSE(&pool->idle_list, thread, list) {
-#ifdef DEBUG_SCHED_MULTITHREAD
-			ast_cli(a->fd, "Thread %d: state=%d, update=%d, actions=%d, func='%s'\n", 
-					thread->threadnum, thread->iostate, (int)(t - thread->checktime), thread->actions, thread->curfunc);
-#else
-			ast_cli(a->fd, "Thread %d: state=%d, update=%d, actions=%d\n", 
-					thread->threadnum, thread->iostate, (int)(t - thread->checktime), thread->actions);
-#endif
+			char *state, *f1;
+			switch(thread->iostate) {
+			case THREADPOOL_IOSTATE_READY: state = "READY"; break;
+			case THREADPOOL_IOSTATE_IDLE: state = "IDLE"; break;
+			case THREADPOOL_IOSTATE_PROCESSING: state = "PROCESSING"; break;
+			case THREADPOOL_IOSTATE_SCHEDREADY: state = "SCHEDREADY"; break;
+			default: state = "???"; break;
+			}
+			if (ast_strlen_zero(thread->curfunc))
+				f1 = pool->funcname;
+			else
+				f1 = thread->curfunc;
+			ast_cli(a->fd, "Thread %d: state=%s, update=%d, actions=%d, func='%s'\n", 
+					thread->threadnum, state, (int)(t - thread->checktime), thread->actions, thread->curfunc);
 			threadcount++;
 		}
 		AST_LIST_UNLOCK(&pool->idle_list);
 		ast_cli(a->fd, "Active Threads:\n");
 		AST_LIST_LOCK(&pool->active_list);
 		AST_LIST_TRAVERSE(&pool->active_list, thread, list) {
+			char *state, *f1;
+			switch(thread->iostate) {
+			case THREADPOOL_IOSTATE_READY: state = "READY"; break;
+			case THREADPOOL_IOSTATE_IDLE: state = "IDLE"; break;
+			case THREADPOOL_IOSTATE_PROCESSING: state = "PROCESSING"; break;
+			case THREADPOOL_IOSTATE_SCHEDREADY: state = "SCHEDREADY"; break;
+			default: state = "???"; break;
+			}
+			if (ast_strlen_zero(thread->curfunc))
+				f1 = pool->funcname;
+			else
+				f1 = thread->curfunc;
 			if (thread->type == THREADPOOL_THREAD_TYPE_DYNAMIC)
 				type = 'D';
 			else
 				type = 'P';
-#ifdef DEBUG_SCHED_MULTITHREAD
-			ast_cli(a->fd, "Thread %c%d: state=%d, update=%d, actions=%d, func='%s'\n", 
-					type, thread->threadnum, thread->iostate, (int)(t - thread->checktime), thread->actions, thread->curfunc);
-#else
-			ast_cli(a->fd, "Thread %c%d: state=%d, update=%d, actions=%d\n", 
-					type, thread->threadnum, thread->iostate, (int)(t - thread->checktime), thread->actions);
-#endif
+			ast_cli(a->fd, "Thread %c%d: state=%s, update=%d, actions=%d, func='%s'\n", 
+					type, thread->threadnum, state, (int)(t - thread->checktime), thread->actions, f1);
 			threadcount++;
 		}
 		AST_LIST_UNLOCK(&pool->active_list);
 		ast_cli(a->fd, "Dynamic Threads:\n");
 		AST_LIST_LOCK(&pool->dynamic_list);
 		AST_LIST_TRAVERSE(&pool->dynamic_list, thread, list) {
-#ifdef DEBUG_SCHED_MULTITHREAD
-			ast_cli(a->fd, "Thread %d: state=%d, update=%d, actions=%d, func='%s'\n",
-					thread->threadnum, thread->iostate, (int)(t - thread->checktime), thread->actions, thread->curfunc);
-#else
-			ast_cli(a->fd, "Thread %d: state=%d, update=%d, actions=%d\n",
-					thread->threadnum, thread->iostate, (int)(t - thread->checktime), thread->actions);
-#endif
+			char *state, *f1;
+			switch(thread->iostate) {
+			case THREADPOOL_IOSTATE_READY: state = "READY"; break;
+			case THREADPOOL_IOSTATE_IDLE: state = "IDLE"; break;
+			case THREADPOOL_IOSTATE_PROCESSING: state = "PROCESSING"; break;
+			case THREADPOOL_IOSTATE_SCHEDREADY: state = "SCHEDREADY"; break;
+			default: state = "???"; break;
+			}
+			if (ast_strlen_zero(thread->curfunc))
+				f1 = pool->funcname;
+			else
+				f1 = thread->curfunc;
+			ast_cli(a->fd, "Thread %d: state=%s, update=%d, actions=%d, func='%s'\n",
+					thread->threadnum, state, (int)(t - thread->checktime), thread->actions, f1);
 			dynamiccount++;
 		}
 		AST_LIST_UNLOCK(&pool->dynamic_list);




More information about the asterisk-commits mailing list