summaryrefslogtreecommitdiffstats
path: root/src/svm/queue.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-08-02 10:45:44 -0700
committerDave Barach <openvpp@barachs.net>2018-08-10 20:26:24 +0000
commit993683150202254c6ba8dd43e087a7229edd5d4c (patch)
tree141ce2cdfe546bfe2ad46e66ac9569a33a895072 /src/svm/queue.c
parentf46663c65b0238311af93fcfa3030eefdb56e299 (diff)
vcl: support for eventfd mq signaling
- support eventfd based mq signaling. Based on configuration, vcl epoll/select can use either condvars or epoll on mq eventfds. - add vcl support for memfd segments - vpp explicitly registers cut-through segments with apps/vcl - if using eventfd, make ldp allow one call to libc_epoll_create. Needed for the message queue epfd - update svm_queue_t to allow blocking calls with eventfd signaling. Change-Id: I064151ac370bbe29bb16c968bf4e3659c8286bea Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/svm/queue.c')
-rw-r--r--src/svm/queue.c85
1 files changed, 67 insertions, 18 deletions
diff --git a/src/svm/queue.c b/src/svm/queue.c
index 0fa1fe9b230..771033d7d8a 100644
--- a/src/svm/queue.c
+++ b/src/svm/queue.c
@@ -27,6 +27,7 @@
#include <vppinfra/cache.h>
#include <svm/queue.h>
#include <vppinfra/time.h>
+#include <vppinfra/lock.h>
svm_queue_t *
svm_queue_init (void *base, int nels, int elsize)
@@ -127,6 +128,63 @@ svm_queue_send_signal (svm_queue_t * q, u8 is_prod)
}
}
+static inline void
+svm_queue_wait_inline (svm_queue_t * q)
+{
+ if (q->producer_evtfd == -1)
+ {
+ pthread_cond_wait (&q->condvar, &q->mutex);
+ }
+ else
+ {
+ /* Fake a wait for event. We could use epoll but that would mean
+ * using yet another fd. Should do for now */
+ u32 cursize = q->cursize;
+ pthread_mutex_unlock (&q->mutex);
+ while (q->cursize == cursize)
+ CLIB_PAUSE ();
+ pthread_mutex_lock (&q->mutex);
+ }
+}
+
+void
+svm_queue_wait (svm_queue_t * q)
+{
+ svm_queue_wait_inline (q);
+}
+
+static inline int
+svm_queue_timedwait_inline (svm_queue_t * q, double timeout)
+{
+ struct timespec ts;
+ ts.tv_sec = unix_time_now () + (u32) timeout;
+ ts.tv_nsec = (timeout - (u32) timeout) * 1e9;
+
+ if (q->producer_evtfd == -1)
+ {
+ return pthread_cond_timedwait (&q->condvar, &q->mutex, &ts);
+ }
+ else
+ {
+ double max_time = unix_time_now () + timeout;
+ u32 cursize = q->cursize;
+ int rv;
+
+ pthread_mutex_unlock (&q->mutex);
+ while (q->cursize == cursize && unix_time_now () < max_time)
+ CLIB_PAUSE ();
+ rv = unix_time_now () < max_time ? 0 : ETIMEDOUT;
+ pthread_mutex_lock (&q->mutex);
+ return rv;
+ }
+}
+
+int
+svm_queue_timedwait (svm_queue_t * q, double timeout)
+{
+ return svm_queue_timedwait_inline (q, timeout);
+}
+
/*
* svm_queue_add_nolock
*/
@@ -139,9 +197,7 @@ svm_queue_add_nolock (svm_queue_t * q, u8 * elem)
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
while (q->cursize == q->maxsize)
- {
- (void) pthread_cond_wait (&q->condvar, &q->mutex);
- }
+ svm_queue_wait_inline (q);
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
@@ -170,6 +226,9 @@ svm_queue_add_raw (svm_queue_t * q, u8 * elem)
q->tail = (q->tail + 1) % q->maxsize;
q->cursize++;
+
+ if (q->cursize == 1)
+ svm_queue_send_signal (q, 1);
}
@@ -201,9 +260,7 @@ svm_queue_add (svm_queue_t * q, u8 * elem, int nowait)
return (-2);
}
while (q->cursize == q->maxsize)
- {
- (void) pthread_cond_wait (&q->condvar, &q->mutex);
- }
+ svm_queue_wait_inline (q);
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
@@ -253,9 +310,7 @@ svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait)
return (-2);
}
while (q->cursize + 1 == q->maxsize)
- {
- (void) pthread_cond_wait (&q->condvar, &q->mutex);
- }
+ svm_queue_wait_inline (q);
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
@@ -317,13 +372,9 @@ svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond,
}
else if (cond == SVM_Q_TIMEDWAIT)
{
- struct timespec ts;
- ts.tv_sec = unix_time_now () + time;
- ts.tv_nsec = 0;
while (q->cursize == 0 && rc == 0)
- {
- rc = pthread_cond_timedwait (&q->condvar, &q->mutex, &ts);
- }
+ rc = svm_queue_timedwait_inline (q, time);
+
if (rc == ETIMEDOUT)
{
pthread_mutex_unlock (&q->mutex);
@@ -333,9 +384,7 @@ svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond,
else
{
while (q->cursize == 0)
- {
- (void) pthread_cond_wait (&q->condvar, &q->mutex);
- }
+ svm_queue_wait_inline (q);
}
}