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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/click/lib/libparser/commands.pm	(working copy)
@@ -53505,6 +53505,26 @@
                 function_name => "get_q_len_wait",
                 function_args => [],
         },
+        {
+                obj_type => "ITEM",
+                name => "dequeuerepeat",
+                menu => "root_show_qos",
+                help_string => "show mbuf dequeue iterate count",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "get_dequeue_repeat",
+                function_args => [],
+        },
+        {
+                obj_type => "ITEM",
+                name => "getmaxpendmbuf",
+                menu => "root_show_qos",
+                help_string => "show max pend mbuf",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "get_max_pend_mbuf",
+                function_args => [],
+        },
 
         {
                 obj_type => "ITEM",
@@ -53598,7 +53618,7 @@
                 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",
+		user_level => "CLI_LEVEL_ENGINEER",
                 function_name => "set_class_insert_pos",
                 function_args => [
 			{
@@ -53639,6 +53659,38 @@
 					optional => "NO",
 			},
 		],
+        },
+        {
+                obj_type => "ITEM",
+                name => "dequeuerepeat",
+                menu => "root_qos",
+                help_string => "set mbuf dequeue iterate count",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API|CMD_KAPI_LOCK",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "set_dequeue_repeat",
+                function_args => [
+			{
+					type => "U32",
+					help_string => "set count (1 to 1024)",
+					optional => "NO",
+			},
+		],
+        },
+        {
+                obj_type => "ITEM",
+                name => "maxpendmbuf",
+                menu => "root_qos",
+                help_string => "set max pend mbuf",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API|CMD_KAPI_LOCK",
+		user_level => "CLI_LEVEL_ENGINEER",
+                function_name => "set_max_pend_mbuf",
+                function_args => [
+			{
+					type => "U32",
+					help_string => "set count (1 to 1024)",
+					optional => "NO",
+			},
+		],
         },
 
 	{
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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.c	(working copy)
@@ -66,6 +66,14 @@
 #include <click/app/qos/altq_cbq.h>
 
 #include <click/app/fastlog/fastlog.h>
+#include <click/app/qos/qos_dynamic.h>
+
+extern int max_pend_mbuf;
+
+#ifndef MORELOG
+#define MORELOG
+#endif
+
 
 /*
  * Forward Declarations.
@@ -582,7 +590,15 @@
             return NULL;
         }
 
-	m = rmc_dequeue_next(&cbqp->ifnp, op);
+	if (max_pend_mbuf) {
+	    if (cbqp->cbq_qlen >= max_pend_mbuf)
+		m = rmc_dequeue_next(&cbqp->ifnp, op, 1);
+	    else
+		m = rmc_dequeue_next(&cbqp->ifnp, op, 0);
+	} else {
+		m = rmc_dequeue_next(&cbqp->ifnp, op, 0);
+	}
+            
 
 	if (m && op == ALTDQ_REMOVE) {
 		--cbqp->cbq_qlen;  /* decrement # of packets in cbq */
@@ -597,7 +613,7 @@
 
 #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);
+            fastlog_syslog(LOG_DEBUG, "cbq_dequeue : %x - no packet to dequue, no of outstanding packets to be dequeued : %d\n", cbqp, 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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.h	(working copy)
@@ -294,7 +294,7 @@
 			 void (*)(struct ifaltq *),
 			 int, int, u_int, int, u_int, int);
 extern int	rmc_queue_packet(struct rm_class *, mbuf_t *);
-extern mbuf_t	*rmc_dequeue_next(struct rm_ifdat *, int);
+extern mbuf_t	*rmc_dequeue_next(struct rm_ifdat *, int, int);
 extern void	rmc_update_class_util(struct rm_ifdat *);
 extern void	rmc_delay_action(struct rm_class *, struct rm_class *);
 extern void	rmc_dropall(struct rm_class *);
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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.c	(working copy)
@@ -45,6 +45,10 @@
 #define ALTQ_DEBUG 1
 */
 
+#ifndef MORELOG
+#define MORELOG
+#endif
+
 #if (__FreeBSD__ != 2)
 #include "opt_inet.h"
 #ifdef __FreeBSD__
@@ -97,7 +101,7 @@
 static void	rmc_depth_compute(struct rm_class *);
 static void	rmc_depth_recompute(rm_class_t *);
 
-static mbuf_t	*_rmc_wrr_dequeue_next(struct rm_ifdat *, int);
+static mbuf_t	*_rmc_wrr_dequeue_next(struct rm_ifdat *, int, int);
 static mbuf_t	*_rmc_prr_dequeue_next(struct rm_ifdat *, int);
 
 static int	_rmc_addq(rm_class_t *, mbuf_t *);
@@ -1149,7 +1153,7 @@
 
 
 static mbuf_t *
-_rmc_wrr_dequeue_next(struct rm_ifdat *ifd, int op)
+_rmc_wrr_dequeue_next(struct rm_ifdat *ifd, int op, int send)
 {
 	struct rm_class	*cl = NULL, *first = NULL;
 	u_int		 deficit;
@@ -1212,7 +1216,7 @@
 		do {
                         ++loop_ct;
 #ifdef MORELOG
-                        fastlog_syslog(LOG_DEBUG, "loop cl addr : %x\ncurrent loop count : %u\n", cl, loop_ct);
+                        fastlog_syslog(LOG_DEBUG, "loop cl addr : %x ==> current loop count : %u ==> deficit : %u\n", cl, loop_ct, deficit);
 #endif
 			if ((deficit < 2) && (cl->bytes_alloc_ <= 0)) {
 				cl->bytes_alloc_ += cl->w_allotment_;
@@ -1227,8 +1231,8 @@
 				} 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_));
+                                } else if ( (qlen(cl->q_) >= q_len_wait) || send) {
+                                        fastlog_syslog(LOG_DEBUG, "queue len for class : %x is %d and send : %d..sending it out\n", cl, qlen(cl->q_), send);
 					ifd->borrowed_[ifd->qi_] = NULL;
                                         goto _wrr_out;
                                 } else if (first == NULL && cl->borrow_ != NULL)
