[asterisk-commits] murf: branch murf/bug11210 r95623 - in /team/murf/bug11210: ./ channels/ incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 31 22:20:54 CST 2007


Author: murf
Date: Mon Dec 31 22:20:53 2007
New Revision: 95623

URL: http://svn.digium.com/view/asterisk?view=rev&rev=95623
Log:
Optimized the schedule() routine just a little. There's a little bit of a problem with hangup and the rtp stuff, tho...

Modified:
    team/murf/bug11210/Makefile
    team/murf/bug11210/channels/chan_sip.c
    team/murf/bug11210/include/asterisk/dlinkedlists.h
    team/murf/bug11210/include/asterisk/sched.h
    team/murf/bug11210/main/sched.c

Modified: team/murf/bug11210/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/Makefile?view=diff&rev=95623&r1=95622&r2=95623
==============================================================================
--- team/murf/bug11210/Makefile (original)
+++ team/murf/bug11210/Makefile Mon Dec 31 22:20:53 2007
@@ -105,7 +105,7 @@
 ASTLDFLAGS+=$(LDOPTS)
 
 #Uncomment this to see all build commands instead of 'quiet' output
-#NOISY_BUILD=yes
+NOISY_BUILD=yes
 
 ASTTOPDIR:=$(CURDIR)
 
@@ -113,8 +113,8 @@
 OVERWRITE=y
 
 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
-DEBUG=-g3
-
+DEBUG=-g3 -pg
+ASTLDFLAGS += -pg
 
 # Define standard directories for various platforms
 # These apply if they are not redefined in asterisk.conf 

Modified: team/murf/bug11210/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_sip.c?view=diff&rev=95623&r1=95622&r2=95623
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Mon Dec 31 22:20:53 2007
@@ -1798,6 +1798,7 @@
 static const char *nat2str(int nat) attribute_const;
 static int peer_status(struct sip_peer *peer, char *status, int statuslen);
 static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *sip_show_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char * _sip_show_peers(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]);
 static char *sip_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -1889,6 +1890,7 @@
 static int __sip_do_register(struct sip_registry *r);
 static int sip_reg_timeout(const void *data);
 static void sip_send_all_registers(void);
+static int sip_reinvite_retry(const void *data);
 
 /*--- Parsing SIP requests and responses */
 static void append_date(struct sip_request *req);	/* Append date to SIP packet */
@@ -3514,14 +3516,20 @@
 	} else if (sin) { /* search by addr? */
 		tmp_peer.addr.sin_addr.s_addr = sin->sin_addr.s_addr;
 		tmp_peer.addr.sin_port = sin->sin_port;
+		tmp_peer.flags[0].flags = 0;
 		p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER,"ao2_find in peers_by_ip table"); /* WAS:  p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */
 		if (!p) {
 			struct ao2_iterator i;
 			char ad[40];
 			struct sip_peer *d2;
+			ast_set_flag(&tmp_peer.flags[0], SIP_INSECURE_PORT);
+			p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER,"ao2_find in peers_by_ip table 2"); /* WAS:  p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */
+			if (p) {
+				return p;
+			}
+			
 			addr2str(sin, ad);
 			ast_log(LOG_NOTICE,"Couldn't find sin=> %s...\n", ad);
-				
 			i = ao2_iterator_init(peers_by_ip, 0);
 				
 			while ((d2 = ao2_t_iterator_next(&i,"iterate thru peers_by_ip "))) {
@@ -12260,6 +12268,45 @@
 
 	return CLI_SUCCESS;
 }
