aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm/message_queue.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-07-11 16:35:38 -0700
committerDave Barach <openvpp@barachs.net>2018-07-18 18:54:07 +0000
commite91bdb3783653b34c1bbf9738a739e646d02f533 (patch)
tree8472b991b10c3843cf0ac8245a7852ad4851fcfa /src/svm/message_queue.c
parent19668e8a3984aec0e91811696e8b4194e3019cb3 (diff)
svm: make message queue more compact
Change-Id: Id45957163c2b95a2300a8ac9104fc92b9cc928ed Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm/message_queue.c')
-rw-r--r--src/svm/message_queue.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c
index 77c15ed4654..0f9be9c11b7 100644
--- a/src/svm/message_queue.c
+++ b/src/svm/message_queue.c
@@ -38,19 +38,36 @@ svm_msg_q_ring_data (svm_msg_q_ring_t * ring, u32 elt_index)
svm_msg_q_t *
svm_msg_q_alloc (svm_msg_q_cfg_t * cfg)
{
+ svm_msg_q_ring_cfg_t *ring_cfg;
svm_msg_q_ring_t *ring;
+ u8 *base, *rings_ptr;
+ uword rings_sz = 0;
+ vec_header_t *vh;
svm_msg_q_t *mq;
- uword size;
+ u32 vec_sz;
int i;
- if (!cfg)
+ ASSERT (cfg);
+
+ vec_sz = vec_header_bytes (0) + sizeof (svm_msg_q_ring_t) * cfg->n_rings;
+ for (i = 0; i < cfg->n_rings; i++)
+ {
+ if (cfg->ring_cfgs[i].data)
+ continue;
+ ring_cfg = &cfg->ring_cfgs[i];
+ rings_sz += (uword) ring_cfg->nitems * ring_cfg->elsize;
+ }
+
+ base = clib_mem_alloc_aligned (sizeof (svm_msg_q_t) + vec_sz + rings_sz,
+ CLIB_CACHE_LINE_BYTES);
+ if (!base)
return 0;
- mq = clib_mem_alloc_aligned (sizeof (svm_msg_q_t), CLIB_CACHE_LINE_BYTES);
- memset (mq, 0, sizeof (*mq));
- mq->q = svm_queue_init (cfg->q_nitems, sizeof (svm_msg_q_msg_t),
- cfg->consumer_pid, 0);
- vec_validate (mq->rings, cfg->n_rings - 1);
+ mq = (svm_msg_q_t *) base;
+ vh = (vec_header_t *) (base + sizeof (svm_msg_q_t));
+ vh->len = cfg->n_rings;
+ mq->rings = (svm_msg_q_ring_t *) (vh + 1);
+ rings_ptr = (u8 *) mq->rings + vec_sz;
for (i = 0; i < cfg->n_rings; i++)
{
ring = &mq->rings[i];
@@ -60,10 +77,12 @@ svm_msg_q_alloc (svm_msg_q_cfg_t * cfg)
ring->data = cfg->ring_cfgs[i].data;
else
{
- size = (uword) ring->nitems * ring->elsize;
- ring->data = clib_mem_alloc_aligned (size, CLIB_CACHE_LINE_BYTES);
+ ring->data = rings_ptr;
+ rings_ptr += (uword) ring->nitems * ring->elsize;
}
}
+ mq->q = svm_queue_init (cfg->q_nitems, sizeof (svm_msg_q_msg_t),
+ cfg->consumer_pid, 0);
return mq;
}
@@ -71,13 +90,7 @@ svm_msg_q_alloc (svm_msg_q_cfg_t * cfg)
void
svm_msg_q_free (svm_msg_q_t * mq)
{
- svm_msg_q_ring_t *ring;
-
- vec_foreach (ring, mq->rings)
- {
- clib_mem_free (ring->data);
- }
- vec_free (mq->rings);
+ svm_queue_free (mq->q);
clib_mem_free (mq);
}