@@ -1459,14 +1463,14 @@
  */
 
 mbuf_t *
-rmc_dequeue_next(struct rm_ifdat *ifd, int mode)
+rmc_dequeue_next(struct rm_ifdat *ifd, int mode, int send)
 {
 	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_) {
-		return (_rmc_wrr_dequeue_next(ifd, mode));
+		return (_rmc_wrr_dequeue_next(ifd, mode, send));
         }
 	else {
 		return (_rmc_prr_dequeue_next(ifd, mode));
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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_classifier.c	(working copy)
@@ -1133,6 +1133,7 @@
 	*/
 	bcopy(qos_filter, pfltr, sizeof(qos_filter_t));
 
+
 	pfltr->used = 1;
 	++n_filters;
 	mtx_unlock (&qos_filter_lock);
@@ -1141,8 +1142,9 @@
 	if(QOS_FAILURE == ret) {
 	    bzero(pfltr, sizeof(qos_filter_t));
 	    qos_filter_share.fltr_g_stats.count_add_table_fail++;
+	    pfltr->used = 0;
+	    --n_filters;
 	    fastlog_syslog(LOG_DEBUG, "ERROR: failed to add the filter to the table\n");
-	    mtx_unlock (&qos_filter_lock);
 	    goto 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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.h	(working copy)
@@ -25,12 +25,14 @@
 
 extern struct dyn_session_qos_conf_head dyn_session_qos_conf_head;
 extern int qos_session_status;
+extern int dequeue_repeat;
 extern uint32_t repeat_segment_num;
 extern uint32_t q_del_step_size;
 extern struct mtx qos_session_lock;
 extern struct mtx qos_filter_lock;
 
 extern uint32_t max_dyn_queue;
+extern int max_pend_mbuf;
 
 //CBQ
 extern int class_insert_pos;
@@ -80,3 +82,9 @@
 
 int set_q_len_wait (void *pcb, uint32_t count);
 int get_q_len_wait (void *pcb);
+
+int set_dequeue_repeat (void *pcb, uint32_t count);
+int get_dequeue_repeat (void *pcb);
+
+int set_max_pend_mbuf (void *pcb, uint32_t count);
+int get_max_pend_mbuf (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 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c	(working copy)
@@ -36,13 +36,16 @@
 struct mtx qos_filter_lock;
 
 int qos_session_status = SESSION_DISABLE;
+int dequeue_repeat = 2;
+
+int max_pend_mbuf = 0;
 
 uint32_t repeat_segment_num = 50;
 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 class_insert_pos = 205;
+int loop_class_count = 200;
 int q_len_wait = 512;
 
 struct dyn_session_qos_conf_head dyn_session_qos_conf_head = STAILQ_HEAD_INITIALIZER(dyn_session_qos_conf_head);
@@ -490,3 +493,23 @@
     app_printf(pcb, "q_len_wait : %u\n", q_len_wait);
     return QOS_SUCCESS;
 }
+
+int set_dequeue_repeat (void *pcb, uint32_t count) {
+    dequeue_repeat = count;
+    return QOS_SUCCESS;
+}
+
+int get_dequeue_repeat (void *pcb) {
+    app_printf(pcb, "count : %u\n", dequeue_repeat);
+    return QOS_SUCCESS;
+}
+
+int set_max_pend_mbuf (void *pcb, uint32_t count) {
+    max_pend_mbuf = count;
+    return QOS_SUCCESS;
+}
+
+int get_max_pend_mbuf (void *pcb) {
+    app_printf(pcb, "count : %d\n", max_pend_mbuf);
+    return QOS_SUCCESS;
+}
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.c	(revision 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.c	(working copy)
@@ -66,6 +66,7 @@
 extern int qos_session_cleanup;
 extern struct mtx qos_session_lock;
 extern unsigned int current_dyn_q_count;
+extern int dequeue_repeat;
 
 /* QoS qid generator */
 static uint32_t qos_index = 0;
@@ -124,6 +125,7 @@
 	/* Find in sub queue list */
 	for(;;){
 		STAILQ_FOREACH(pQoSQSub, &qos_queue_sub_head, list_entry) {
+	                fastlog_syslog(LOG_DEBUG, "qos_queue_get: qos sub\n");
 			if (strcmp(pParent, pQoSQSub->sQName) == 0) {
 				if (NULL == pQoSQSubFirst) {
 					pQoSQSubFirst = pQoSQSub;
@@ -181,6 +183,7 @@
 		pQoSQSubFirst->ref_cnt++;
 	    }
 	}
+
 	return(QOS_SUCCESS);
 }
 
@@ -250,22 +253,32 @@
  *
  * return: VOID.
  *************************************************************************/
+
 void qos_start(struct ifnet *ifp)
 {
 	struct mbuf *m_head;
         char temp;
+        int i;
 
 	while (!IFQ_IS_EMPTY(&ifp->if_rcv)) {
 		if (ifp->if_rcv.ifq_head != NULL) {
 			IF_DEQUEUE(&ifp->if_rcv, m_head);
+		        if (m_head == NULL) { break; }
+		            (*ifp->if_input)(ifp, m_head);
 		} else {
-			IF_LOCK(&ifp->if_rcv);
-			m_head = tbr_dequeue_ptr(&ifp->if_rcv, ALTDQ_REMOVE);
+		        IF_LOCK(&ifp->if_rcv);
+                        for (i = 1; i <= dequeue_repeat; i++) {
+			    m_head = tbr_dequeue_ptr(&ifp->if_rcv, ALTDQ_REMOVE);
+		            if (m_head == NULL) { 
+                                break; 
+                            } else {
+		                (*ifp->if_input)(ifp, m_head);
+                            }
+                        }
 			IF_UNLOCK(&ifp->if_rcv);
+                        if (m_head == NULL)
+                            break;
 		}
-		if (m_head == NULL) { break; }
-
-		(*ifp->if_input)(ifp, m_head);
 	}
 
 	return;
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/netinet/click_rule.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/netinet/click_rule.c	(revision 38270)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/netinet/click_rule.c	(working copy)
@@ -2190,6 +2190,7 @@
 		return 0;
 	}
 	/* find the same from the clickrule_group_t singly-linked list */
+#if 0
 	gh_p = clickrule_group_find(grh_p, newgh_p);
 	if (!gh_p) { /* we need to use created group */
 		clickrule_group_insert(grh_p, newgh_p);
@@ -2200,6 +2201,12 @@
 		*gh_pp = gh_p;
 		gh_p->references++;
 	}
+#endif
+#if 1
+	clickrule_group_insert(grh_p, newgh_p);
+	*gh_pp = newgh_p;
+	newgh_p->references++;
+#endif
 	/* decrease the references for group */
 	if (oldgh_p && oldgh_p->references) {
 		oldgh_p->references--;
@@ -2369,6 +2376,7 @@
 	clickrule_group_t	*pp = NULL;
 	clickrule_group_t	*cp = SLIST_FIRST(grh_p);
 
+#if 0
 	/* find place to insert */
 	while (cp && cp->priority <= g_p->priority) {
 		pp = cp;
@@ -2380,6 +2388,10 @@
 	} else {
 		SLIST_INSERT_HEAD(grh_p, g_p, next_p);
 	}
+#endif
+#if 1
+        SLIST_INSERT_HEAD(grh_p, g_p, next_p);
+#endif
 }
 
 /*
