session/tcp/vcl: fixes and optimizations 94/18094/5
authorFlorin Coras <fcoras@cisco.com>
Thu, 7 Mar 2019 05:13:42 +0000 (21:13 -0800)
committerDave Barach <openvpp@barachs.net>
Fri, 8 Mar 2019 20:03:31 +0000 (20:03 +0000)
Change-Id: Idc7dfe743399dd8dee0f6b3ec83f194f3fca580b
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vcl/vcl_locked.c
src/vcl/vppcom.c
src/vnet/session/session_node.c
src/vnet/tcp/tcp.c
src/vnet/tcp/tcp.h
src/vnet/tcp/tcp_output.c

index 725f1bf..fb19b5d 100644 (file)
@@ -862,6 +862,9 @@ vls_unshare_vcl_worker_sessions (vcl_worker_t * wrk)
   vcl_locked_session_t *vls;
   vcl_session_t *s;
 
+  if (pool_elts (vcm->workers) <= 1)
+    return;
+
   current_wrk = vcl_get_worker_index ();
   is_current = current_wrk == wrk->wrk_index;
   vls_table_wlock ();
index 72e1194..bdc1131 100644 (file)
@@ -1681,9 +1681,9 @@ vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n,
   vcl_worker_t *wrk = vcl_worker_get_current ();
   int n_write, is_nonblocking;
   vcl_session_t *s = 0;
-  svm_fifo_t *tx_fifo = 0;
   session_evt_type_t et;
   svm_msg_q_msg_t msg;
+  svm_fifo_t *tx_fifo;
   session_event_t *e;
   svm_msg_q_t *mq;
   u8 is_ct;
@@ -1746,12 +1746,12 @@ vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n,
   if (s->is_dgram)
     n_write = app_send_dgram_raw (tx_fifo, &s->transport,
                                  s->vpp_evt_q, buf, n, et,
-                                 !is_ct /* do_evt */ , SVM_Q_WAIT);
+                                 0 /* do_evt */ , SVM_Q_WAIT);
   else
     n_write = app_send_stream_raw (tx_fifo, s->vpp_evt_q, buf, n, et,
-                                  !is_ct /* do_evt */ , SVM_Q_WAIT);
+                                  0 /* do_evt */ , SVM_Q_WAIT);
 
-  if (is_ct && svm_fifo_set_event (s->tx_fifo))
+  if (svm_fifo_set_event (s->tx_fifo))
     app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo->master_session_index,
                            et, SVM_Q_WAIT);
 
@@ -1940,11 +1940,28 @@ vppcom_select_condvar (vcl_worker_t * wrk, int n_bits,
                       vcl_si_set * except_map, double time_to_wait,
                       u32 * bits_set)
 {
-  time_to_wait = (time_to_wait == -1) ? 1e6 : time_to_wait;
-  vcl_select_handle_mq (wrk, wrk->app_event_queue, n_bits, read_map,
-                       write_map, except_map, (bits_set ? 0 : time_to_wait),
-                       bits_set);
-  return *bits_set;
+  double wait = 0, start = 0;
+
+  if (!*bits_set)
+    {
+      wait = time_to_wait;
+      start = clib_time_now (&wrk->clib_time);
+    }
+
+  do
+    {
+      vcl_select_handle_mq (wrk, wrk->app_event_queue, n_bits, read_map,
+                           write_map, except_map, wait, bits_set);
+      if (*bits_set)
+       return *bits_set;
+      if (wait == -1)
+       continue;
+
+      wait = wait - (clib_time_now (&wrk->clib_time) - start);
+    }
+  while (wait > 0);
+
+  return 0;
 }
 
 static int
@@ -2517,10 +2534,28 @@ static int
 vppcom_epoll_wait_condvar (vcl_worker_t * wrk, struct epoll_event *events,
                           int maxevents, u32 n_evts, double wait_for_time)
 {
-  wait_for_time = (wait_for_time == -1) ? (double) 1e6 : wait_for_time;
-  vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events, maxevents,
-                           (n_evts ? 0 : wait_for_time), &n_evts);
-  return n_evts;
+  double wait = 0, start = 0;
+
+  if (!n_evts)
+    {
+      wait = wait_for_time;
+      start = clib_time_now (&wrk->clib_time);
+    }
+
+  do
+    {
+      vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events, maxevents,
+                               wait, &n_evts);
+      if (n_evts)
+       return n_evts;
+      if (wait == -1)
+       continue;
+
+      wait = wait - (clib_time_now (&wrk->clib_time) - start);
+    }
+  while (wait > 0);
+
+  return 0;
 }
 
 static int
index fb53846..a7ff214 100644 (file)
@@ -928,6 +928,7 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
              clib_warning ("session was freed!");
              continue;
            }
+         CLIB_PREFETCH (s->tx_fifo, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
          wrk->ctx.s = s;
          /* Spray packets in per session type frames, since they go to
           * different nodes */
index 7b28dd3..f40ef42 100644 (file)
@@ -1156,13 +1156,6 @@ tcp_update_time (f64 now, u8 thread_index)
   tcp_flush_frames_to_output (wrk);
 }
 
-static u32
-tcp_session_push_header (transport_connection_t * tconn, vlib_buffer_t * b)
-{
-  tcp_connection_t *tc = (tcp_connection_t *) tconn;
-  return tcp_push_header (tc, b);
-}
-
 static void
 tcp_session_flush_data (transport_connection_t * tconn)
 {
index 511f013..07ceb5a 100644 (file)
@@ -820,7 +820,8 @@ tcp_set_time_now (tcp_worker_ctx_t * wrk)
   return wrk->time_now;
 }
 
-u32 tcp_push_header (tcp_connection_t * tconn, vlib_buffer_t * b);
+u32 tcp_session_push_header (transport_connection_t * tconn,
+                            vlib_buffer_t * b);
 
 void tcp_connection_timers_init (tcp_connection_t * tc);
 void tcp_connection_timers_reset (tcp_connection_t * tc);
index 94f96b6..2f728cc 100644 (file)
@@ -1173,8 +1173,9 @@ tcp_push_hdr_i (tcp_connection_t * tc, vlib_buffer_t * b,
 }
 
 u32
-tcp_push_header (tcp_connection_t * tc, vlib_buffer_t * b)
+tcp_session_push_header (transport_connection_t * tconn, vlib_buffer_t * b)
 {
+  tcp_connection_t *tc = (tcp_connection_t *) tconn;
   tcp_push_hdr_i (tc, b, TCP_STATE_ESTABLISHED, /* compute opts */ 0,
                  /* burst */ 1);
   tc->snd_una_max = tc->snd_nxt;