diff options
author | Florin Coras <fcoras@cisco.com> | 2021-01-27 18:08:25 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2021-01-28 15:57:33 +0000 |
commit | 80b742592bd227cedb22362abb6286838977ba4f (patch) | |
tree | ca87e72c58df443744cc6b50a65feaf947ef36de /src/svm/fifo_segment.c | |
parent | b13ba133fbdb3a66a6c3ddf19a2bc80525b92606 (diff) |
svm vcl: add helper fn that discovers mqs in segment
Type: improvement
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I1b083ee793a7cf91b1001bfe88353fa5e6515c42
Diffstat (limited to 'src/svm/fifo_segment.c')
-rw-r--r-- | src/svm/fifo_segment.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c index 3e9aecb9dc8..76cc046efec 100644 --- a/src/svm/fifo_segment.c +++ b/src/svm/fifo_segment.c @@ -301,6 +301,7 @@ fifo_segment_init (fifo_segment_t * fs) fsh->max_log2_fifo_size = min_log2 (max_fifo); fsh->n_cached_bytes = 0; fsh->n_reserved_bytes = fsh->byte_index; + fsh->start_byte_index = fsh->byte_index; ASSERT (fsh->max_byte_index <= sh->ssvm_size - offset); fs->max_byte_index = fsh->max_byte_index; @@ -1054,6 +1055,38 @@ fifo_segment_msg_q_attach (fifo_segment_t *fs, uword offset, u32 mq_index) return mq; } +void +fifo_segment_msg_qs_discover (fifo_segment_t *fs, int *fds, u32 n_fds) +{ + svm_msg_q_shared_t *smq; + u32 n_mqs, size, i; + uword offset = 0, n_alloced; + svm_msg_q_t *mq; + + n_mqs = fs->h->n_mqs; + if (n_fds && n_mqs != n_fds) + { + clib_warning ("expected %u fds got %u", n_mqs, n_fds); + return; + } + + vec_validate (fs->mqs, n_mqs - 1); + n_alloced = fs->h->n_reserved_bytes - fs->h->start_byte_index; + ASSERT (n_alloced % n_mqs == 0); + size = n_alloced / n_mqs; + + offset = fs->h->start_byte_index; + for (i = 0; i < n_mqs; i++) + { + mq = vec_elt_at_index (fs->mqs, i); + smq = (svm_msg_q_shared_t *) ((u8 *) fs->h + offset); + svm_msg_q_attach (mq, smq); + if (n_fds) + svm_msg_q_set_eventfd (mq, fds[i]); + offset += size; + } +} + uword fifo_segment_msg_q_offset (fifo_segment_t *fs, u32 mq_index) { |