diff options
author | Florin Coras <fcoras@cisco.com> | 2020-12-18 09:19:18 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2020-12-20 20:04:17 +0000 |
commit | 40a5da8e96a910287001e9db119d1f0134fc9fb8 (patch) | |
tree | c87e9bef047c7bd73d85454dd9394398117c13d1 /src/svm | |
parent | 3daf1f5d3a5918564ae2acdd748b24acaef5bce0 (diff) |
tls: use fifo segments instead of chunks
Type: refactor
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Id67cf8a3e1c5c9b4160689fde5de9ce7ed8a2ee3
Diffstat (limited to 'src/svm')
-rw-r--r-- | src/svm/svm_fifo.c | 36 | ||||
-rw-r--r-- | src/svm/svm_fifo.h | 15 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index f1ac8d49b92..ff941a7a6dd 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -1222,6 +1222,42 @@ svm_fifo_fill_chunk_list (svm_fifo_t * f) } int +svm_fifo_provision_chunks (svm_fifo_t *f, svm_fifo_seg_t *fs, u32 n_segs, + u32 len) +{ + u32 head, tail, n_avail, head_pos, n_bytes, fs_index = 1, clen; + svm_fifo_chunk_t *c; + + f_load_head_tail_prod (f, &head, &tail); + + if (f_free_count (f, head, tail) < len) + return SVM_FIFO_EFULL; + + n_avail = f_chunk_end (f->end_chunk) - tail; + + if (n_avail < len && f_try_chunk_alloc (f, head, tail, len)) + return SVM_FIFO_EGROW; + + c = f->tail_chunk; + head_pos = (tail - c->start_byte); + fs[0].data = c->data + head_pos; + fs[0].len = clib_min (c->length - head_pos, len); + n_bytes = fs[0].len; + + while (n_bytes < len && fs_index < n_segs) + { + c = c->next; + clen = clib_min (c->length, len - n_bytes); + fs[fs_index].data = c->data; + fs[fs_index].len = clen; + n_bytes += clen; + fs_index += 1; + } + + return fs_index; +} + +int svm_fifo_segments (svm_fifo_t * f, u32 offset, svm_fifo_seg_t * fs, u32 n_segs, u32 max_bytes) { diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h index 4239e9d78ea..2a054526865 100644 --- a/src/svm/svm_fifo.h +++ b/src/svm/svm_fifo.h @@ -208,6 +208,21 @@ svm_fifo_chunk_t *svm_fifo_chunk_alloc (u32 size); */ int svm_fifo_fill_chunk_list (svm_fifo_t * f); /** + * Provision and return chunks for number of bytes requested + * + * Allocates enough chunks to cover the bytes requested and returns them + * in the fifo segment array. The number of bytes provisioned may be less + * than requested if not enough segments were provided. + * + * @param f fifo + * @param fs array of fifo segments + * @param n_segs length of fifo segments array + * @param len number of bytes to preallocate + * @return number of fifo segments provisioned or error + */ +int svm_fifo_provision_chunks (svm_fifo_t *f, svm_fifo_seg_t *fs, u32 n_segs, + u32 len); +/** * Initialize rbtrees used for ooo lookups * * @param f fifo |