summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-12-27 10:26:56 -0800
committerDave Wallace <dwallacelf@gmail.com>2020-08-12 14:37:52 +0000
commit34ccf72c4adabfb06081917b702b017b85f8e21b (patch)
treee8e6215316064ca8058d2af0c8ce9d884f18809c /src/svm
parent1144fb0f98ad4c7b84aad6b480933fa409c6f4c7 (diff)
svm: broadcast on raw dequeues and full rings
Type: fix Change-Id: I0cac9001290e7ed4e2e318ae62c56e97ec75a3db Signed-off-by: Florin Coras <fcoras@cisco.com> (cherry picked from commit fea813ae3de5343a2bc91306fddf6dbd1832f93d)
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/message_queue.c6
-rw-r--r--src/svm/queue.c28
-rw-r--r--src/svm/queue.h1
3 files changed, 28 insertions, 7 deletions
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c
index 6113450e7cb..c8c54184dbe 100644
--- a/src/svm/message_queue.c
+++ b/src/svm/message_queue.c
@@ -169,6 +169,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];
@@ -182,7 +183,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);