Code Review
/
vpp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add an ip6 local hop-by-hop protocol demux table
[vpp.git]
/
src
/
svm
/
queue.c
diff --git
a/src/svm/queue.c
b/src/svm/queue.c
index
771033d
..
c9db454
100644
(file)
--- a/
src/svm/queue.c
+++ b/
src/svm/queue.c
@@
-2,7
+2,7
@@
*------------------------------------------------------------------
* svm_queue.c - unidirectional shared-memory queues
*
*------------------------------------------------------------------
* svm_queue.c - unidirectional shared-memory queues
*
- * Copyright (c) 2009 Cisco and/or its affiliates.
+ * Copyright (c) 2009
-2019
Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@
-37,15
+37,15
@@
svm_queue_init (void *base, int nels, int elsize)
pthread_condattr_t cattr;
q = (svm_queue_t *) base;
pthread_condattr_t cattr;
q = (svm_queue_t *) base;
- memset (q, 0, sizeof (*q));
+
clib_
memset (q, 0, sizeof (*q));
q->elsize = elsize;
q->maxsize = nels;
q->producer_evtfd = -1;
q->consumer_evtfd = -1;
q->elsize = elsize;
q->maxsize = nels;
q->producer_evtfd = -1;
q->consumer_evtfd = -1;
- memset (&attr, 0, sizeof (attr));
- memset (&cattr, 0, sizeof (cattr));
+
clib_
memset (&attr, 0, sizeof (attr));
+
clib_
memset (&cattr, 0, sizeof (cattr));
if (pthread_mutexattr_init (&attr))
clib_unix_warning ("mutexattr_init");
if (pthread_mutexattr_init (&attr))
clib_unix_warning ("mutexattr_init");
@@
-75,7
+75,7
@@
svm_queue_alloc_and_init (int nels, int elsize, int consumer_pid)
q = clib_mem_alloc_aligned (sizeof (svm_queue_t)
+ nels * elsize, CLIB_CACHE_LINE_BYTES);
q = clib_mem_alloc_aligned (sizeof (svm_queue_t)
+ nels * elsize, CLIB_CACHE_LINE_BYTES);
- memset (q, 0, sizeof (*q));
+
clib_
memset (q, 0, sizeof (*q));
q = svm_queue_init (q, nels, elsize);
q->consumer_pid = consumer_pid;
q = svm_queue_init (q, nels, elsize);
q->consumer_pid = consumer_pid;
@@
-122,7
+122,7
@@
svm_queue_send_signal (svm_queue_t * q, u8 is_prod)
{
int __clib_unused rv, fd;
u64 data = 1;
{
int __clib_unused rv, fd;
u64 data = 1;
- ASSERT (q->consumer_evtfd
!= -1
);
+ ASSERT (q->consumer_evtfd
> 0 && q->producer_evtfd > 0
);
fd = is_prod ? q->producer_evtfd : q->consumer_evtfd;
rv = write (fd, &data, sizeof (data));
}
fd = is_prod ? q->producer_evtfd : q->consumer_evtfd;
rv = write (fd, &data, sizeof (data));
}
@@
-140,10
+140,10
@@
svm_queue_wait_inline (svm_queue_t * q)
/* 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;
/* 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
);
+
svm_queue_unlock (q
);
while (q->cursize == cursize)
CLIB_PAUSE ();
while (q->cursize == cursize)
CLIB_PAUSE ();
-
pthread_mutex_lock (&q->mutex
);
+
svm_queue_lock (q
);
}
}
}
}
@@
-170,11
+170,11
@@
svm_queue_timedwait_inline (svm_queue_t * q, double timeout)
u32 cursize = q->cursize;
int rv;
u32 cursize = q->cursize;
int rv;
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
while (q->cursize == cursize && unix_time_now () < max_time)
CLIB_PAUSE ();
rv = unix_time_now () < max_time ? 0 : ETIMEDOUT;
while (q->cursize == cursize && unix_time_now () < max_time)
CLIB_PAUSE ();
rv = unix_time_now () < max_time ? 0 : ETIMEDOUT;
-
pthread_mutex_lock (&q->mutex
);
+
svm_queue_lock (q
);
return rv;
}
}
return rv;
}
}
@@
-201,7
+201,7
@@
svm_queue_add_nolock (svm_queue_t * q, u8 * elem)
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
- clib_memcpy (tailp, elem, q->elsize);
+ clib_memcpy
_fast
(tailp, elem, q->elsize);
q->tail++;
q->cursize++;
q->tail++;
q->cursize++;
@@
-222,7
+222,7
@@
svm_queue_add_raw (svm_queue_t * q, u8 * elem)
i8 *tailp;
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
i8 *tailp;
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
- clib_memcpy (tailp, elem, q->elsize);
+ clib_memcpy
_fast
(tailp, elem, q->elsize);
q->tail = (q->tail + 1) % q->maxsize;
q->cursize++;
q->tail = (q->tail + 1) % q->maxsize;
q->cursize++;
@@
-250,13
+250,13
@@
svm_queue_add (svm_queue_t * q, u8 * elem, int nowait)
}
}
else
}
}
else
-
pthread_mutex_lock (&q->mutex
);
+
svm_queue_lock (q
);
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
if (nowait)
{
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
if (nowait)
{
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return (-2);
}
while (q->cursize == q->maxsize)
return (-2);
}
while (q->cursize == q->maxsize)
@@
-264,7
+264,7
@@
svm_queue_add (svm_queue_t * q, u8 * elem, int nowait)
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
- clib_memcpy (tailp, elem, q->elsize);
+ clib_memcpy
_fast
(tailp, elem, q->elsize);
q->tail++;
q->cursize++;
q->tail++;
q->cursize++;
@@
-277,7
+277,7
@@
svm_queue_add (svm_queue_t * q, u8 * elem, int nowait)
if (need_broadcast)
svm_queue_send_signal (q, 1);
if (need_broadcast)
svm_queue_send_signal (q, 1);
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return 0;
}
return 0;
}
@@
-300,13
+300,13
@@
svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait)
}
}
else
}
}
else
-
pthread_mutex_lock (&q->mutex
);
+
svm_queue_lock (q
);
if (PREDICT_FALSE (q->cursize + 1 == q->maxsize))
{
if (nowait)
{
if (PREDICT_FALSE (q->cursize + 1 == q->maxsize))
{
if (nowait)
{
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return (-2);
}
while (q->cursize + 1 == q->maxsize)
return (-2);
}
while (q->cursize + 1 == q->maxsize)
@@
-314,7
+314,7
@@
svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait)
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
}
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
- clib_memcpy (tailp, elem, q->elsize);
+ clib_memcpy
_fast
(tailp, elem, q->elsize);
q->tail++;
q->cursize++;
q->tail++;
q->cursize++;
@@
-325,7
+325,7
@@
svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait)
need_broadcast = (q->cursize == 1);
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
need_broadcast = (q->cursize == 1);
tailp = (i8 *) (&q->data[0] + q->elsize * q->tail);
- clib_memcpy (tailp, elem2, q->elsize);
+ clib_memcpy
_fast
(tailp, elem2, q->elsize);
q->tail++;
q->cursize++;
q->tail++;
q->cursize++;
@@
-336,7
+336,7
@@
svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait)
if (need_broadcast)
svm_queue_send_signal (q, 1);
if (need_broadcast)
svm_queue_send_signal (q, 1);
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return 0;
}
return 0;
}
@@
-361,13
+361,13
@@
svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond,
}
}
else
}
}
else
-
pthread_mutex_lock (&q->mutex
);
+
svm_queue_lock (q
);
if (PREDICT_FALSE (q->cursize == 0))
{
if (cond == SVM_Q_NOWAIT)
{
if (PREDICT_FALSE (q->cursize == 0))
{
if (cond == SVM_Q_NOWAIT)
{
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return (-2);
}
else if (cond == SVM_Q_TIMEDWAIT)
return (-2);
}
else if (cond == SVM_Q_TIMEDWAIT)
@@
-377,7
+377,7
@@
svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond,
if (rc == ETIMEDOUT)
{
if (rc == ETIMEDOUT)
{
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return ETIMEDOUT;
}
}
return ETIMEDOUT;
}
}
@@
-389,7
+389,7
@@
svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond,
}
headp = (i8 *) (&q->data[0] + q->elsize * q->head);
}
headp = (i8 *) (&q->data[0] + q->elsize * q->head);
- clib_memcpy (elem, headp, q->elsize);
+ clib_memcpy
_fast
(elem, headp, q->elsize);
q->head++;
/* $$$$ JFC shouldn't this be == 0? */
q->head++;
/* $$$$ JFC shouldn't this be == 0? */
@@
-404,7
+404,7
@@
svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond,
if (need_broadcast)
svm_queue_send_signal (q, 0);
if (need_broadcast)
svm_queue_send_signal (q, 0);
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return 0;
}
return 0;
}
@@
-415,15
+415,15
@@
svm_queue_sub2 (svm_queue_t * q, u8 * elem)
int need_broadcast;
i8 *headp;
int need_broadcast;
i8 *headp;
-
pthread_mutex_lock (&q->mutex
);
+
svm_queue_lock (q
);
if (q->cursize == 0)
{
if (q->cursize == 0)
{
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
return -1;
}
headp = (i8 *) (&q->data[0] + q->elsize * q->head);
return -1;
}
headp = (i8 *) (&q->data[0] + q->elsize * q->head);
- clib_memcpy (elem, headp, q->elsize);
+ clib_memcpy
_fast
(elem, headp, q->elsize);
q->head++;
need_broadcast = (q->cursize == q->maxsize / 2);
q->head++;
need_broadcast = (q->cursize == q->maxsize / 2);
@@
-431,7
+431,7
@@
svm_queue_sub2 (svm_queue_t * q, u8 * elem)
if (PREDICT_FALSE (q->head == q->maxsize))
q->head = 0;
if (PREDICT_FALSE (q->head == q->maxsize))
q->head = 0;
-
pthread_mutex_unlock (&q->mutex
);
+
svm_queue_unlock (q
);
if (need_broadcast)
svm_queue_send_signal (q, 0);
if (need_broadcast)
svm_queue_send_signal (q, 0);
@@
-451,7
+451,7
@@
svm_queue_sub_raw (svm_queue_t * q, u8 * elem)
}
headp = (i8 *) (&q->data[0] + q->elsize * q->head);
}
headp = (i8 *) (&q->data[0] + q->elsize * q->head);
- clib_memcpy (elem, headp, q->elsize);
+ clib_memcpy
_fast
(elem, headp, q->elsize);
q->head = (q->head + 1) % q->maxsize;
q->cursize--;
q->head = (q->head + 1) % q->maxsize;
q->cursize--;