X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fmessage_queue.h;h=4b314b837e9048c63e5265e74b924e3c42669688;hb=86cff9cdaaffd795795c80e5bc0874390a14b3e1;hp=50f79fb0c191ea38f7d7ca1a2e6ca4e477579b72;hpb=213b1bb3b9652ce2937e3b47573cc54ee3008387;p=vpp.git diff --git a/src/svm/message_queue.h b/src/svm/message_queue.h index 50f79fb0c19..4b314b837e9 100644 --- a/src/svm/message_queue.h +++ b/src/svm/message_queue.h @@ -24,16 +24,30 @@ #include #include -typedef struct svm_msg_q_ring_ +typedef struct svm_msg_q_ring_shared_ { volatile u32 cursize; /**< current size of the ring */ u32 nitems; /**< max size of the ring */ volatile u32 head; /**< current head (for dequeue) */ volatile u32 tail; /**< current tail (for enqueue) */ u32 elsize; /**< size of an element */ - u8 *data; /**< chunk of memory for msg data */ + u8 data[0]; /**< chunk of memory for msg data */ +} svm_msg_q_ring_shared_t; + +typedef struct svm_msg_q_ring_ +{ + u32 nitems; /**< max size of the ring */ + u32 elsize; /**< size of an element */ + svm_msg_q_ring_shared_t *shr; /**< ring in shared memory */ } __clib_packed svm_msg_q_ring_t; +typedef struct svm_msg_q_shared_ +{ + u32 n_rings; /**< number of rings after q */ + u32 pad; /**< 8 byte alignment for q */ + svm_queue_t q[0]; /**< queue for exchanging messages */ +} __clib_packed svm_msg_q_shared_t; + typedef struct svm_msg_q_ { svm_queue_t *q; /**< queue for exchanging messages */ @@ -77,10 +91,12 @@ typedef union * ring configs * @return message queue */ -svm_msg_q_t *svm_msg_q_alloc (svm_msg_q_cfg_t * cfg); -svm_msg_q_t *svm_msg_q_init (void *base, svm_msg_q_cfg_t *cfg); +svm_msg_q_shared_t *svm_msg_q_alloc (svm_msg_q_cfg_t *cfg); +svm_msg_q_shared_t *svm_msg_q_init (void *base, svm_msg_q_cfg_t *cfg); uword svm_msg_q_size_to_alloc (svm_msg_q_cfg_t *cfg); +void svm_msg_q_attach (svm_msg_q_t *mq, void *smq_base); + /** * Free message queue * @@ -267,8 +283,8 @@ svm_msg_q_is_full (svm_msg_q_t * mq) static inline u8 svm_msg_q_ring_is_full (svm_msg_q_t * mq, u32 ring_index) { - ASSERT (ring_index < vec_len (mq->rings)); - return (mq->rings[ring_index].cursize == mq->rings[ring_index].nitems); + svm_msg_q_ring_t *ring = vec_elt_at_index (mq->rings, ring_index); + return (ring->shr->cursize >= ring->nitems); } /**