diff options
-rw-r--r-- | src/svm/message_queue.c | 6 | ||||
-rw-r--r-- | src/svm/queue.c | 28 | ||||
-rw-r--r-- | src/svm/queue.h | 1 |
3 files changed, 28 insertions, 7 deletions
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c index 10266a8039c..b381173c70b 100644 --- a/src/svm/message_queue.c +++ b/src/svm/message_queue.c @@ -170,6 +170,7 @@ void svm_msg_q_free_msg (svm_msg_q_t * mq, svm_msg_q_msg_t * msg) { svm_msg_q_ring_t *ring; + int need_signal; ASSERT (vec_len (mq->rings) > msg->ring_index); ring = &mq->rings[msg->ring_index]; @@ -183,7 +184,12 @@ svm_msg_q_free_msg (svm_msg_q_t * mq, svm_msg_q_msg_t * msg) /* for now, expect messages to be processed in order */ ASSERT (0); } + + need_signal = ring->cursize == ring->nitems; clib_atomic_fetch_sub (&ring->cursize, 1); + + if (PREDICT_FALSE (need_signal)) + svm_queue_send_signal (mq->q, 0); } static int diff --git a/src/svm/queue.c b/src/svm/queue.c index c9db454db1e..4d37a5f7810 100644 --- a/src/svm/queue.c +++ b/src/svm/queue.c @@ -112,7 +112,7 @@ svm_queue_is_full (svm_queue_t * q) } static inline void -svm_queue_send_signal (svm_queue_t * q, u8 is_prod) +svm_queue_send_signal_inline (svm_queue_t * q, u8 is_prod) { if (q->producer_evtfd == -1) { @@ -125,9 +125,17 @@ svm_queue_send_signal (svm_queue_t * q, u8 is_prod) ASSERT (q->consumer_evtfd > 0 && q->producer_evtfd > 0); fd = is_prod ? q->producer_evtfd : q->consumer_evtfd; rv = write (fd, &data, sizeof (data)); + if (PREDICT_FALSE (rv)) + clib_unix_warning ("signal write returned %d", rv); } } +void +svm_queue_send_signal (svm_queue_t * q, u8 is_prod) +{ + svm_queue_send_signal_inline (q, is_prod); +} + static inline void svm_queue_wait_inline (svm_queue_t * q) { @@ -212,7 +220,7 @@ svm_queue_add_nolock (svm_queue_t * q, u8 * elem) q->tail = 0; if (need_broadcast) - svm_queue_send_signal (q, 1); + svm_queue_send_signal_inline (q, 1); return 0; } @@ -228,7 +236,7 @@ svm_queue_add_raw (svm_queue_t * q, u8 * elem) q->cursize++; if (q->cursize == 1) - svm_queue_send_signal (q, 1); + svm_queue_send_signal_inline (q, 1); } @@ -275,7 +283,7 @@ svm_queue_add (svm_queue_t * q, u8 * elem, int nowait) q->tail = 0; if (need_broadcast) - svm_queue_send_signal (q, 1); + svm_queue_send_signal_inline (q, 1); svm_queue_unlock (q); @@ -334,7 +342,7 @@ svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait) q->tail = 0; if (need_broadcast) - svm_queue_send_signal (q, 1); + svm_queue_send_signal_inline (q, 1); svm_queue_unlock (q); @@ -402,7 +410,7 @@ svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond, q->head = 0; if (need_broadcast) - svm_queue_send_signal (q, 0); + svm_queue_send_signal_inline (q, 0); svm_queue_unlock (q); @@ -434,7 +442,7 @@ svm_queue_sub2 (svm_queue_t * q, u8 * elem) svm_queue_unlock (q); if (need_broadcast) - svm_queue_send_signal (q, 0); + svm_queue_send_signal_inline (q, 0); return 0; } @@ -442,6 +450,7 @@ svm_queue_sub2 (svm_queue_t * q, u8 * elem) int svm_queue_sub_raw (svm_queue_t * q, u8 * elem) { + int need_broadcast; i8 *headp; if (PREDICT_FALSE (q->cursize == 0)) @@ -453,9 +462,14 @@ svm_queue_sub_raw (svm_queue_t * q, u8 * elem) headp = (i8 *) (&q->data[0] + q->elsize * q->head); clib_memcpy_fast (elem, headp, q->elsize); + need_broadcast = q->cursize == q->maxsize; + q->head = (q->head + 1) % q->maxsize; q->cursize--; + if (PREDICT_FALSE (need_broadcast)) + svm_queue_send_signal_inline (q, 0); + return 0; } diff --git a/src/svm/queue.h b/src/svm/queue.h index 2630f17a86c..9d21b24d7ea 100644 --- a/src/svm/queue.h +++ b/src/svm/queue.h @@ -77,6 +77,7 @@ int svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond, u32 time); int svm_queue_sub2 (svm_queue_t * q, u8 * elem); void svm_queue_lock (svm_queue_t * q); +void svm_queue_send_signal (svm_queue_t * q, u8 is_prod); void svm_queue_unlock (svm_queue_t * q); int svm_queue_is_full (svm_queue_t * q); int svm_queue_add_nolock (svm_queue_t * q, u8 * elem); |