summaryrefslogtreecommitdiffstats
path: root/src/svm/queue.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-12-27 10:26:56 -0800
committerDave Barach <openvpp@barachs.net>2019-12-30 19:50:38 +0000
commitfea813ae3de5343a2bc91306fddf6dbd1832f93d (patch)
treeabb186eec7f6ed246077f24798ebd7161f731cec /src/svm/queue.c
parent9f3f18f99fd321cdcfc331e92b10b64f0ef590b3 (diff)
svm: broadcast on raw dequeues and full rings
Type: fix Change-Id: I0cac9001290e7ed4e2e318ae62c56e97ec75a3db Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm/queue.c')
-rw-r--r--src/svm/queue.c28
1 files changed, 21 insertions, 7 deletions
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;
}