summaryrefslogtreecommitdiffstats
path: root/src/plugins/hs_apps/sapi
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-12-08 17:50:45 -0800
committerFlorin Coras <fcoras@cisco.com>2020-12-24 23:08:43 -0800
commitc547e91df7083007c87615ac1e37b6f223e575e9 (patch)
tree0677e843f5307becf326c14d43d57c0e4b8c3329 /src/plugins/hs_apps/sapi
parent8219f1f361083cc63022b70d11b08f52833d4789 (diff)
svm: split fifo into private and shared structs
Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Id8e77e8b2623be719fd43a95e181eaa5b7df2b6e
Diffstat (limited to 'src/plugins/hs_apps/sapi')
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo.c48
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_bapi.c33
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_common.h2
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_proto_udp.c16
4 files changed, 61 insertions, 38 deletions
diff --git a/src/plugins/hs_apps/sapi/vpp_echo.c b/src/plugins/hs_apps/sapi/vpp_echo.c
index 4cce41edf95..a47a4d455d8 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo.c
@@ -69,9 +69,9 @@ echo_session_dequeue_notify (echo_session_t * s)
int rv;
if (!svm_fifo_set_event (s->rx_fifo))
return;
- if ((rv =
- app_send_io_evt_to_vpp (s->vpp_evt_q, s->rx_fifo->master_session_index,
- SESSION_IO_EVT_RX, SVM_Q_WAIT)))
+ if ((rv = app_send_io_evt_to_vpp (s->vpp_evt_q,
+ s->rx_fifo->shr->master_session_index,
+ SESSION_IO_EVT_RX, SVM_Q_WAIT)))
ECHO_FAIL (ECHO_FAIL_SEND_IO_EVT, "app_send_io_evt_to_vpp errored %d",
rv);
svm_fifo_clear_deq_ntf (s->rx_fifo);
@@ -542,7 +542,6 @@ session_accepted_handler (session_accepted_msg_t * mp)
{
app_session_evt_t _app_evt, *app_evt = &_app_evt;
session_accepted_reply_msg_t *rmp;
- svm_fifo_t *rx_fifo, *tx_fifo;
echo_main_t *em = &echo_main;
echo_session_t *session, *ls;
@@ -552,24 +551,22 @@ session_accepted_handler (session_accepted_msg_t * mp)
"Unknown listener handle 0x%lx", mp->listener_handle);
return;
}
- if (echo_segment_lookup (mp->segment_handle) == ~0)
+
+ /* Allocate local session and set it up */
+ session = echo_session_new (em);
+
+ if (echo_attach_session (mp->segment_handle, mp->server_rx_fifo,
+ mp->server_tx_fifo, session))
{
ECHO_FAIL (ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC,
"accepted wait_for_segment_allocation errored");
return;
}
- /* Allocate local session and set it up */
- session = echo_session_new (em);
- session->vpp_session_handle = mp->handle;
-
- rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
- rx_fifo->client_session_index = session->session_index;
- tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
- tx_fifo->client_session_index = session->session_index;
+ session->vpp_evt_q =
+ uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *);
- session->rx_fifo = rx_fifo;
- session->tx_fifo = tx_fifo;
+ session->vpp_session_handle = mp->handle;
/* session->transport needed by app_send_dgram */
clib_memcpy_fast (&session->transport.rmt_ip, &mp->rmt.ip,
@@ -581,10 +578,8 @@ session_accepted_handler (session_accepted_msg_t * mp)
session->transport.lcl_port = em->uri_elts.port;
session->vpp_session_handle = mp->handle;
- session->start = clib_time_now (&em->clib_time);
- session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
- svm_msg_q_t *);
session->listener_index = ls->session_index;
+ session->start = clib_time_now (&em->clib_time);
/* Add it to lookup table */
ECHO_LOG (2, "Accepted session 0x%lx S[%u] -> 0x%lx S[%u]",
@@ -607,7 +602,6 @@ session_connected_handler (session_connected_msg_t * mp)
echo_main_t *em = &echo_main;
echo_session_t *session;
u32 listener_index = htonl (mp->context);
- svm_fifo_t *rx_fifo, *tx_fifo;
clib_atomic_add_fetch (&em->max_sim_connects, 1);
@@ -621,24 +615,18 @@ session_connected_handler (session_connected_msg_t * mp)
}
session = echo_session_new (em);
- if (echo_segment_lookup (mp->segment_handle) == ~0)
+
+ if (echo_attach_session (mp->segment_handle, mp->server_rx_fifo,
+ mp->server_tx_fifo, session))
{
ECHO_FAIL (ECHO_FAIL_CONNECTED_WAIT_FOR_SEG_ALLOC,
"connected wait_for_segment_allocation errored");
return;
}
-
- rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
- rx_fifo->client_session_index = session->session_index;
- tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
- tx_fifo->client_session_index = session->session_index;
-
- session->rx_fifo = rx_fifo;
- session->tx_fifo = tx_fifo;
- session->vpp_session_handle = mp->handle;
- session->start = clib_time_now (&em->clib_time);
session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
svm_msg_q_t *);
+ session->vpp_session_handle = mp->handle;
+ session->start = clib_time_now (&em->clib_time);
session->listener_index = listener_index;
/* session->transport needed by app_send_dgram */
clib_memcpy_fast (&session->transport.lcl_ip, &mp->lcl.ip,
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
index e71c0e9adba..c643cec2ce3 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
@@ -262,6 +262,39 @@ echo_segment_detach (u64 segment_handle)
clib_spinlock_unlock (&em->segment_handles_lock);
}
+int
+echo_attach_session (uword segment_handle, uword rxf_offset, uword txf_offset,
+ echo_session_t *s)
+{
+ svm_fifo_shared_t *rx_fifo, *tx_fifo;
+ echo_main_t *em = &echo_main;
+ fifo_segment_t *fs;
+ u32 fs_index;
+
+ fs_index = echo_segment_lookup (segment_handle);
+ if (fs_index == (u32) ~0)
+ {
+ ECHO_LOG (0, "ERROR: segment for session %u is not mounted!",
+ s->session_index);
+ return -1;
+ }
+
+ rx_fifo = uword_to_pointer (rxf_offset, svm_fifo_shared_t *);
+ tx_fifo = uword_to_pointer (txf_offset, svm_fifo_shared_t *);
+ rx_fifo->client_session_index = s->session_index;
+ tx_fifo->client_session_index = s->session_index;
+
+ clib_spinlock_lock (&em->segment_handles_lock);
+
+ fs = fifo_segment_get_segment (&em->segment_main, fs_index);
+ s->rx_fifo = fifo_segment_alloc_fifo_w_shared (fs, rx_fifo);
+ s->tx_fifo = fifo_segment_alloc_fifo_w_shared (fs, tx_fifo);
+
+ clib_spinlock_unlock (&em->segment_handles_lock);
+
+ return 0;
+}
+
/*
*
* Binary API callbacks
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.h b/src/plugins/hs_apps/sapi/vpp_echo_common.h
index 0def7adab36..cd2bbb6038c 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_common.h
+++ b/src/plugins/hs_apps/sapi/vpp_echo_common.h
@@ -443,6 +443,8 @@ int echo_segment_attach (u64 segment_handle, char *name,
ssvm_segment_type_t type, int fd);
u32 echo_segment_lookup (u64 segment_handle);
void echo_segment_detach (u64 segment_handle);
+int echo_attach_session (uword segment_handle, uword rxf_offset,
+ uword txf_offset, echo_session_t *s);
/* Binary API */
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_proto_udp.c b/src/plugins/hs_apps/sapi/vpp_echo_proto_udp.c
index 456113cdd7d..9689a83d76b 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_proto_udp.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo_proto_udp.c
@@ -126,24 +126,24 @@ udp_echo_reset_cb (session_reset_msg_t * mp, echo_session_t * s)
static void
udp_echo_bound_uri_cb (session_bound_msg_t * mp, echo_session_t * session)
{
- svm_fifo_t *rx_fifo, *tx_fifo;
echo_main_t *em = &echo_main;
u32 session_index = session->session_index;
if (!em->i_am_master || em->uri_elts.transport_proto != TRANSPORT_PROTO_UDP)
return;
- rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *);
- tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *);
- rx_fifo->client_session_index = session_index;
- tx_fifo->client_session_index = session_index;
+ if (echo_attach_session (mp->segment_handle, mp->rx_fifo, mp->tx_fifo,
+ session))
+ {
+ ECHO_FAIL (ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC,
+ "accepted wait_for_segment_allocation errored");
+ return;
+ }
- session->rx_fifo = rx_fifo;
- session->tx_fifo = tx_fifo;
+ session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
session->transport.is_ip4 = mp->lcl_is_ip4;
clib_memcpy_fast (&session->transport.lcl_ip, mp->lcl_ip,
sizeof (ip46_address_t));
session->transport.lcl_port = mp->lcl_port;
- session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
echo_notify_event (em, ECHO_EVT_FIRST_QCONNECT);
session->session_type = ECHO_SESSION_TYPE_STREAM;