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 38379)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_cbq.c	(working copy)
@@ -69,10 +69,6 @@
 #include <click/app/qos/qos_dynamic.h>
 
 
-#ifndef MORELOG
-#define MORELOG
-#endif
-
 
 /*
  * Forward Declarations.
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 38379)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/altq_rmclass.c	(working copy)
@@ -45,9 +45,6 @@
 #define ALTQ_DEBUG 1
 */
 
-#ifndef MORELOG
-#define MORELOG
-#endif
 
 #if (__FreeBSD__ != 2)
 #include "opt_inet.h"
@@ -93,6 +90,7 @@
  * Local routines.
  */
 
+
 extern int class_insert_pos;
 extern int loop_class_count;
 extern int q_len_wait;
@@ -1118,6 +1116,9 @@
 			if (top != NULL && top->avgidle_ == top->minidle_)
 				top = NULL;
 			p->overtime_ = *now;
+#ifdef MORELOG
+                        fastlog_syslog(LOG_DEBUG, "overlimit action top : %p, class : %x\n", top, cl);
+#endif
 			(p->overlimit)(p, top);
 #else
 			p->overtime_ = *now;
@@ -1156,7 +1157,6 @@
  * borrow gets to send.
  */
 
-
 static mbuf_t *
 _rmc_wrr_dequeue_next(struct rm_ifdat *ifd, int op)
 {
@@ -1228,22 +1228,26 @@
 					if (cl->bytes_alloc_ > 0 || deficit > 1) {
 						goto _wrr_out;
                                         }
+                                    deficit = 1;
+                                    ifd->borrowed_[ifd->qi_] = NULL;
 
-				} 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) {
+#ifdef MORELOG
                                         fastlog_syslog(LOG_DEBUG, "current pending mbufs for class : %x is %d.....sending out\n", cl, qlen(cl->q_));
+#endif
 					qos_filter_share.fltr_g_stats.q_overload_count[cpri]++;
 					ifd->borrowed_[ifd->qi_] = NULL;
                                         goto _wrr_out;
-                                } else if (first == NULL && cl->borrow_ != NULL)
+                                } else if (first == NULL && cl->borrow_ != NULL) {
+				    fastlog_syslog(LOG_DEBUG, "borrowing candidate : %x\n", cl);
 				    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
+				first = cl; /* if no underlimit class found, we will attempt this class */
 			}
 			cl->bytes_alloc_ = 0;
 			cl = cl->peer_;
@@ -1278,7 +1282,9 @@
 	CBQTRACE(_rmc_wrr_dequeue_next, 'otsr', ifd->cutoff_);
 
 	if (!ifd->efficient_ || first == NULL) {
-                fastlog_syslog(LOG_DEBUG, "dequeue failed. return NULL\n");
+#ifdef MORELOG
+		fastlog_syslog(LOG_DEBUG, "dequeue failed. return NULL\n");
+#endif
 		return (NULL);
         }
 	cl = first;
@@ -1393,7 +1399,7 @@
 					first = cl;
 			}
 			cl = cl->peer_;
-		} while (cl != ifd->active_[cpri]);
+		} while ((cl != NULL) && (cl != ifd->active_[cpri]));
 	}
 
 #ifdef ADJUST_CUTOFF
@@ -1794,6 +1800,10 @@
 	#endif
 			} else
 				t = 2;
+#ifdef MORELOG
+		        fastlog_syslog(LOG_DEBUG, "rmc_restart : fixing to 2 ticks appeared to have better performace at higher QoS sessions\n");
+#endif
+			t = 2;
 			CALLOUT_RESET(&cl->callout_, t,
 				      (timeout_t *)rmc_restart, (caddr_t)cl);
 		}
@@ -1825,6 +1835,7 @@
 	struct rm_ifdat	*ifd = cl->ifdat_;
 	int		 s;
 
+	fastlog_syslog(LOG_DEBUG, "rmc_restart for the class : %x\n", cl);
 #ifdef __NetBSD__
 	s = splnet();
 #else
@@ -1839,6 +1850,22 @@
 			CBQTRACE(rmc_restart, 'trts', cl->stats_.handle);
 			(ifd->restart)(ifd->ifq_);
 		}
+	        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);
 	}
 	IFQ_UNLOCK(ifd->ifq_);
 	splx(s);
@@ -1855,6 +1882,7 @@
 static void
 rmc_root_overlimit(struct rm_class *cl, struct rm_class *borrow)
 {
+    fastlog_syslog(LOG_DEBUG, "rmc_root_overlimit:PANIC\n");
     panic("rmc_root_overlimit");
 }
 
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 38379)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_dynamic.c	(working copy)
@@ -45,7 +45,7 @@
 
 int class_insert_pos = 8;
 int loop_class_count = 48;
-int q_len_wait = 1000;
+int q_len_wait = 1027; /* default value is set above 1024 which is the max queue length. We can tune this to smaller value for better performance */
 
 struct dyn_session_qos_conf_head dyn_session_qos_conf_head = STAILQ_HEAD_INITIALIZER(dyn_session_qos_conf_head);
 
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 38379)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_scheduler.h	(working copy)
@@ -43,7 +43,7 @@
 #define QOS_BORROW_DEFAULT	QOS_UNBORROW
 
 
-#define QOS_DEFAULT_QLIMIT 2048
+#define QOS_DEFAULT_QLIMIT 1024
 
 /*************************************************************************
  * STRUCTURE DEFINITIONS
Index: /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_subr.c
===================================================================
--- /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_subr.c	(revision 38379)
+++ /branches/rel_apv_10_4_0_112_gail/usr/src/sys/click/app/qos/qos_subr.c	(working copy)
@@ -197,6 +197,10 @@
 	struct rm_class *cl, *sub_cl;
 	struct qos_queue_info qosq_info;
 
+	struct ifnet    *ifp;
+	struct ifaltq *ifq;
+	cbq_state_t *cbqp;
+
 	QOS_CHECK_LICENSE;
 
 	if(!strcmp(QOS_NAME_FOR_ALL, sHwIf)) {
@@ -238,6 +242,15 @@
 
 		app_printf(pcb, "QoS statistics for interface \"%s\" %s %s\n", pQoSIfConf->sIfName, pQoSIfConf->sDir,pQoSIfConf->sBand);
 
+                ifp = ifunit(pQoSIfConf->sHwIf);
+                if (!strcmp (pQoSIfConf->sDir, "OUT")) {
+                    ifq = &ifp->if_snd;
+                } else {
+                    ifq = &ifp->if_rcv;
+                }
+                cbqp = (cbq_state_t *)ifq->altq_disc;
+                cl = cbqp->ifnp.default_;
+                qos_print_class_stat(pcb, cl);
 
 		if (!current_dyn_q_count) {
 		    STAILQ_FOREACH(pQoSQRoot, &qos_queue_root_head, list_entry) {
