aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/hs_apps/vcl/vcl_test.h5
-rw-r--r--src/plugins/hs_apps/vcl/vcl_test_server.c23
-rw-r--r--src/svm/svm_fifo.c49
-rw-r--r--src/svm/svm_fifo.h18
-rw-r--r--src/vcl/vppcom.c35
-rw-r--r--src/vcl/vppcom.h8
6 files changed, 78 insertions, 60 deletions
diff --git a/src/plugins/hs_apps/vcl/vcl_test.h b/src/plugins/hs_apps/vcl/vcl_test.h
index c6b9230e6c9..6bb3446cf48 100644
--- a/src/plugins/hs_apps/vcl/vcl_test.h
+++ b/src/plugins/hs_apps/vcl/vcl_test.h
@@ -444,7 +444,8 @@ vcl_test_read (int fd, uint8_t * buf, uint32_t nbytes,
}
static inline int
-vcl_test_read_ds (int fd, vppcom_data_segments_t ds, vcl_test_stats_t * stats)
+vcl_test_read_ds (int fd, vppcom_data_segment_t * ds,
+ vcl_test_stats_t * stats)
{
int rx_bytes;
@@ -452,7 +453,7 @@ vcl_test_read_ds (int fd, vppcom_data_segments_t ds, vcl_test_stats_t * stats)
{
if (stats)
stats->rx_xacts++;
- rx_bytes = vppcom_session_read_segments (fd, ds);
+ rx_bytes = vppcom_session_read_segments (fd, ds, 2, ~0);
if (rx_bytes < 0)
{
diff --git a/src/plugins/hs_apps/vcl/vcl_test_server.c b/src/plugins/hs_apps/vcl/vcl_test_server.c
index af5b914cdac..d55fef30e89 100644
--- a/src/plugins/hs_apps/vcl/vcl_test_server.c
+++ b/src/plugins/hs_apps/vcl/vcl_test_server.c
@@ -38,7 +38,7 @@ typedef struct
vcl_test_stats_t stats;
vppcom_endpt_t endpt;
uint8_t ip[16];
- vppcom_data_segments_t ds;
+ vppcom_data_segment_t ds[2];
} vcl_test_server_conn_t;
typedef struct
@@ -246,20 +246,33 @@ vts_server_rx (vcl_test_server_conn_t * conn, int rx_bytes)
}
if (vsm->use_ds)
- vppcom_session_free_segments (conn->fd, conn->ds);
+ vppcom_session_free_segments (conn->fd, rx_bytes);
if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
}
static void
+vts_copy_ds (void *buf, vppcom_data_segment_t * ds, u32 max_bytes)
+{
+ uint32_t n_bytes = 0, ds_idx = 0;
+
+ while (n_bytes < max_bytes)
+ {
+ clib_memcpy_fast (buf + n_bytes, ds[ds_idx].data,
+ clib_min (ds[ds_idx].len, max_bytes - n_bytes));
+ ds_idx += 1;
+ }
+}
+
+static void
vts_server_echo (vcl_test_server_conn_t * conn, int rx_bytes)
{
vcl_test_server_main_t *vsm = &vcl_server_main;
int tx_bytes, nbytes, pos;
if (vsm->use_ds)
- vppcom_data_segment_copy (conn->buf, conn->ds, rx_bytes);
+ vts_copy_ds (conn->buf, conn->ds, rx_bytes);
/* If it looks vaguely like a string, make sure it's terminated */
pos = rx_bytes < conn->buf_size ? rx_bytes : conn->buf_size - 1;
@@ -590,7 +603,7 @@ vts_conn_read_config (vcl_test_server_conn_t * conn)
{
/* We could avoid the copy if the first segment is big enough but this
* just simplifies things */
- vppcom_data_segment_copy (conn->buf, conn->ds, sizeof (vcl_test_cfg_t));
+ vts_copy_ds (conn->buf, conn->ds, sizeof (vcl_test_cfg_t));
}
return (vcl_test_cfg_t *) conn->buf;
}
@@ -692,7 +705,7 @@ vts_worker_loop (void *arg)
if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
{
if (vsm->use_ds)
- vppcom_session_free_segments (conn->fd, conn->ds);
+ vppcom_session_free_segments (conn->fd, rx_bytes);
vts_handle_cfg (wrk, rx_cfg, conn, rx_bytes);
if (!wrk->nfds)
{
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index fda9481e721..2cce2bf50b3 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -1136,9 +1136,11 @@ svm_fifo_fill_chunk_list (svm_fifo_t * f)
}
int
-svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs)
+svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs, u32 n_segs,
+ u32 max_bytes)
{
- u32 cursize, head, tail, head_idx;
+ u32 cursize, to_read, head, tail, fs_index = 1, n_bytes, head_pos, len;
+ svm_fifo_chunk_t *c;
f_load_head_tail_cons (f, &head, &tail);
@@ -1148,37 +1150,26 @@ svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs)
if (PREDICT_FALSE (cursize == 0))
return SVM_FIFO_EEMPTY;
- head_idx = head;
+ to_read = clib_min (cursize, max_bytes);
- if (tail < head)
- {
- fs[0].len = f->size - head_idx;
- fs[0].data = f->head_chunk->data + head_idx;
- fs[1].len = cursize - fs[0].len;
- fs[1].data = f->head_chunk->data;
- }
- else
+ c = f->head_chunk;
+ head_pos = head - c->start_byte;
+ fs[0].data = c->data + head_pos;
+ fs[0].len = c->length - head_pos;
+ n_bytes = fs[0].len;
+ c = c->next;
+
+ while (n_bytes < to_read && fs_index < n_segs)
{
- fs[0].len = cursize;
- fs[0].data = f->head_chunk->data + head_idx;
- fs[1].len = 0;
- fs[1].data = 0;
+ len = clib_min (c->length, to_read - n_bytes);
+ fs[fs_index].data = c->data;
+ fs[fs_index].len = len;
+ n_bytes += len;
+ c = c->next;
+ fs_index += 1;
}
- return cursize;
-}
-
-void
-svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs)
-{
- u32 head;
- /* consumer owned index */
- head = f->head;
-
- ASSERT (fs[0].data == f->head_chunk->data + head);
- head = (head + fs[0].len + fs[1].len);
- /* store-rel: consumer owned index (paired with load-acq in producer) */
- clib_atomic_store_rel_n (&f->head, head);
+ return n_bytes;
}
/**
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index f7503c8e900..93ef006fd48 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -348,8 +348,22 @@ int svm_fifo_dequeue_drop (svm_fifo_t * f, u32 len);
* @param f fifo
*/
void svm_fifo_dequeue_drop_all (svm_fifo_t * f);
-int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs);
-void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs);
+/**
+ * Get pointers to fifo chunks data in @ref svm_fifo_seg_t array
+ *
+ * Populates fifo segment array with pointers to fifo chunk data and lengths.
+ * Because this returns pointers to data, it must be paired with
+ * @ref svm_fifo_dequeue_drop to actually release the fifo chunks after the
+ * data is consumed.
+ *
+ * @param f fifo
+ * @param fs array of fifo segments allocated by caller
+ * @param n_segs number of fifo segments in array
+ * @param max_bytes max bytes to be mapped to fifo segments
+ * @return number of bytes in fifo segments or SVM_FIFO_EEMPTY
+ */
+int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs, u32 n_segs,
+ u32 max_bytes);
/**
* Add io events subscriber to list
*
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index 8a934c3686a..56f50ad5cba 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -1929,7 +1929,8 @@ vppcom_session_peek (uint32_t session_handle, void *buf, int n)
int
vppcom_session_read_segments (uint32_t session_handle,
- vppcom_data_segments_t ds)
+ vppcom_data_segment_t * ds, uint32_t n_segments,
+ uint32_t max_bytes)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
int n_read = 0, is_nonblocking;
@@ -1982,15 +1983,13 @@ vppcom_session_read_segments (uint32_t session_handle,
}
}
- n_read = svm_fifo_segments (rx_fifo, (svm_fifo_seg_t *) ds);
- svm_fifo_unset_event (rx_fifo);
-
+ n_read = svm_fifo_segments (rx_fifo, (svm_fifo_seg_t *) ds, n_segments,
+ max_bytes);
return n_read;
}
void
-vppcom_session_free_segments (uint32_t session_handle,
- vppcom_data_segments_t ds)
+vppcom_session_free_segments (uint32_t session_handle, uint32_t n_bytes)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
vcl_session_t *s;
@@ -1999,20 +1998,20 @@ vppcom_session_free_segments (uint32_t session_handle,
if (PREDICT_FALSE (!s || s->is_vep))
return;
- svm_fifo_segments_free (s->rx_fifo, (svm_fifo_seg_t *) ds);
-}
-
-int
-vppcom_data_segment_copy (void *buf, vppcom_data_segments_t ds, u32 max_bytes)
-{
- u32 first_copy = clib_min (ds[0].len, max_bytes);
- clib_memcpy_fast (buf, ds[0].data, first_copy);
- if (first_copy < max_bytes)
+ svm_fifo_dequeue_drop (s->rx_fifo, n_bytes);
+ if (svm_fifo_is_empty_cons (s->rx_fifo))
{
- clib_memcpy_fast (buf + first_copy, ds[1].data,
- clib_min (ds[1].len, max_bytes - first_copy));
+ svm_fifo_unset_event (s->rx_fifo);
+ if (!svm_fifo_is_empty_cons (s->rx_fifo)
+ && svm_fifo_set_event (s->rx_fifo)
+ && VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK))
+ {
+ session_event_t *e;
+ vec_add2 (wrk->unhandled_evts_vector, e, 1);
+ e->event_type = SESSION_IO_EVT_RX;
+ e->session_index = s->session_index;
+ }
}
- return 0;
}
static u8
diff --git a/src/vcl/vppcom.h b/src/vcl/vppcom.h
index 61df64a6852..f4386682a1b 100644
--- a/src/vcl/vppcom.h
+++ b/src/vcl/vppcom.h
@@ -199,15 +199,15 @@ extern int vppcom_session_index (vcl_session_handle_t session_handle);
extern int vppcom_session_worker (vcl_session_handle_t session_handle);
extern int vppcom_session_read_segments (uint32_t session_handle,
- vppcom_data_segments_t ds);
+ vppcom_data_segment_t * ds,
+ uint32_t n_segments,
+ uint32_t max_bytes);
extern void vppcom_session_free_segments (uint32_t session_handle,
- vppcom_data_segments_t ds);
+ uint32_t n_bytes);
extern int vppcom_session_tls_add_cert (uint32_t session_handle, char *cert,
uint32_t cert_len);
extern int vppcom_session_tls_add_key (uint32_t session_handle, char *key,
uint32_t key_len);
-extern int vppcom_data_segment_copy (void *buf, vppcom_data_segments_t ds,
- uint32_t max_bytes);
extern int vppcom_unformat_proto (uint8_t * proto, char *proto_str);
extern int vppcom_session_is_connectable_listener (uint32_t session_handle);
extern int vppcom_session_listener (uint32_t session_handle);