summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/svm/svm_fifo.c23
-rw-r--r--src/svm/svm_fifo.h27
-rw-r--r--src/vcl/vcl_private.c11
-rw-r--r--src/vnet/session/session.c54
-rwxr-xr-xsrc/vnet/session/session_api.c85
5 files changed, 152 insertions, 48 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index e7a1188d591..b53a2e294f7 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -845,6 +845,29 @@ svm_fifo_init_pointers (svm_fifo_t * f, u32 pointer)
f->head = f->tail = pointer % f->nitems;
}
+void
+svm_fifo_add_subscriber (svm_fifo_t * f, u8 subscriber)
+{
+ if (f->n_subscribers >= SVM_FIFO_MAX_EVT_SUBSCRIBERS)
+ return;
+ f->subscribers[f->n_subscribers++] = subscriber;
+}
+
+void
+svm_fifo_del_subscriber (svm_fifo_t * f, u8 subscriber)
+{
+ int i;
+
+ for (i = 0; i < f->n_subscribers; i++)
+ {
+ if (f->subscribers[i] != subscriber)
+ continue;
+ f->subscribers[i] = f->subscribers[f->n_subscribers - 1];
+ f->n_subscribers--;
+ break;
+ }
+}
+
#endif
/*
* fd.io coding-style-patch-verification: ON
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index 613e0cad5eb..b0d38ed4f0a 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -40,6 +40,7 @@ format_function_t format_ooo_list;
#define OOO_SEGMENT_INVALID_INDEX ((u32)~0)
#define SVM_FIFO_INVALID_SESSION_INDEX ((u32)~0)
#define SVM_FIFO_INVALID_INDEX ((u32)~0)
+#define SVM_FIFO_MAX_EVT_SUBSCRIBERS 8
enum
{
@@ -57,13 +58,13 @@ typedef struct
typedef struct _svm_fifo
{
+ CLIB_CACHE_LINE_ALIGN_MARK (shared_first);
volatile u32 cursize; /**< current fifo size */
u32 nitems;
- CLIB_CACHE_LINE_ALIGN_MARK (end_cursize);
+ CLIB_CACHE_LINE_ALIGN_MARK (shared_second);
volatile u32 has_event; /**< non-zero if deq event exists */
- /* Backpointers */
u32 master_session_index;
u32 client_session_index;
u8 master_thread_index;
@@ -71,13 +72,15 @@ typedef struct _svm_fifo
u32 segment_manager;
u32 segment_index;
u32 ct_session_index; /**< Local session index for vpp */
- CLIB_CACHE_LINE_ALIGN_MARK (end_shared);
+ u32 freelist_index; /**< aka log2(allocated_size) - const. */
+ i8 refcnt; /**< reference count */
+
+ CLIB_CACHE_LINE_ALIGN_MARK (consumer);
u32 head;
volatile u32 want_tx_ntf; /**< producer wants nudge */
volatile u32 has_tx_ntf;
- CLIB_CACHE_LINE_ALIGN_MARK (end_consumer);
- /* producer */
+ CLIB_CACHE_LINE_ALIGN_MARK (producer);
u32 tail;
ooo_segment_t *ooo_segments; /**< Pool of ooo segments */
@@ -85,11 +88,13 @@ typedef struct _svm_fifo
u32 ooos_newest; /**< Last segment to have been updated */
struct _svm_fifo *next; /**< next in freelist/active chain */
struct _svm_fifo *prev; /**< prev in active chain */
+ u8 n_subscribers;
+ u8 subscribers[SVM_FIFO_MAX_EVT_SUBSCRIBERS];
+
#if SVM_FIFO_TRACE
svm_fifo_trace_elem_t *trace;
#endif
- u32 freelist_index; /**< aka log2(allocated_size) - const. */
- i8 refcnt; /**< reference count */
+
CLIB_CACHE_LINE_ALIGN_MARK (data);
} svm_fifo_t;
@@ -198,6 +203,8 @@ int svm_fifo_segments (svm_fifo_t * f, svm_fifo_segment_t * fs);
void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_segment_t * fs);
void svm_fifo_init_pointers (svm_fifo_t * f, u32 pointer);
void svm_fifo_overwrite_head (svm_fifo_t * f, u8 * data, u32 len);
+void svm_fifo_add_subscriber (svm_fifo_t * f, u8 subscriber);
+void svm_fifo_del_subscriber (svm_fifo_t * f, u8 subscriber);
format_function_t format_svm_fifo;
/**
@@ -297,6 +304,12 @@ svm_fifo_needs_tx_ntf (svm_fifo_t * f, u32 n_last_deq)
return 0;
}
+always_inline u8
+svm_fifo_n_subscribers (svm_fifo_t * f)
+{
+ return f->n_subscribers;
+}
+
u32 svm_fifo_number_ooo_segments (svm_fifo_t * f);
ooo_segment_t *svm_fifo_first_ooo_segment (svm_fifo_t * f);
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index 32664312f01..4241bcf1789 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -392,6 +392,11 @@ vcl_worker_share_session (vcl_worker_t * parent, vcl_worker_t * wrk,
ss = vcl_shared_session_get (new_s->shared_index);
vec_add1 (ss->workers, wrk->wrk_index);
}
+ if (new_s->rx_fifo)
+ {
+ svm_fifo_add_subscriber (new_s->rx_fifo, wrk->vpp_wrk_index);
+ svm_fifo_add_subscriber (new_s->tx_fifo, wrk->vpp_wrk_index);
+ }
}
int
@@ -416,6 +421,12 @@ vcl_worker_unshare_session (vcl_worker_t * wrk, vcl_session_t * s)
return 1;
}
+ if (s->rx_fifo)
+ {
+ svm_fifo_del_subscriber (s->rx_fifo, wrk->vpp_wrk_index);
+ svm_fifo_del_subscriber (s->tx_fifo, wrk->vpp_wrk_index);
+ }
+
/* If the first removed and not last, start session worker change.
* First request goes to vpp and vpp reflects it back to the right
* worker */
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index c56712bbf87..efd1d73c4a0 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -518,6 +518,30 @@ stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
return svm_fifo_dequeue_drop (s->server_tx_fifo, max_bytes);
}
+static inline int
+session_notify_subscribers (u32 app_index, stream_session_t * s,
+ svm_fifo_t * f, session_evt_type_t evt_type)
+{
+ app_worker_t *app_wrk;
+ application_t *app;
+ int i;
+
+ app = application_get (app_index);
+ if (!app)
+ return -1;
+
+ for (i = 0; i < f->n_subscribers; i++)
+ {
+ app_wrk = application_get_worker (app, f->subscribers[i]);
+ if (!app_wrk)
+ continue;
+ if (app_worker_lock_and_send_event (app_wrk, s, evt_type))
+ return -1;
+ }
+
+ return 0;
+}
+
/**
* Notify session peer that new data has been enqueued.
*
@@ -529,10 +553,10 @@ stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
static inline int
session_enqueue_notify (stream_session_t * s)
{
- app_worker_t *app;
+ app_worker_t *app_wrk;
- app = app_worker_get_if_valid (s->app_wrk_index);
- if (PREDICT_FALSE (!app))
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (PREDICT_FALSE (!app_wrk))
{
SESSION_DBG ("invalid s->app_index = %d", s->app_wrk_index);
return 0;
@@ -545,22 +569,36 @@ session_enqueue_notify (stream_session_t * s)
}));
/* *INDENT-ON* */
- return app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_RX);
+ if (PREDICT_FALSE (app_worker_lock_and_send_event (app_wrk, s,
+ FIFO_EVENT_APP_RX)))
+ return -1;
+
+ if (PREDICT_FALSE (svm_fifo_n_subscribers (s->server_rx_fifo)))
+ return session_notify_subscribers (app_wrk->app_index, s,
+ s->server_rx_fifo, FIFO_EVENT_APP_RX);
+
+ return 0;
}
int
session_dequeue_notify (stream_session_t * s)
{
- app_worker_t *app;
+ app_worker_t *app_wrk;
- app = app_worker_get_if_valid (s->app_wrk_index);
- if (PREDICT_FALSE (!app))
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (PREDICT_FALSE (!app_wrk))
return -1;
- if (app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_TX))
+ if (PREDICT_FALSE (app_worker_lock_and_send_event (app_wrk, s,
+ FIFO_EVENT_APP_TX)))
return -1;
+ if (PREDICT_FALSE (s->server_tx_fifo->n_subscribers))
+ return session_notify_subscribers (app_wrk->app_index, s,
+ s->server_tx_fifo, FIFO_EVENT_APP_TX);
+
svm_fifo_clear_tx_ntf (s->server_tx_fifo);
+
return 0;
}
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index 2d20d5f697b..2decd9b8a2e 100755
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -505,10 +505,10 @@ mq_send_session_accepted_cb (stream_session_t * s)
return 0;
}
-static void
-mq_send_session_disconnected_cb (stream_session_t * s)
+static inline void
+mq_send_session_close_evt (app_worker_t * app_wrk, session_handle_t sh,
+ session_evt_type_t evt_type)
{
- app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
svm_msg_q_msg_t _msg, *msg = &_msg;
session_disconnected_msg_t *mp;
svm_msg_q_t *app_mq;
@@ -519,53 +519,72 @@ mq_send_session_disconnected_cb (stream_session_t * s)
return;
evt = svm_msg_q_msg_data (app_mq, msg);
clib_memset (evt, 0, sizeof (*evt));
- evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
+ evt->event_type = evt_type;
mp = (session_disconnected_msg_t *) evt->data;
- mp->handle = session_handle (s);
+ mp->handle = sh;
mp->context = app_wrk->api_client_index;
svm_msg_q_add_and_unlock (app_mq, msg);
}
+static inline void
+mq_notify_close_subscribers (u32 app_index, session_handle_t sh,
+ svm_fifo_t * f, session_evt_type_t evt_type)
+{
+ app_worker_t *app_wrk;
+ application_t *app;
+ int i;
+
+ app = application_get (app_index);
+ if (!app)
+ return;
+
+ for (i = 0; i < f->n_subscribers; i++)
+ {
+ if (!(app_wrk = application_get_worker (app, f->subscribers[i])))
+ continue;
+ mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED);
+ }
+}
+
+static void
+mq_send_session_disconnected_cb (stream_session_t * s)
+{
+ app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
+ session_handle_t sh = session_handle (s);
+
+ mq_send_session_close_evt (app_wrk, session_handle (s),
+ SESSION_CTRL_EVT_DISCONNECTED);
+
+ if (svm_fifo_n_subscribers (s->server_rx_fifo))
+ mq_notify_close_subscribers (app_wrk->app_index, sh, s->server_rx_fifo,
+ SESSION_CTRL_EVT_DISCONNECTED);
+}
+
void
mq_send_local_session_disconnected_cb (u32 app_wrk_index,
local_session_t * ls)
{
app_worker_t *app_wrk = app_worker_get (app_wrk_index);
- svm_msg_q_msg_t _msg, *msg = &_msg;
- session_disconnected_msg_t *mp;
- svm_msg_q_t *app_mq;
- session_event_t *evt;
+ session_handle_t sh = application_local_session_handle (ls);
- app_mq = app_wrk->event_queue;
- if (mq_try_lock_and_alloc_msg (app_mq, msg))
- return;
- evt = svm_msg_q_msg_data (app_mq, msg);
- clib_memset (evt, 0, sizeof (*evt));
- evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
- mp = (session_disconnected_msg_t *) evt->data;
- mp->handle = application_local_session_handle (ls);
- mp->context = app_wrk->api_client_index;
- svm_msg_q_add_and_unlock (app_mq, msg);
+ mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED);
+
+ if (svm_fifo_n_subscribers (ls->server_rx_fifo))
+ mq_notify_close_subscribers (app_wrk->app_index, sh, ls->server_rx_fifo,
+ SESSION_CTRL_EVT_DISCONNECTED);
}
static void
mq_send_session_reset_cb (stream_session_t * s)
{
- app_worker_t *app = app_worker_get (s->app_wrk_index);
- svm_msg_q_msg_t _msg, *msg = &_msg;
- session_reset_msg_t *mp;
- svm_msg_q_t *app_mq;
- session_event_t *evt;
+ app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
+ session_handle_t sh = session_handle (s);
- app_mq = app->event_queue;
- if (mq_try_lock_and_alloc_msg (app_mq, msg))
- return;
- evt = svm_msg_q_msg_data (app_mq, msg);
- clib_memset (evt, 0, sizeof (*evt));
- evt->event_type = SESSION_CTRL_EVT_RESET;
- mp = (session_reset_msg_t *) evt->data;
- mp->handle = session_handle (s);
- svm_msg_q_add_and_unlock (app_mq, msg);
+ mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_RESET);
+
+ if (svm_fifo_n_subscribers (s->server_rx_fifo))
+ mq_notify_close_subscribers (app_wrk->app_index, sh, s->server_rx_fifo,
+ SESSION_CTRL_EVT_RESET);
}
static int