+
+static char *sip_show_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char cbuf[2256];
+	struct ast_cb_names cbnames = {9, { "retrans_pkt", 
+										"__sip_autodestruct", 
+										"expire_register", 
+										"auto_congest", 
+										"sip_reg_timeout",
+										"sip_poke_peer_s",
+										"sip_poke_noanswer",
+										"sip_reregister",
+										"sip_reinvite_retry"},
+								   { retrans_pkt,
+									 __sip_autodestruct, 
+									 expire_register, 
+									 auto_congest, 
+									 sip_reg_timeout,
+									 sip_poke_peer_s,
+									 sip_poke_noanswer,
+									 sip_reregister,
+									 sip_reinvite_retry}};
+	
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "sip show sched";
+		e->usage =
+			"Usage: sip show sched\n"
+			"       Shows stats on what's in the sched queue at the moment\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	ast_cli(a->fd,"\n");
+	ast_sched_report(sched, cbuf,sizeof(cbuf), &cbnames);
+	ast_cli(a->fd,cbuf);
+	return CLI_SUCCESS;
+}
+
 
 /*! \brief Show one user in detail */
 static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -17561,7 +17608,7 @@
 	if (!dialog->rtp || !dialog->owner)
 		return;
 	/* If the call is not in UP state or redirected outside Asterisk, no need to check timers */
-	if (dialog->owner->_state != AST_STATE_UP || dialog->redirip.sin_addr.s_addr)
+	if (dialog->owner->_state != AST_STATE_UP || dialog->redirip.sin_addr.s_addr) /* CRASH HERE because dialog->owner is NULL */
 		return;
 
 	/* If the call is involved in a T38 fax session do not check RTP timeout */
@@ -20125,6 +20172,7 @@
 	AST_CLI_DEFINE(sip_show_peer, "Show details on specific SIP peer"),
 	AST_CLI_DEFINE(sip_show_users, "List defined SIP users"),
 	AST_CLI_DEFINE(sip_show_user, "Show details on specific SIP user"),
+	AST_CLI_DEFINE(sip_show_sched, "Present a report on the status of the sched queue"),
 	AST_CLI_DEFINE(sip_prune_realtime, "Prune cached Realtime users/peers"),
 	AST_CLI_DEFINE(sip_do_debug, "Enable/Disable SIP debugging"),
 	AST_CLI_DEFINE(sip_do_history, "Enable SIP history"),

