session: add session flags 67/18367/4
authorFlorin Coras <fcoras@cisco.com>
Mon, 18 Mar 2019 16:06:35 +0000 (09:06 -0700)
committerDave Barach <openvpp@barachs.net>
Mon, 18 Mar 2019 22:07:37 +0000 (22:07 +0000)
- use flag instead of enqueue_epoch for enqueueing rx events.
- use flag for proxy sessions

Change-Id: Iec3eee55a68d02536ece6329348a3369c7c7412e
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/session/application.c
src/vnet/session/application_worker.c
src/vnet/session/session.c
src/vnet/session/session.h
src/vnet/session/session_types.h

index f6fcc4f..91e800d 100644 (file)
@@ -1207,7 +1207,7 @@ application_start_stop_proxy_fib_proto (application_t * app, u8 fib_proto,
 
          app_worker_start_listen (app_wrk, al);
          s = listen_session_get (al->session_index);
-         s->enqueue_epoch = SESSION_PROXY_LISTENER_INDEX;
+         s->flags |= SESSION_F_PROXY;
        }
     }
   else
index 6b294ec..08b42f3 100644 (file)
@@ -453,7 +453,7 @@ app_worker_first_listener (app_worker_t * app_wrk, u8 fib_proto,
    hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
      listener = listen_session_get_from_handle (handle);
      if (listener->session_type == sst
-        && listener->enqueue_epoch != SESSION_PROXY_LISTENER_INDEX)
+        && !(listener->flags & SESSION_F_PROXY))
        return listener;
    }));
   /* *INDENT-ON* */
@@ -476,8 +476,7 @@ app_worker_proxy_listener (app_worker_t * app_wrk, u8 fib_proto,
   /* *INDENT-OFF* */
    hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
      listener = listen_session_get_from_handle (handle);
-     if (listener->session_type == sst
-        && listener->enqueue_epoch == SESSION_PROXY_LISTENER_INDEX)
+     if (listener->session_type == sst && (listener->flags & SESSION_F_PROXY))
        return listener;
    }));
   /* *INDENT-ON* */
index c9eea1d..cd8da50 100644 (file)
@@ -207,7 +207,6 @@ session_alloc_for_connection (transport_connection_t * tc)
 
   s = session_alloc (thread_index);
   s->session_type = session_type_from_proto_and_ip (tc->proto, tc->is_ip4);
-  s->enqueue_epoch = (u64) ~ 0;
   s->session_state = SESSION_STATE_CLOSED;
 
   /* Attach transport to session and vice versa */
@@ -382,9 +381,9 @@ session_enqueue_stream_connection (transport_connection_t * tc,
       session_worker_t *wrk;
 
       wrk = session_main_get_worker (s->thread_index);
-      if (s->enqueue_epoch != wrk->current_enqueue_epoch[tc->proto])
+      if (!(s->flags & SESSION_F_RX_EVT))
        {
-         s->enqueue_epoch = wrk->current_enqueue_epoch[tc->proto];
+         s->flags |= SESSION_F_RX_EVT;
          vec_add1 (wrk->session_to_enqueue[tc->proto], s->session_index);
        }
     }
@@ -420,9 +419,9 @@ session_enqueue_dgram_connection (session_t * s,
       session_worker_t *wrk;
 
       wrk = session_main_get_worker (s->thread_index);
-      if (s->enqueue_epoch != wrk->current_enqueue_epoch[proto])
+      if (!(s->flags & SESSION_F_RX_EVT))
        {
-         s->enqueue_epoch = wrk->current_enqueue_epoch[proto];
+         s->flags |= SESSION_F_RX_EVT;
          vec_add1 (wrk->session_to_enqueue[proto], s->session_index);
        }
     }
@@ -495,6 +494,7 @@ session_enqueue_notify_inline (session_t * s)
   }));
   /* *INDENT-ON* */
 
+  s->flags &= ~SESSION_F_RX_EVT;
   if (PREDICT_FALSE (app_worker_lock_and_send_event (app_wrk, s,
                                                     SESSION_IO_EVT_RX)))
     return -1;
@@ -570,7 +570,6 @@ session_main_flush_enqueue_events (u8 transport_proto, u32 thread_index)
 
   vec_reset_length (indices);
   wrk->session_to_enqueue[transport_proto] = indices;
-  wrk->current_enqueue_epoch[transport_proto]++;
 
   return errors;
 }
@@ -1294,7 +1293,7 @@ session_manager_main_enable (vlib_main_t * vm)
   vlib_thread_main_t *vtm = vlib_get_thread_main ();
   u32 num_threads, preallocated_sessions_per_worker;
   session_worker_t *wrk;
-  int i, j;
+  int i;
 
   num_threads = 1 /* main thread */  + vtm->n_threads;
 
@@ -1304,12 +1303,6 @@ session_manager_main_enable (vlib_main_t * vm)
   /* Allocate cache line aligned worker contexts */
   vec_validate_aligned (smm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES);
 
-  for (i = 0; i < TRANSPORT_N_PROTO; i++)
-    {
-      for (j = 0; j < num_threads; j++)
-       smm->wrk[j].current_enqueue_epoch[i] = 1;
-    }
-
   for (i = 0; i < num_threads; i++)
     {
       wrk = &smm->wrk[i];
index cea1b37..26506ca 100644 (file)
@@ -21,8 +21,6 @@
 #include <svm/message_queue.h>
 #include <svm/ssvm.h>
 
-#define SESSION_PROXY_LISTENER_INDEX ((u8)~0 - 1)
-
 #define foreach_session_input_error                                            \
 _(NO_SESSION, "No session drops")                                       \
 _(NO_LISTENER, "No listener for dst port drops")                        \
@@ -80,9 +78,6 @@ typedef struct session_worker_
   /** vlib_time_now last time around the track */
   f64 last_vlib_time;
 
-  /** Per-proto enqueue epoch counters */
-  u64 current_enqueue_epoch[TRANSPORT_N_PROTO];
-
   /** Per-proto vector of sessions to enqueue */
   u32 *session_to_enqueue[TRANSPORT_N_PROTO];
 
index a0d3362..0845f02 100644 (file)
@@ -128,6 +128,12 @@ typedef enum
   SESSION_STATE_N_STATES,
 } session_state_t;
 
+typedef enum session_flags_
+{
+  SESSION_F_RX_EVT,
+  SESSION_F_PROXY
+} session_flags_t;
+
 typedef struct session_
 {
   /** Pointers to rx/tx buffers. Once allocated, these do not move */
@@ -149,8 +155,8 @@ typedef struct session_
   /** Index of the thread that allocated the session */
   u8 thread_index;
 
-  /** Tracks last enqueue epoch to avoid generating multiple enqueue events */
-  u64 enqueue_epoch;
+  /** Session flags. See @ref session_flags_t */
+  u32 flags;
 
   /** Index of the transport connection associated to the session */
   u32 connection_index;