tcp: optimize tcp output

Change-Id: Idf17a0633a1618b12c22b1119e40c2e9d3192df9
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vnet/session/session_debug.h b/src/vnet/session/session_debug.h
index f63509d..559f0bd 100644
--- a/src/vnet/session/session_debug.h
+++ b/src/vnet/session/session_debug.h
@@ -23,6 +23,8 @@
   _(DEQ, "dequeue")			\
   _(DEQ_NODE, "dequeue")		\
   _(POLL_GAP_TRACK, "poll gap track")	\
+  _(POLL_DISPATCH_TIME, "dispatch time")\
+  _(DISPATCH_END, "dispatch end")	\
 
 typedef enum _session_evt_dbg
 {
@@ -31,7 +33,7 @@
 #undef _
 } session_evt_dbg_e;
 
-#define SESSION_DEBUG (0 && TRANSPORT_DEBUG)
+#define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0)
 #define SESSION_DEQ_NODE_EVTS (0)
 #define SESSION_EVT_POLL_DBG (0)
 
@@ -55,6 +57,7 @@
   } * ed;								\
   ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
 
+#if SESSION_DEQ_NODE_EVTS && SESSION_DEBUG > 1
 #define SESSION_EVT_DEQ_HANDLER(_s, _body)				\
 {									\
   ELOG_TYPE_DECLARE (_e) =						\
@@ -77,7 +80,6 @@
   do { _body; } while (0);						\
 }
 
-#if SESSION_DEQ_NODE_EVTS && SESSION_DEBUG > 1
 #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)				\
 {									\
   ELOG_TYPE_DECLARE (_e) =						\
@@ -94,6 +96,8 @@
   ed->data[0] = _node_evt;						\
 }
 #else
+#define SESSION_EVT_DEQ_HANDLER(_s, _body)
+#define SESSION_EVT_ENQ_HANDLER(_s, _body)
 #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
 #endif /* SESSION_DEQ_NODE_EVTS */
 
@@ -117,11 +121,34 @@
   _smm->last_event_poll_by_thread[_ti] = now;				\
 }
 
+#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti)		\
+{									\
+  f64 diff = vlib_time_now (vlib_get_main ()) -				\
+	       _smm->last_event_poll_by_thread[_ti];			\
+  if (diff > 5e-2)							\
+    {									\
+      ELOG_TYPE_DECLARE (_e) =						\
+      {									\
+        .format = "dispatch time: %d us",				\
+        .format_args = "i4",						\
+      };								\
+      DEC_SESSION_ED(_e, 1);						\
+      ed->data[0] = diff *1000000.0;					\
+    }									\
+}
+
 #else
 #define SESSION_EVT_POLL_GAP(_smm, _my_thread_index)
 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _my_thread_index)
+#define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti)
 #endif /* SESSION_EVT_POLL_DBG */
 
+#define SESSION_EVT_DISPATCH_END_HANDLER(_smm, _ti)			\
+{									\
+  SESSION_EVT_DEQ_NODE_HANDLER(1);					\
+  SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti);			\
+}
+
 #define CONCAT_HELPER(_a, _b) _a##_b
 #define CC(_a, _b) CONCAT_HELPER(_a, _b)
 #define SESSION_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)