Index: /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm	(working copy)
@@ -53447,17 +53447,17 @@
         },
         {
                 obj_type => "ITEM",
-                name => "sessionpacketcount",
+                name => "sespacketcnt",
                 menu => "root_show_qos",
                 help_string => "show minimum packet count in a stream to create a session",
                 cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
-		user_level => "CLI_LEVEL_ENGINEER",
+                user_level => "CLI_LEVEL_ENGINEER",
                 function_name => "get_tuple_count",
                 function_args => [],
         },
         {
                 obj_type => "ITEM",
-                name => "sessionqdelstepcount",
+                name => "sesdelstep",
                 menu => "root_show_qos",
                 help_string => "show session queue delete step count",
                 cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
@@ -53467,7 +53467,7 @@
         },
         {
                 obj_type => "ITEM",
-                name => "sessionmaxcount",
+                name => "sesmaxcount",
                 menu => "root_show_qos",
                 help_string => "show max session count limit",
                 cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
@@ -53475,6 +53475,36 @@
                 function_name => "get_qos_max_session_count",
                 function_args => [],
         },
+        {
+                obj_type => "ITEM",
+                name => "qosclspos",
+                menu => "root_show_qos",
+                help_string => "show QoS class insert position",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "get_class_insert_pos",
+                function_args => [],
+        },
+        {
+                obj_type => "ITEM",
+                name => "qosclasscnt",
+                menu => "root_show_qos",
+                help_string => "show loop count to iterate over the QoS Session classes",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "get_loop_class_count",
+                function_args => [],
+        },
+        {
+                obj_type => "ITEM",
+                name => "qlenwait",
+                menu => "root_show_qos",
+                help_string => "show max outstanding mbuf allowed to be in queue",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "get_q_len_wait",
+                function_args => [],
+        },
 
         {
                 obj_type => "ITEM",
@@ -53516,7 +53546,7 @@
 
         {
                 obj_type => "ITEM",
-                name => "sessionpacketcount",
+                name => "sespacketcnt",
                 menu => "root_qos",
                 help_string => "Minimum packet count in a stream to create a session",
                 cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
@@ -53525,16 +53555,16 @@
 		function_args => [
 			{
 					type => "U32",
-					help_string => "set count [50 to 1024]",
+					help_string => "set count [1 to 1024]",
 					optional => "NO",
 			},
 		],
         },
         {
                 obj_type => "ITEM",
-                name => "sessionqdelstepcount",
+                name => "sesdelstep",
                 menu => "root_qos",
-                help_string => "set queue delete step count",
+                help_string => "set session queue delete step count",
                 cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
 		user_level => "CLI_LEVEL_ENGINEER",
                 function_name => "set_q_del_step_size",
@@ -53548,7 +53578,7 @@
         },
         {
                 obj_type => "ITEM",
-                name => "sessionmaxcount",
+                name => "sesmaxcount",
                 menu => "root_qos",
                 help_string => "set max session count limit",
                 cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API|CMD_KAPI_LOCK",
@@ -53557,7 +53587,55 @@
                 function_args => [
 			{
 					type => "U32",
-					help_string => "set count [max 50000]",
+					help_string => "set count [max 700000]",
+					optional => "NO",
+			},
+		],
+        },
+        {
+                obj_type => "ITEM",
+                name => "qosclspos",
+                menu => "root_qos",
+                help_string => "set QoS class insert position",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API|CMD_KAPI_LOCK",
+                user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "set_class_insert_pos",
+                function_args => [
+			{
+					type => "U32",
+					help_string => "set count(1 to 50000)",
+					optional => "NO",
+			},
+		],
+        },
+        {
+                obj_type => "ITEM",
+                name => "qosclasscnt",
+                menu => "root_qos",
+                help_string => "set loop count to iterate over the QoS Session classes",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API|CMD_KAPI_LOCK",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "set_loop_class_count",
+                function_args => [
+			{
+					type => "U32",
+					help_string => "set count(1 to 50000)",
+					optional => "NO",
+			},
+		],
+        },
+        {
+                obj_type => "ITEM",
+                name => "qlenwait",
+                menu => "root_qos",
+                help_string => "set max outstanding mbuf allowed to be in queue",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API|CMD_KAPI_LOCK",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "set_q_len_wait",
+                function_args => [
+			{
+					type => "U32",
+					help_string => "set count (0 to 1024)",
 					optional => "NO",
 			},
 		],
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.h	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.h	(working copy)
@@ -91,7 +91,7 @@
 #ifdef _KERNEL
 
 #ifndef MAX_DYN_QUEUE
-#define MAX_DYN_QUEUE 50000
+#define MAX_DYN_QUEUE 700000
 #endif
 
 #define	CBQ_MAX_CLASSES	(MAX_DYN_QUEUE + 1024)
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.c	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.c	(working copy)
@@ -65,6 +65,8 @@
 #ifdef __QOS_COMPILED__
 #include <click/app/qos/altq_cbq.h>
 
+#include <click/app/fastlog/fastlog.h>
+
 /*
  * Forward Declarations.
  */
@@ -556,6 +558,7 @@
 
 	len = m_pktlen(m);
 	if (rmc_queue_packet(cl, m) != 0) {
+                fastlog_syslog(LOG_DEBUG, "error queueing the packets. Current queue length %d\n", cl->q_->qlen_);
 		/* drop occurred.  some mbuf was freed in rmc_queue_packet. */
 		PKTCNTR_ADD(&cl->stats_.drop_cnt, len);
 		return (ENOBUFS);
@@ -575,6 +578,10 @@
 
 	IFQ_LOCK_ASSERT(ifq);
 
+        if ((op == ALTDQ_REMOVE) && (cbqp->cbq_qlen <= 0)) {
+            return NULL;
+        }
+
 	m = rmc_dequeue_next(&cbqp->ifnp, op);
 
 	if (m && op == ALTDQ_REMOVE) {
@@ -583,7 +590,16 @@
 
 		/* Update the class. */
 		rmc_update_class_util(&cbqp->ifnp);
+#ifdef MORELOG
+                fastlog_syslog(LOG_DEBUG, "cbq_dequeue : no of outstanding packets to be dequeued : %d\n", cbqp->cbq_qlen);
+#endif
 	}
+
+#ifdef MORELOG
+        if (!m) {
+            fastlog_syslog(LOG_DEBUG, "cbq_dequeue : no packet to dequue, no of outstanding packets to be dequeued : %d\n", cbqp->cbq_qlen);
+        }
+#endif
 	return (m);
 }
 
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.h	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.h	(working copy)
@@ -192,6 +192,7 @@
 	rm_class_t	*next_;		/* Next pointer, used if child */
 
 	rm_class_t	*peer_;		/* Peer class */
+	rm_class_t	*prev_peer_;	/* Previous Peer class */
 	rm_class_t	*borrow_;	/* Borrow class */
 	rm_class_t	*parent_;	/* Parent class */
 
@@ -227,6 +228,7 @@
 	int		qi_;		/* In/out pointers for downstream */
 	int		qo_;		/* packets */
 
+        struct  mtx lock;
 	/*
 	 * Active class state and WRR state.
 	 */
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.c	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.c	(working copy)
@@ -74,16 +74,24 @@
 #include <click/app/qos/altq_rmclass.h>
 #include <click/app/qos/altq_red.h>
 
+#include <sys/syslog.h>
+#include <click/app/qos/qos_dynamic.h>
 /*
  * Local Macros
  */
 
 #define	reset_cutoff(ifd)	{ ifd->cutoff_ = RM_MAXDEPTH; }
 
+
 /*
  * Local routines.
  */
 
+extern int class_insert_pos;
+extern int loop_class_count;
+extern int q_len_wait;
+
+
 static int	rmc_satisfied(struct rm_class *, struct timeval *);
 static void	rmc_wrr_set_weights(struct rm_ifdat *);
 static void	rmc_depth_compute(struct rm_class *);
@@ -326,6 +334,7 @@
 	struct rm_class	*cl;
 	struct rm_class	*peer;
 	int		 s;
+	int ncount = 0;
 
 	if (pri >= RM_MAXPRIO)
 		return (NULL);
@@ -453,15 +462,23 @@
 	s = splimp();
 #endif
 	IFQ_LOCK(ifd->ifq_);
+	mtx_lock(&ifd->lock);
 	if ((peer = ifd->active_[pri]) != NULL) {
-		/* find the last class at this pri */
-		cl->peer_ = peer;
-		while (peer->peer_ != ifd->active_[pri])
+		while (peer->peer_ != NULL && ++ncount < class_insert_pos)
 			peer = peer->peer_;
-		peer->peer_ = cl;
+                if (peer->peer_ == NULL) {
+	            peer->peer_ = cl;
+                    cl->prev_peer_ = peer;
+		    cl->peer_ = NULL;
+                } else {
+                        cl->peer_ = peer->peer_;
+                        peer->peer_ = cl;
+                        cl->prev_peer_ = peer;
+                }
 	} else {
+		cl->peer_ = NULL;
+                cl->prev_peer_ = NULL;
 		ifd->active_[pri] = cl;
-		cl->peer_ = cl;
 	}
 
 	if (cl->parent_) {
@@ -482,8 +499,9 @@
 	if (ifd->wrr_) {
 		ifd->num_[pri]++;
 		ifd->alloc_[pri] += cl->allotment_;
-		rmc_wrr_set_weights(ifd);
+		cl->w_allotment_ = cl->allotment_;
 	}
+        mtx_unlock(&ifd->lock);
 	IFQ_UNLOCK(ifd->ifq_);
 	splx(s);
 	return (cl);
@@ -747,22 +765,22 @@
 	/*
 	 * Delete class from class priority peer list.
 	 */
-	if ((p = ifd->active_[cl->pri_]) != NULL) {
+	if ((ifd->active_[cl->pri_]) != NULL) {
 		/*
 		 * If there is more than one member of this priority
 		 * level, then look for class(cl) in the priority level.
 		 */
-		if (p != p->peer_) {
-			while (p->peer_ != cl)
-				p = p->peer_;
-			p->peer_ = cl->peer_;
-
-			if (ifd->active_[cl->pri_] == cl)
-				ifd->active_[cl->pri_] = cl->peer_;
-		} else {
-			ALTQ_ASSERT(p == cl);
-			ifd->active_[cl->pri_] = NULL;
-		}
+                if (cl == ifd->active_[cl->pri_]) {
+                    ifd->active_[cl->pri_] = cl->peer_;
+                    if (cl->peer_) {
+                        cl->peer_->prev_peer_ = NULL;
+                    }
+                } else {
+                     if (cl->prev_peer_)
+                        cl->prev_peer_->peer_ = cl->peer_;
+                     if (cl->peer_)
+                        cl->peer_->prev_peer_ = cl->prev_peer_;
+                }
 	}
 
 	/*
@@ -771,7 +789,7 @@
 	if (ifd->wrr_) {
 		ifd->alloc_[cl->pri_] -= cl->allotment_;
 		ifd->num_[cl->pri_]--;
-		rmc_wrr_set_weights(ifd);
+		cl->w_allotment_ = cl->allotment_;
 	}
 
 	/*
@@ -842,6 +860,7 @@
 	ifd->ns_per_byte_ = nsecPerByte;
 	ifd->maxpkt_ = mtu;
 	ifd->wrr_ = (flags & RMCF_WRR) ? 1 : 0;
+        mtx_init(&ifd->lock, "qos cbq interface lock", NULL, MTX_DEF | MTX_NOWITNESS);
 	ifd->efficient_ = (flags & RMCF_EFFICIENT) ? 1 : 0;
 #if 1
 	ifd->maxiftime_ = mtu * nsecPerByte / 1000 * 16;
@@ -899,6 +918,7 @@
  *	Returns:	0 on successful queueing
  *			-1 when packet drop occurs
  */
+
 int
 rmc_queue_packet(struct rm_class *cl, mbuf_t *m)
 {
@@ -944,9 +964,11 @@
 #endif /* !ALTQ */
 	}
 
-	if (_rmc_addq(cl, m) < 0)
+	if (_rmc_addq(cl, m) < 0) {
 		/* failed */
+                fastlog_syslog(LOG_DEBUG, "rmc_queue_packet : FAILED to enqueue mbuf for the class : %x\n", cl);
 		return (-1);
+        }
 
 	if (is_empty) {
 		CBQTRACE(rmc_queue_packet, 'ytpe', cl->stats_.handle);
@@ -955,9 +977,29 @@
 
 	if (qlen(cl->q_) > qlimit(cl->q_)) {
 		/* note: qlimit can be set to 0 or 1 */
+                fastlog_syslog(LOG_DEBUG, "mbuf DROP action for class : %x. Pending mbuf's : %d. Max allowed mbuf's : %d\n", cl, qlen(cl->q_), qlimit(cl->q_));
 		rmc_drop_action(cl);
 		return (-1);
 	}
+#ifdef MORELOG
+	fastlog_syslog(LOG_DEBUG, "rmc_queue_packet : mbuf enqueued for the class : %x\n", cl);
+#endif
+	mtx_lock(&ifd->lock);
+	if (cl == ifd->active_[cl->pri_])
+	    ;
+	else {
+	    if (cl->prev_peer_ != NULL )
+		cl->prev_peer_->peer_ = cl->peer_;
+	    if (cl->peer_ != NULL)
+		cl->peer_->prev_peer_ = cl->prev_peer_;
+	    cl->peer_ = ifd->active_[cl->pri_]->peer_;
+	    ifd->active_[cl->pri_]->peer_ = cl;
+	    cl->prev_peer_ = ifd->active_[cl->pri_];
+	    if (cl->peer_) {
+		cl->peer_->prev_peer_ = cl;
+	    }
+	} 
+	mtx_unlock(&ifd->lock);
 	return (0);
 }
 
@@ -982,7 +1024,7 @@
 					return;
 				}
 				p = p->peer_;
-			} while (p != bp);
+			} while (p != NULL);
 		}
 	}
 
