summaryrefslogtreecommitdiffstats
path: root/src/vnet/session
diff options
context:
space:
mode:
authorRyujiro Shibuya <ryujiro.shibuya@owmobility.com>2020-01-22 12:11:42 +0000
committerDave Barach <openvpp@barachs.net>2020-02-25 19:18:49 +0000
commitd8f48e2166747b529aa23762ac314dd686590c89 (patch)
treeebd94006c2eb6be5db9c0f1fec5ff7f984aeb38a /src/vnet/session
parent234fe894d80a6ebc7e457bc86f2eea80d5ef01ea (diff)
session: basic fifo-tuning-logic
- Allowing application to register custom fifo-tuning-logic. - Adding an example custom fifo-tuning-logic in hs_app/proxy. Type: feature Signed-off-by: Ryujiro Shibuya <ryujiro.shibuya@owmobility.com> Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I2aca14d1f23d5c3c9debb7f4c46aca3a15a8d1b9
Diffstat (limited to 'src/vnet/session')
-rw-r--r--src/vnet/session/application.c2
-rw-r--r--src/vnet/session/application.h3
-rw-r--r--src/vnet/session/application_interface.h5
-rw-r--r--src/vnet/session/application_worker.c18
-rw-r--r--src/vnet/session/segment_manager.c37
-rw-r--r--src/vnet/session/segment_manager.h3
-rw-r--r--src/vnet/session/session.c26
-rw-r--r--src/vnet/session/session_types.h8
8 files changed, 93 insertions, 9 deletions
diff --git a/src/vnet/session/application.c b/src/vnet/session/application.c
index 0dcb3e6ad94..7777c7275b3 100644
--- a/src/vnet/session/application.c
+++ b/src/vnet/session/application.c
@@ -550,6 +550,8 @@ application_alloc_and_init (app_init_args_t * a)
props->use_mq_eventfd = 1;
if (options[APP_OPTIONS_TLS_ENGINE])
app->tls_engine = options[APP_OPTIONS_TLS_ENGINE];
+ if (options[APP_OPTIONS_MAX_FIFO_SIZE])
+ props->max_fifo_size = options[APP_OPTIONS_MAX_FIFO_SIZE];
if (options[APP_OPTIONS_HIGH_WATERMARK])
props->high_watermark = options[APP_OPTIONS_HIGH_WATERMARK];
if (options[APP_OPTIONS_LOW_WATERMARK])
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index 9943576377d..90b5a5a277e 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -261,6 +261,9 @@ int app_worker_migrate_notify (app_worker_t * app_wrk, session_t * s,
session_handle_t new_sh);
int app_worker_builtin_rx (app_worker_t * app_wrk, session_t * s);
int app_worker_builtin_tx (app_worker_t * app_wrk, session_t * s);
+int app_worker_session_fifo_tuning (app_worker_t * app_wrk, session_t * s,
+ svm_fifo_t * f,
+ session_ft_action_t act, u32 len);
segment_manager_t *app_worker_get_listen_segment_manager (app_worker_t *,
session_t *);
segment_manager_t *app_worker_get_connect_segment_manager (app_worker_t *);
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index d03994fc1f9..2ecabb03204 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -68,6 +68,10 @@ typedef struct session_cb_vft_
/** Cert and key pair delete notification */
int (*app_cert_key_pair_delete_callback) (app_cert_key_pair_t * ckpair);
+ /** Delegate fifo-tuning-logic to application */
+ int (*fifo_tuning_callback) (session_t * s, svm_fifo_t * f,
+ session_ft_action_t act, u32 bytes);
+
} session_cb_vft_t;
#define foreach_app_init_args \
@@ -201,6 +205,7 @@ typedef enum
APP_OPTIONS_PROXY_TRANSPORT,
APP_OPTIONS_ACCEPT_COOKIE,
APP_OPTIONS_TLS_ENGINE,
+ APP_OPTIONS_MAX_FIFO_SIZE,
APP_OPTIONS_HIGH_WATERMARK,
APP_OPTIONS_LOW_WATERMARK,
APP_OPTIONS_N_OPTIONS
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index 0b67d2922bf..1793998f1e0 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -275,11 +275,16 @@ app_worker_init_accepted (session_t * s)
app_worker_t *app_wrk;
segment_manager_t *sm;
session_t *listener;
+ application_t *app;
listener = listen_session_get_from_handle (s->listener_handle);
app_wrk = application_listener_select_worker (listener);
s->app_wrk_index = app_wrk->wrk_index;
+ app = application_get (app_wrk->app_index);
+ if (app->cb_fns.fifo_tuning_callback)
+ s->flags |= SESSION_F_CUSTOM_FIFO_TUNING;
+
sm = app_worker_get_listen_segment_manager (app_wrk, listener);
if (app_worker_alloc_session_fifos (sm, s))
return -1;
@@ -307,6 +312,10 @@ app_worker_init_connected (app_worker_t * app_wrk, session_t * s)
if (app_worker_alloc_session_fifos (sm, s))
return -1;
}
+
+ if (app->cb_fns.fifo_tuning_callback)
+ s->flags |= SESSION_F_CUSTOM_FIFO_TUNING;
+
return 0;
}
@@ -433,6 +442,15 @@ app_worker_connect_session (app_worker_t * app, session_endpoint_t * sep,
}
int
+app_worker_session_fifo_tuning (app_worker_t * app_wrk, session_t * s,
+ svm_fifo_t * f,
+ session_ft_action_t act, u32 len)
+{
+ application_t *app = application_get (app_wrk->app_index);
+ return app->cb_fns.fifo_tuning_callback (s, f, act, len);
+}
+
+int
app_worker_alloc_connects_segment_manager (app_worker_t * app_wrk)
{
segment_manager_t *sm;
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index 25fbd6f2c04..eb3f63c9a6c 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -26,11 +26,12 @@ typedef struct segment_manager_main_
/*
* Configuration
*/
- u32 default_fifo_size; /**< default rx/tx fifo size */
- u32 default_segment_size; /**< default fifo segment size */
- u32 default_app_mq_size; /**< default app msg q size */
- u8 default_high_watermark; /**< default high watermark % */
- u8 default_low_watermark; /**< default low watermark % */
+ u32 default_fifo_size; /**< default rx/tx fifo size */
+ u32 default_segment_size; /**< default fifo segment size */
+ u32 default_app_mq_size; /**< default app msg q size */
+ u32 default_max_fifo_size; /**< default max fifo size */
+ u8 default_high_watermark; /**< default high watermark % */
+ u8 default_low_watermark; /**< default low watermark % */
} segment_manager_main_t;
static segment_manager_main_t sm_main;
@@ -56,6 +57,7 @@ segment_manager_props_init (segment_manager_props_t * props)
props->rx_fifo_size = sm_main.default_fifo_size;
props->tx_fifo_size = sm_main.default_fifo_size;
props->evt_q_size = sm_main.default_app_mq_size;
+ props->max_fifo_size = sm_main.default_max_fifo_size;
props->high_watermark = sm_main.default_high_watermark;
props->low_watermark = sm_main.default_low_watermark;
props->n_slices = vlib_num_workers () + 1;
@@ -335,6 +337,10 @@ segment_manager_init (segment_manager_t * sm)
sm_main.default_segment_size);
prealloc_fifo_pairs = props->prealloc_fifos;
+ sm->max_fifo_size = props->max_fifo_size ?
+ props->max_fifo_size : sm_main.default_max_fifo_size;
+ sm->max_fifo_size = clib_max (sm->max_fifo_size, 4096);
+
segment_manager_set_watermarks (sm,
props->high_watermark,
props->low_watermark);
@@ -832,6 +838,7 @@ segment_manager_main_init (segment_manager_main_init_args_t * a)
sm->default_fifo_size = 1 << 12;
sm->default_segment_size = 1 << 20;
sm->default_app_mq_size = 128;
+ sm->default_max_fifo_size = 4 << 20;
sm->default_high_watermark = 80;
sm->default_low_watermark = 50;
}
@@ -844,6 +851,9 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input,
u8 show_segments = 0, verbose = 0;
segment_manager_t *sm;
fifo_segment_t *seg;
+ app_worker_t *app_wrk;
+ application_t *app;
+ u8 custom_logic;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
@@ -859,13 +869,22 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input,
pool_elts (smm->segment_managers));
if (verbose && pool_elts (smm->segment_managers))
{
- vlib_cli_output (vm, "%-10s%=15s%=12s", "Index", "App Index",
- "Segments");
+ vlib_cli_output (vm, "%-6s%=10s%=10s%=13s%=11s%=11s%=12s",
+ "Index", "AppIndex", "Segments", "MaxFifoSize",
+ "HighWater", "LowWater", "FifoTuning");
/* *INDENT-OFF* */
pool_foreach (sm, smm->segment_managers, ({
- vlib_cli_output (vm, "%-10d%=15d%=12d", segment_manager_index (sm),
- sm->app_wrk_index, pool_elts (sm->segments));
+ app_wrk = app_worker_get_if_valid (sm->app_wrk_index);
+ app = app_wrk ? application_get (app_wrk->app_index) : 0;
+ custom_logic = (app && (app->cb_fns.fifo_tuning_callback)) ? 1 : 0;
+
+ vlib_cli_output (vm, "%-6d%=10d%=10d%=13U%=11d%=11d%=12s",
+ segment_manager_index (sm),
+ sm->app_wrk_index, pool_elts (sm->segments),
+ format_memory_size, sm->max_fifo_size,
+ sm->high_watermark, sm->low_watermark,
+ custom_logic ? "custom" : "none");
}));
/* *INDENT-ON* */
diff --git a/src/vnet/session/segment_manager.h b/src/vnet/session/segment_manager.h
index cad95509b2e..688711a3312 100644
--- a/src/vnet/session/segment_manager.h
+++ b/src/vnet/session/segment_manager.h
@@ -19,6 +19,7 @@
#include <vppinfra/lock.h>
#include <vppinfra/valloc.h>
#include <svm/fifo_segment.h>
+#include <vnet/session/session_types.h>
typedef struct _segment_manager_props
{
@@ -34,6 +35,7 @@ typedef struct _segment_manager_props
u8 n_slices; /**< number of fs slices/threads */
ssvm_segment_type_t segment_type; /**< seg type: if set to SSVM_N_TYPES,
private segments are used */
+ u32 max_fifo_size; /**< max fifo size */
u8 high_watermark; /**< memory usage high watermark % */
u8 low_watermark; /**< memory usage low watermark % */
} segment_manager_props_t;
@@ -61,6 +63,7 @@ typedef struct _segment_manager
*/
svm_msg_q_t *event_queue;
+ u32 max_fifo_size;
u8 high_watermark;
u8 low_watermark;
} segment_manager_t;
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index b006cfaf2bb..e9cda361f37 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -396,6 +396,24 @@ session_enqueue_chain_tail (session_t * s, vlib_buffer_t * b,
return 0;
}
+void
+session_fifo_tuning (session_t * s, svm_fifo_t * f,
+ session_ft_action_t act, u32 len)
+{
+ if (s->flags & SESSION_F_CUSTOM_FIFO_TUNING)
+ {
+ app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
+ app_worker_session_fifo_tuning (app_wrk, s, f, act, len);
+ if (CLIB_ASSERT_ENABLE)
+ {
+ segment_manager_t *sm;
+ sm = segment_manager_get (f->segment_manager);
+ ASSERT (f->size >= 4096);
+ ASSERT (f->size <= sm->max_fifo_size);
+ }
+ }
+}
+
/*
* Enqueue data for delivery to session peer. Does not notify peer of enqueue
* event but on request can queue notification events for later delivery by
@@ -458,6 +476,8 @@ session_enqueue_stream_connection (transport_connection_t * tc,
s->flags |= SESSION_F_RX_EVT;
vec_add1 (wrk->session_to_enqueue[tc->proto], s->session_index);
}
+
+ session_fifo_tuning (s, s->rx_fifo, SESSION_FT_ACTION_ENQUEUED, 0);
}
return enqueued;
@@ -495,6 +515,8 @@ session_enqueue_dgram_connection (session_t * s,
s->flags |= SESSION_F_RX_EVT;
vec_add1 (wrk->session_to_enqueue[proto], s->session_index);
}
+
+ session_fifo_tuning (s, s->rx_fifo, SESSION_FT_ACTION_ENQUEUED, 0);
}
return enqueued;
}
@@ -514,6 +536,7 @@ session_tx_fifo_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
u32 rv;
rv = svm_fifo_dequeue_drop (s->tx_fifo, max_bytes);
+ session_fifo_tuning (s, s->tx_fifo, SESSION_FT_ACTION_DEQUEUED, rv);
if (svm_fifo_needs_deq_ntf (s->tx_fifo, max_bytes))
session_dequeue_notify (s);
@@ -674,6 +697,9 @@ session_main_flush_enqueue_events (u8 transport_proto, u32 thread_index)
continue;
}
+ session_fifo_tuning (s, s->rx_fifo, SESSION_FT_ACTION_ENQUEUED,
+ 0 /* TODO/not needed */ );
+
if (PREDICT_FALSE (session_enqueue_notify_inline (s)))
errors++;
}
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index be8ad9cdb83..aa0e8650747 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -123,6 +123,13 @@ typedef enum
SESSION_CLEANUP_SESSION,
} session_cleanup_ntf_t;
+typedef enum session_ft_action_
+{
+ SESSION_FT_ACTION_ENQUEUED,
+ SESSION_FT_ACTION_DEQUEUED,
+ SESSION_FT_ACTION_N_ACTIONS
+} session_ft_action_t;
+
/*
* Session states
*/
@@ -154,6 +161,7 @@ typedef enum
_(CUSTOM_TX, "custom-tx") \
_(IS_MIGRATING, "migrating") \
_(UNIDIRECTIONAL, "unidirectional") \
+ _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
typedef enum session_flags_bits_
{