Modified: team/murf/bug11210/include/asterisk/dlinkedlists.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/include/asterisk/dlinkedlists.h?view=diff&rev=95623&r1=95622&r2=95623
==============================================================================
--- team/murf/bug11210/include/asterisk/dlinkedlists.h (original)
+++ team/murf/bug11210/include/asterisk/dlinkedlists.h Mon Dec 31 22:20:53 2007
@@ -826,6 +826,27 @@
 #define AST_RWDLLIST_INSERT_AFTER AST_DLLIST_INSERT_AFTER
 
 /*!
+  \brief Inserts a list entry before a given entry.
+  \param head This is a pointer to the list head structure
+  \param listelm This is a pointer to the entry before which the new entry should
+  be inserted.
+  \param elm This is a pointer to the entry to be inserted.
+  \param field This is the name of the field (declared using AST_DLLIST_ENTRY())
+  used to link entries of this list together.
+ */
+#define AST_DLLIST_INSERT_BEFORE(head, listelm, elm, field) do {		\
+	(elm)->field.next = (listelm);			\
+	(elm)->field.prev = (listelm)->field.prev;			\
+	if ((listelm)->field.prev)				\
+		(listelm)->field.prev->field.next = (elm);	\
+	(listelm)->field.prev = (elm);					\
+	if ((head)->first == (listelm))					\
+		(head)->first = (elm);					\
+} while (0)
+
+#define AST_RWDLLIST_INSERT_BEFORE AST_DLLIST_INSERT_BEFORE
+
+/*!
   \brief Inserts a list entry at the head of a list.
   \param head This is a pointer to the list head structure
   \param elm This is a pointer to the entry to be inserted.

Modified: team/murf/bug11210/include/asterisk/sched.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/include/asterisk/sched.h?view=diff&rev=95623&r1=95622&r2=95623
==============================================================================
--- team/murf/bug11210/include/asterisk/sched.h (original)
+++ team/murf/bug11210/include/asterisk/sched.h Mon Dec 31 22:20:53 2007
@@ -26,6 +26,7 @@
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
+
 
 /*! \brief Max num of schedule structs
  * \note The max number of schedule structs to keep around
@@ -58,6 +59,14 @@
 typedef int (*ast_sched_cb)(const void *data);
 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
 
+struct ast_cb_names
+{
+	int numassocs;
+	char *list[10];
+	ast_sched_cb cblist[10];
+};
+char *ast_sched_report(struct sched_context *con, char *buf, int bufsiz, struct ast_cb_names *cbnames);
+		
 /*! \brief Adds a scheduled event
  * Schedule an event to take place at some point in the future.  callback
  * will be called with data as the argument, when milliseconds into the

Modified: team/murf/bug11210/main/sched.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/main/sched.c?view=diff&rev=95623&r1=95622&r2=95623
==============================================================================
--- team/murf/bug11210/main/sched.c (original)
+++ team/murf/bug11210/main/sched.c Mon Dec 31 22:20:53 2007
@@ -192,17 +192,34 @@
  */
 static void schedule(struct sched_context *con, struct sched *s)
 {
-	 
 	struct sched *cur = NULL;
 	int ret;
-	
-	AST_DLLIST_TRAVERSE_SAFE_BEGIN(&con->schedq, cur, list) {
-		if (ast_tvcmp(s->when, cur->when) == -1) {
-			AST_DLLIST_INSERT_BEFORE_CURRENT(s, list);
-			break;
-		}
-	}
-	AST_DLLIST_TRAVERSE_SAFE_END;
+	int df = 0;
+	int de = 0;
+	struct sched *first = AST_DLLIST_FIRST(&con->schedq);
+	struct sched *last = AST_DLLIST_LAST(&con->schedq);
+	if (first)
+		df = ast_tvdiff_us(s->when, first->when);
+	if (last)
+		de = ast_tvdiff_us(s->when, last->when);
+	if (df < 0)
+		df = -df;
+	if (de < 0)
+		de = -de;
+	if (df < de)
+		AST_DLLIST_TRAVERSE(&con->schedq, cur, list) {
+			if (ast_tvcmp(s->when, cur->when) == -1) {
+				AST_DLLIST_INSERT_BEFORE(&con->schedq, cur, s, list);
+				break;
+			}
+		}
+	else
+		AST_DLLIST_TRAVERSE_BACKWARDS(&con->schedq, cur, list) {
+			if (ast_tvcmp(s->when, cur->when) == 1) {
+				AST_DLLIST_INSERT_AFTER(&con->schedq, cur, s, list);
+				break;
+			}
+		}
 	if (!cur)
 		AST_DLLIST_INSERT_TAIL(&con->schedq, s, list);
 	ret = ast_hashtab_insert_safe(con->schedq_ht, s);
@@ -468,6 +485,39 @@
 AST_DLLIST_APPEND_DLLIST(head, list, field)
 
 */
+
+char *ast_sched_report(struct sched_context *con, char *buf, int bufsiz, struct ast_cb_names *cbnames)
+{
+	int *countlist,i;
+	struct sched *cur;
+	char buf2[1200];
+	ast_sched_cb xxx = NULL;
+	
+	buf[0] = 0;
+	sprintf(buf, " Highwater = %d\n schedcnt = %d\n", con->highwater, con->schedcnt);
+	countlist = ast_calloc(sizeof(int),cbnames->numassocs+1);
+	
+	AST_DLLIST_TRAVERSE(&con->schedq, cur, list) {
+		/* match the callback to the cblist */
+		for (i=0;i<cbnames->numassocs;i++) {
+			if (cur->callback == cbnames->cblist[i])
+				break;
+		}
+		if (i < cbnames->numassocs)
+			countlist[i]++;
+		else {
+			xxx = cur->callback;
+			countlist[cbnames->numassocs]++;
+		}
+	}
+	for (i=0;i<cbnames->numassocs;i++) {
+		sprintf(buf2,"    %s : %d\n", cbnames->list[i], countlist[i]);
+		strcat(buf, buf2);
+	}
+	sprintf(buf2,"   <unknown:%p> : %d\n", xxx, countlist[cbnames->numassocs]);
+	strcat( buf, buf2);
+	return buf;
+}
 
 
 static void dll_tests(void)




More information about the asterisk-commits mailing list