tcp: improve pacing after idle send periods

Rest pacer on ack reception if we haven't recently sent anything.

Type: feature

Change-Id: I820bacd81b65130052dfafbfcbe6ca4553069fbc
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vnet/session/session_node.c b/src/vnet/session/session_node.c
index 9e53718..f51b892 100644
--- a/src/vnet/session/session_node.c
+++ b/src/vnet/session/session_node.c
@@ -845,6 +845,7 @@
     {
       if (ctx->transport_vft->flush_data)
 	ctx->transport_vft->flush_data (ctx->tc);
+      e->event_type = SESSION_IO_EVT_TX;
     }
 
   if (ctx->s->flags & SESSION_F_CUSTOM_TX)
@@ -883,7 +884,12 @@
   session_tx_set_dequeue_params (vm, ctx, max_burst, peek_data);
 
   if (PREDICT_FALSE (!ctx->max_len_to_snd))
-    return SESSION_TX_NO_DATA;
+    {
+      transport_connection_tx_pacer_reset_bucket (ctx->tc,
+						  vm->clib_time.
+						  last_cpu_time);
+      return SESSION_TX_NO_DATA;
+    }
 
   n_bufs_needed = ctx->n_segs_per_evt * ctx->n_bufs_per_seg;
   vec_validate_aligned (wrk->tx_buffers, n_bufs_needed - 1,
diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c
index 49a4af7..8f7e30c 100644
--- a/src/vnet/session/transport.c
+++ b/src/vnet/session/transport.c
@@ -47,10 +47,6 @@
  */
 static double transport_pacer_period;
 
-#define TRANSPORT_PACER_MIN_MSS 	1460
-#define TRANSPORT_PACER_MIN_BURST 	TRANSPORT_PACER_MIN_MSS
-#define TRANSPORT_PACER_MAX_BURST	(43 * TRANSPORT_PACER_MIN_MSS)
-
 u8 *
 format_transport_proto (u8 * s, va_list * args)
 {
@@ -583,6 +579,13 @@
   u64 n_periods = norm_time_now - pacer->last_update;
   u64 inc;
 
+  if (PREDICT_FALSE (n_periods > 5e5))
+    {
+      pacer->last_update = norm_time_now;
+      pacer->bucket = TRANSPORT_PACER_MIN_BURST;
+      return TRANSPORT_PACER_MIN_BURST;
+    }
+
   if (n_periods > 0
       && (inc = (f32) n_periods * pacer->tokens_per_period) > 10)
     {
@@ -674,7 +677,7 @@
   u32 snd_space, max_paced_burst;
 
   snd_space = tp_vfts[tc->proto].send_space (tc);
-  if (transport_connection_is_tx_paced (tc))
+  if (snd_space && transport_connection_is_tx_paced (tc))
     {
       time_now >>= SPACER_CPU_TICKS_PER_PERIOD_SHIFT;
       max_paced_burst = spacer_max_burst (&tc->pacer, time_now);
diff --git a/src/vnet/session/transport.h b/src/vnet/session/transport.h
index 5b45be0..914991d 100644
--- a/src/vnet/session/transport.h
+++ b/src/vnet/session/transport.h
@@ -19,6 +19,10 @@
 #include <vnet/vnet.h>
 #include <vnet/session/transport_types.h>
 
+#define TRANSPORT_PACER_MIN_MSS 	1460
+#define TRANSPORT_PACER_MIN_BURST 	TRANSPORT_PACER_MIN_MSS
+#define TRANSPORT_PACER_MAX_BURST	(43 * TRANSPORT_PACER_MIN_MSS)
+
 typedef struct _transport_options_t
 {
   transport_tx_fn_type_t tx_type;