@@ -1038,19 +1080,20 @@
 	 * If cl is the root class, then always return that it is
 	 * underlimit.  Otherwise, check to see if the class is underlimit.
 	 */
-	if (cl->parent_ == NULL)
+	if (cl->parent_ == NULL) {
 		return (1);
-
+        }
 	top = NULL;
 	while (cl->undertime_.tv_sec && TV_LT(now, &cl->undertime_)) {
 		if (((cl = cl->borrow_) == NULL) ||
 		    (cl->depth_ > ifd->cutoff_)) {
 #ifdef ADJUST_CUTOFF
-			if (cl != NULL)
+			if (cl != NULL) {
 				/* cutoff is taking effect, just
 				   return false without calling
 				   the delay action. */
 				return (0);
+                        }
 #endif
 #ifdef BORROW_OFFTIME
 			/*
@@ -1104,6 +1147,7 @@
  * borrow gets to send.
  */
 
+
 static mbuf_t *
 _rmc_wrr_dequeue_next(struct rm_ifdat *ifd, int op)
 {
@@ -1113,6 +1157,8 @@
 	mbuf_t		*m;
 	struct timeval	 now;
 
+	u_int		 loop_ct;
+
 	RM_GETTIME(now);
 
 	/*
@@ -1143,6 +1189,7 @@
 		if (ifd->na_[cpri] == 0)
 			continue;
 		deficit = 0;
+                loop_ct = 0;
 		/*
 		 * Loop through twice for a priority level, if some class
 		 * was unable to send a packet the first round because
@@ -1154,29 +1201,47 @@
 		 */
  _wrr_loop:
 		cl = ifd->active_[cpri];
+                if (cl == NULL) {
+                    fastlog_syslog(LOG_DEBUG, "_rmc_wrr_dequeue_next : no active mbuf to process\n");
+                    return NULL;
+                }
+#ifdef MORELOG
+                fastlog_syslog(LOG_DEBUG, "_rmc_wrr_dequeue_next : 1st class to process: %x\n", cl);
+#endif
 		ALTQ_ASSERT(cl != NULL);
 		do {
-			if ((deficit < 2) && (cl->bytes_alloc_ <= 0))
+                        ++loop_ct;
+#ifdef MORELOG
+                        fastlog_syslog(LOG_DEBUG, "loop cl addr : %x\ncurrent loop count : %u\n", cl, loop_ct);
+#endif
+			if ((deficit < 2) && (cl->bytes_alloc_ <= 0)) {
 				cl->bytes_alloc_ += cl->w_allotment_;
+			}
 			if (!qempty(cl->q_)) {
 				if ((cl->undertime_.tv_sec == 0) ||
 				    rmc_under_limit(cl, &now)) {
-					if (cl->bytes_alloc_ > 0 || deficit > 1)
+					if (cl->bytes_alloc_ > 0 || deficit > 1) {
 						goto _wrr_out;
+                                        }
 
-					/* underlimit but no alloc */
-					deficit = 1;
-#if 1
+				} else if (first == NULL && cl->borrow_ != NULL) {
+                                        fastlog_syslog(LOG_DEBUG, "borrowing candidate : %x\n", cl);
+					first = cl; /* borrowing candidate */
+                                } else if (qlen(cl->q_) >= q_len_wait) {
+                                        fastlog_syslog(LOG_DEBUG, "queue len for class : %x is %d..sending it out\n", cl, qlen(cl->q_));
 					ifd->borrowed_[ifd->qi_] = NULL;
+                                        goto _wrr_out;
+                                } else if (first == NULL && cl->borrow_ != NULL)
+				    first = cl; /* borrowing candidate */
+#ifdef MORELOG
+                                else {
+                                        fastlog_syslog(LOG_DEBUG, "queue not empty but will not process, as it is overlimit class : %x, qlen is %d\n", cl, qlen(cl->q_));
+                                }
 #endif
-				}
-				else if (first == NULL && cl->borrow_ != NULL)
-					first = cl; /* borrowing candidate */
 			}
-
 			cl->bytes_alloc_ = 0;
 			cl = cl->peer_;
-		} while (cl != ifd->active_[cpri]);
+		} while (cl != NULL && loop_ct <= loop_class_count); // while (cl != ifd->active_[cpri]);
 
 		if (deficit == 1) {
 			/* first loop found an underlimit class with deficit */
@@ -1205,9 +1270,10 @@
 	reset_cutoff(ifd);
 	CBQTRACE(_rmc_wrr_dequeue_next, 'otsr', ifd->cutoff_);
 
-	if (!ifd->efficient_ || first == NULL)
+	if (!ifd->efficient_ || first == NULL) {
+                fastlog_syslog(LOG_DEBUG, "dequeue failed. return NULL\n");
 		return (NULL);
-
+        }
 	cl = first;
 	cpri = cl->pri_;
 #if 0	/* too time-consuming for nothing */
@@ -1223,23 +1289,41 @@
 	 * Deque the packet and do the book keeping...
 	 */
  _wrr_out:
+
+
 	if (op == ALTDQ_REMOVE) {
 		m = _rmc_getq(cl);
-		if (m == NULL)
+		if (m == NULL) {
+                        fastlog_syslog(LOG_DEBUG, "panic in _rmc_getq\n");
 			panic("_rmc_wrr_dequeue_next");
-		if (qempty(cl->q_))
+                }
+#ifdef MORELOG
+                fastlog_syslog(LOG_DEBUG, "DEQUEUE done for the class : %x but still : %d mbuf remaining....\n", cl, qlen(cl->q_));
+#endif
+                mtx_lock(&ifd->lock);
+		if (qempty(cl->q_)) {
 			ifd->na_[cpri]--;
+#ifdef MORELOG
+                        fastlog_syslog(LOG_DEBUG, "all packets empty for one of the class : %x. total class's in priority %d is %d\n", cl, cpri, ifd->na_[cpri]);
+#endif
+                }
+                else if (cl == ifd->active_[cl->pri_]) ;
+                else {
+                        if (cl->prev_peer_ != NULL )
+                            cl->prev_peer_->peer_ = cl->peer_;
+                        if (cl->peer_ != NULL) {
+                            cl->peer_->prev_peer_ = cl->prev_peer_;
+                        }
+                        cl->prev_peer_ = NULL;
+                        cl->peer_ = ifd->active_[cl->pri_];
+	                ifd->active_[cl->pri_]->prev_peer_ = cl;
+			ifd->active_[cl->pri_] = cl;
+                }
+                mtx_unlock(&ifd->lock);
 
 		/*
 		 * Update class statistics and link data.
 		 */
-		if (cl->bytes_alloc_ > 0)
-			cl->bytes_alloc_ -= m_pktlen(m);
-
-		if ((cl->bytes_alloc_ <= 0) || first == cl)
-			ifd->active_[cl->pri_] = cl->peer_;
-		else
-			ifd->active_[cl->pri_] = cl;
 
 		ifd->class_[ifd->qi_] = cl;
 		ifd->curlen_[ifd->qi_] = m_pktlen(m);
@@ -1377,12 +1461,16 @@
 mbuf_t *
 rmc_dequeue_next(struct rm_ifdat *ifd, int mode)
 {
-	if (ifd->queued_ >= ifd->maxqueued_)
+	if (ifd->queued_ >= ifd->maxqueued_) {
+                fastlog_syslog(LOG_DEBUG, "classes are ovelimit not dequeuing. current size : %d.  max : %d\n", ifd->queued_, ifd->maxqueued_);
 		return (NULL);
-	else if (ifd->wrr_)
+        }
+	else if (ifd->wrr_) {
 		return (_rmc_wrr_dequeue_next(ifd, mode));
-	else
+        }
+	else {
 		return (_rmc_prr_dequeue_next(ifd, mode));
+        }
 }
 
 /*
@@ -1641,6 +1729,9 @@
 	int	delay, t, extradelay;
 
 	do {
+#ifdef MORELOG
+                fastlog_syslog(LOG_DEBUG, "rmc_delay_action for class : %x\n", cl);
+#endif
 		cl->stats_.overactions++;
 
 		if (!cl->sleeping_) {
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_subr.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_subr.c	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_subr.c	(working copy)
@@ -54,6 +54,7 @@
 #include <sys/sysctl.h>
 #include <sys/queue.h>
 #include <sys/pcpu.h>
+#include <click/app/fastlog/fastlog.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -280,8 +281,10 @@
 			tbr->tbr_last = now;
 		}
 		/* if token is still negative, don't allow dequeue */
-		if (tbr->tbr_token <= 0)
+		if (tbr->tbr_token <= 0) {
+			fastlog_syslog(LOG_DEBUG, "token is still negative, don't allow dequeue\n");
 			return (NULL);
+                }
 	}
 
 	if (ALTQ_IS_ENABLED(ifq))
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.h	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.h	(working copy)
@@ -36,7 +36,7 @@
 
 
 #ifndef MAX_DYN_QUEUE
-#define MAX_DYN_QUEUE 50000
+#define MAX_DYN_QUEUE 700000
 #endif
 
 #define QOS_MAX_FLTR_NUM (MAX_DYN_QUEUE + 1024)
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c	(working copy)
@@ -58,7 +58,7 @@
 #include <click/app/qos/qos_dynamic.h>
 
 #ifndef MAX_DYN_QUEUE
-#define MAX_DYN_QUEUE 50000
+#define MAX_DYN_QUEUE 700000
 #endif
 
 extern uint32_t max_dyn_queue;
@@ -1133,6 +1133,10 @@
 	*/
 	bcopy(qos_filter, pfltr, sizeof(qos_filter_t));
 
+	pfltr->used = 1;
+	++n_filters;
+	mtx_unlock (&qos_filter_lock);
+
 	ret = qos_filter_add_table(qs, pfltr);
 	if(QOS_FAILURE == ret) {
 	    bzero(pfltr, sizeof(qos_filter_t));
@@ -1142,9 +1146,6 @@
 	    goto ADD_FLTR_ERROR;
 	}
 
-	pfltr->used = 1;
-	++n_filters;
-	mtx_unlock (&qos_filter_lock);
 	return QOS_SUCCESS;
 
 ADD_FLTR_ERROR:
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h	(working copy)
@@ -32,6 +32,11 @@
 
 extern uint32_t max_dyn_queue;
 
+//CBQ
+extern int class_insert_pos;
+extern int loop_class_count;
+extern int q_len_wait;
+
 typedef struct dyn_qos_session_lookup {
     struct dyn_qos_session_lookup *dyn_qos_session_lookup_node[N_CHILDREN];
     qos_queue_root_t *qos_session_q_save;
@@ -66,3 +71,12 @@
 int qos_session_init (void);
 int set_qos_max_session_count (void *pcb, uint32_t count);
 int get_qos_max_session_count (void *pcb);
+
+int set_loop_class_count (void *pcb, uint32_t count);
+int get_loop_class_count (void *pcb);
+
+int set_class_insert_pos (void *pcb, uint32_t count);
+int get_class_insert_pos (void *pcb);
+
+int set_q_len_wait (void *pcb, uint32_t count);
+int get_q_len_wait (void *pcb);
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c	(working copy)
@@ -29,7 +29,7 @@
 #define TUPLE_LEN 12 /* src ip + src port + dest ip + dst port */
 
 #ifndef MAX_DYN_QUEUE
-#define MAX_DYN_QUEUE 50000
+#define MAX_DYN_QUEUE 700000
 #endif
 
 struct mtx qos_session_lock;
@@ -41,6 +41,10 @@
 uint32_t q_del_step_size = 1;
 uint32_t max_dyn_queue = MAX_DYN_QUEUE;
 
+int class_insert_pos = 105;
+int loop_class_count = 100;
+int q_len_wait = 512;
+
 struct dyn_session_qos_conf_head dyn_session_qos_conf_head = STAILQ_HEAD_INITIALIZER(dyn_session_qos_conf_head);
 
 dyn_qos_session_lookup_t *dyn_qos_session_lookup_root = NULL;
@@ -456,3 +460,33 @@
     app_printf(pcb, "count : %u\n", max_dyn_queue);
     return QOS_SUCCESS;
 }
+
+int set_loop_class_count (void *pcb, uint32_t count) {
+    loop_class_count = count;
+    return QOS_SUCCESS;
+}
+
+int get_loop_class_count (void *pcb) {
+    app_printf(pcb, "loop_class_count : %u\n", loop_class_count);
+    return QOS_SUCCESS;
+}
+
+int set_class_insert_pos (void *pcb, uint32_t count) {
+    class_insert_pos = count;
+    return QOS_SUCCESS;
+}
+
+int get_class_insert_pos (void *pcb) {
+    app_printf(pcb, "class_insert_pos : %u\n", class_insert_pos);
+    return QOS_SUCCESS;
+}
+
+int set_q_len_wait (void *pcb, uint32_t count) {
+    q_len_wait = count;
+    return QOS_SUCCESS;
+}
+
+int get_q_len_wait (void *pcb) {
+    app_printf(pcb, "q_len_wait : %u\n", q_len_wait);
+    return QOS_SUCCESS;
+}
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h	(working copy)
@@ -42,9 +42,8 @@
 
 #define QOS_BORROW_DEFAULT	QOS_UNBORROW
 
-/* QoS queue size limit. It is recommend not to create Queues (except 'default queues') when 'QoS Session' feature is enabled. */
 
-#define QOS_DEFAULT_QLIMIT (MAX_DYN_QUEUE + 100)
+#define QOS_DEFAULT_QLIMIT 2048
 
 /*************************************************************************
  * STRUCTURE DEFINITIONS
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_var.h
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_var.h	(revision 38255)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_var.h	(working copy)
@@ -46,7 +46,7 @@
 
 /* QoS maximum queue */
 #ifndef MAX_DYN_QUEUE
-#define MAX_DYN_QUEUE 50000
+#define MAX_DYN_QUEUE 700000
 #endif
 
 #define QOS_MAXQ (MAX_DYN_QUEUE + 1024)
