diff options
author | Florin Coras <fcoras@cisco.com> | 2018-07-04 04:15:05 -0700 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2018-07-17 09:02:17 +0000 |
commit | 3c2fed5145d9e40a9ecd178c2866c813eddc6203 (patch) | |
tree | 7ff2408f3b1c4a52fb6d7cd091508de1ce950e5f /src/vnet/session-apps | |
parent | 5da96a77a84ae5414debbc46d390464d51010113 (diff) |
session: use msg queue for events
Change-Id: I3c58367eec2243fe19b75be78a175c5261863e9e
Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/session-apps')
-rw-r--r-- | src/vnet/session-apps/echo_client.c | 31 | ||||
-rw-r--r-- | src/vnet/session-apps/echo_client.h | 2 | ||||
-rw-r--r-- | src/vnet/session-apps/echo_server.c | 17 | ||||
-rw-r--r-- | src/vnet/session-apps/http_server.c | 23 | ||||
-rw-r--r-- | src/vnet/session-apps/proxy.c | 31 | ||||
-rw-r--r-- | src/vnet/session-apps/proxy.h | 4 |
6 files changed, 27 insertions, 81 deletions
diff --git a/src/vnet/session-apps/echo_client.c b/src/vnet/session-apps/echo_client.c index 6ee91f9c54b..3d1af676186 100644 --- a/src/vnet/session-apps/echo_client.c +++ b/src/vnet/session-apps/echo_client.c @@ -62,13 +62,8 @@ send_data_chunk (echo_client_main_t * ecm, eclient_session_t * s) svm_fifo_t *f = s->data.tx_fifo; rv = clib_min (svm_fifo_max_enqueue (f), bytes_this_chunk); svm_fifo_enqueue_nocopy (f, rv); - if (svm_fifo_set_event (f)) - { - session_fifo_event_t evt; - evt.fifo = f; - evt.event_type = FIFO_EVENT_APP_TX; - svm_queue_add (s->data.vpp_evt_q, (u8 *) & evt, 0); - } + session_send_io_evt_to_thread_custom (f, s->thread_index, + FIFO_EVENT_APP_TX); } else rv = app_send_stream (&s->data, test_data + test_buf_offset, @@ -98,13 +93,8 @@ send_data_chunk (echo_client_main_t * ecm, eclient_session_t * s) hdr.lcl_port = at->lcl_port; svm_fifo_enqueue_nowait (f, sizeof (hdr), (u8 *) & hdr); svm_fifo_enqueue_nocopy (f, rv); - if (svm_fifo_set_event (f)) - { - session_fifo_event_t evt; - evt.fifo = f; - evt.event_type = FIFO_EVENT_APP_TX; - svm_queue_add (s->data.vpp_evt_q, (u8 *) & evt, 0); - } + session_send_io_evt_to_thread_custom (f, s->thread_index, + FIFO_EVENT_APP_TX); } else rv = app_send_dgram (&s->data, test_data + test_buf_offset, @@ -462,18 +452,9 @@ echo_clients_rx_callback (stream_session_t * s) if (svm_fifo_max_dequeue (s->server_rx_fifo)) { - session_fifo_event_t evt; - svm_queue_t *q; if (svm_fifo_set_event (s->server_rx_fifo)) - { - evt.fifo = s->server_rx_fifo; - evt.event_type = FIFO_EVENT_BUILTIN_RX; - q = session_manager_get_vpp_event_queue (s->thread_index); - if (PREDICT_FALSE (q->cursize == q->maxsize)) - clib_warning ("out of event queue space"); - else if (svm_queue_add (q, (u8 *) & evt, 0)) - clib_warning ("failed to enqueue self-tap"); - } + session_send_io_evt_to_thread (s->server_rx_fifo, + FIFO_EVENT_BUILTIN_RX); } return 0; } diff --git a/src/vnet/session-apps/echo_client.h b/src/vnet/session-apps/echo_client.h index f3fc8d2b59e..db5ba163628 100644 --- a/src/vnet/session-apps/echo_client.h +++ b/src/vnet/session-apps/echo_client.h @@ -46,7 +46,7 @@ typedef struct * Application setup parameters */ svm_queue_t *vl_input_queue; /**< vpe input queue */ - svm_queue_t **vpp_event_queue; + svm_msg_q_t **vpp_event_queue; u32 cli_node_index; /**< cli process node index */ u32 my_client_index; /**< loopback API client handle */ diff --git a/src/vnet/session-apps/echo_server.c b/src/vnet/session-apps/echo_server.c index 7d1ae5a4d49..770f4ba7337 100644 --- a/src/vnet/session-apps/echo_server.c +++ b/src/vnet/session-apps/echo_server.c @@ -23,7 +23,7 @@ typedef struct /* * Server app parameters */ - svm_queue_t **vpp_queue; + svm_msg_q_t **vpp_queue; svm_queue_t *vl_input_queue; /**< Sever's event queue */ u32 app_index; /**< Server app index */ @@ -145,10 +145,8 @@ echo_server_rx_callback (stream_session_t * s) int actual_transfer; svm_fifo_t *tx_fifo, *rx_fifo; echo_server_main_t *esm = &echo_server_main; - session_fifo_event_t evt; u32 thread_index = vlib_get_thread_index (); app_session_transport_t at; - svm_queue_t *q; ASSERT (s->thread_index == thread_index); @@ -170,8 +168,9 @@ echo_server_rx_callback (stream_session_t * s) max_dequeue = ph.data_length - ph.data_offset; if (!esm->vpp_queue[s->thread_index]) { - q = session_manager_get_vpp_event_queue (s->thread_index); - esm->vpp_queue[s->thread_index] = q; + svm_msg_q_t *mq; + mq = session_manager_get_vpp_event_queue (s->thread_index); + esm->vpp_queue[s->thread_index] = mq; } max_enqueue -= sizeof (session_dgram_hdr_t); } @@ -191,13 +190,7 @@ echo_server_rx_callback (stream_session_t * s) /* Program self-tap to retry */ if (svm_fifo_set_event (rx_fifo)) { - evt.fifo = rx_fifo; - evt.event_type = FIFO_EVENT_BUILTIN_RX; - - q = esm->vpp_queue[s->thread_index]; - if (PREDICT_FALSE (q->cursize == q->maxsize)) - clib_warning ("out of event queue space"); - else if (svm_queue_add (q, (u8 *) & evt, 0)) + if (session_send_io_evt_to_thread (rx_fifo, FIFO_EVENT_BUILTIN_RX)) clib_warning ("failed to enqueue self-tap"); vec_validate (esm->rx_retries[s->thread_index], s->session_index); diff --git a/src/vnet/session-apps/http_server.c b/src/vnet/session-apps/http_server.c index 9ad1297b901..ef9f760c992 100644 --- a/src/vnet/session-apps/http_server.c +++ b/src/vnet/session-apps/http_server.c @@ -32,7 +32,7 @@ typedef struct typedef struct { u8 **rx_buf; - svm_queue_t **vpp_queue; + svm_msg_q_t **vpp_queue; u64 byte_index; uword *handler_by_get_request; @@ -140,7 +140,6 @@ http_cli_output (uword arg, u8 * buffer, uword buffer_bytes) void send_data (stream_session_t * s, u8 * data) { - session_fifo_event_t evt; u32 offset, bytes_to_send; f64 delay = 10e-3; http_server_main_t *hsm = &http_server_main; @@ -178,14 +177,8 @@ send_data (stream_session_t * s, u8 * data) bytes_to_send -= actual_transfer; if (svm_fifo_set_event (s->server_tx_fifo)) - { - /* Fabricate TX event, send to vpp */ - evt.fifo = s->server_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - - svm_queue_add (hsm->vpp_queue[s->thread_index], - (u8 *) & evt, 0 /* do wait for mutex */ ); - } + session_send_io_evt_to_thread (s->server_tx_fifo, + FIFO_EVENT_APP_TX); delay = 10e-3; } } @@ -379,15 +372,7 @@ http_server_rx_callback (stream_session_t * s) /* Send an RPC request via the thread-0 input node */ if (vlib_get_thread_index () != 0) - { - session_fifo_event_t evt; - evt.rpc_args.fp = alloc_http_process_callback; - evt.rpc_args.arg = args; - evt.event_type = FIFO_EVENT_RPC; - svm_queue_add - (session_manager_get_vpp_event_queue (0 /* main thread */ ), - (u8 *) & evt, 0 /* do wait for mutex */ ); - } + session_send_rpc_evt_to_thread (0, alloc_http_process_callback, args); else alloc_http_process (args); return 0; diff --git a/src/vnet/session-apps/proxy.c b/src/vnet/session-apps/proxy.c index 78aa0de2840..6260ad350f0 100644 --- a/src/vnet/session-apps/proxy.c +++ b/src/vnet/session-apps/proxy.c @@ -194,7 +194,6 @@ proxy_rx_callback (stream_session_t * s) int proxy_index; uword *p; svm_fifo_t *active_open_tx_fifo; - session_fifo_event_t evt; ASSERT (s->thread_index == thread_index); @@ -212,10 +211,9 @@ proxy_rx_callback (stream_session_t * s) if (svm_fifo_set_event (active_open_tx_fifo)) { u32 ao_thread_index = active_open_tx_fifo->master_thread_index; - evt.fifo = active_open_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - if (svm_queue_add (pm->active_open_event_queue[ao_thread_index], - (u8 *) & evt, 0 /* do wait for mutex */ )) + if (session_send_io_evt_to_thread_custom (active_open_tx_fifo, + ao_thread_index, + FIFO_EVENT_APP_TX)) clib_warning ("failed to enqueue tx evt"); } } @@ -278,7 +276,6 @@ active_open_connected_callback (u32 app_index, u32 opaque, proxy_main_t *pm = &proxy_main; proxy_session_t *ps; u8 thread_index = vlib_get_thread_index (); - session_fifo_event_t evt; if (is_fail) { @@ -320,15 +317,9 @@ active_open_connected_callback (u32 app_index, u32 opaque, /* * Send event for active open tx fifo */ + ASSERT (s->thread_index == thread_index); if (svm_fifo_set_event (s->server_tx_fifo)) - { - evt.fifo = s->server_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - if (svm_queue_add - (pm->active_open_event_queue[thread_index], (u8 *) & evt, - 0 /* do wait for mutex */ )) - clib_warning ("failed to enqueue tx evt"); - } + session_send_io_evt_to_thread (s->server_tx_fifo, FIFO_EVENT_APP_TX); return 0; } @@ -354,8 +345,6 @@ active_open_disconnect_callback (stream_session_t * s) static int active_open_rx_callback (stream_session_t * s) { - proxy_main_t *pm = &proxy_main; - session_fifo_event_t evt; svm_fifo_t *proxy_tx_fifo; proxy_tx_fifo = s->server_rx_fifo; @@ -365,12 +354,10 @@ active_open_rx_callback (stream_session_t * s) */ if (svm_fifo_set_event (proxy_tx_fifo)) { - u32 p_thread_index = proxy_tx_fifo->master_thread_index; - evt.fifo = proxy_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - if (svm_queue_add (pm->server_event_queue[p_thread_index], (u8 *) & evt, - 0 /* do wait for mutex */ )) - clib_warning ("failed to enqueue server rx evt"); + u8 thread_index = proxy_tx_fifo->master_thread_index; + return session_send_io_evt_to_thread_custom (proxy_tx_fifo, + thread_index, + FIFO_EVENT_APP_TX); } return 0; diff --git a/src/vnet/session-apps/proxy.h b/src/vnet/session-apps/proxy.h index 4bca0a02cd8..c221a5e75f2 100644 --- a/src/vnet/session-apps/proxy.h +++ b/src/vnet/session-apps/proxy.h @@ -40,8 +40,8 @@ typedef struct { svm_queue_t *vl_input_queue; /**< vpe input queue */ /** per-thread vectors */ - svm_queue_t **server_event_queue; - svm_queue_t **active_open_event_queue; + svm_msg_q_t **server_event_queue; + svm_msg_q_t **active_open_event_queue; u8 **rx_buf; /**< intermediate rx buffers */ u32 cli_node_index; /**< cli process node index */ |