FD.io VPP
v19.01.2-3-gf61a1a8
Vector Packet Processing
|
Unidirectional shared-memory multi-ring message queue. More...
Go to the source code of this file.
Data Structures | |
struct | svm_msg_q_ring_ |
struct | svm_msg_q_ |
struct | svm_msg_q_ring_cfg_ |
struct | svm_msg_q_cfg_ |
union | svm_msg_q_msg_t |
Macros | |
#define | SVM_MQ_INVALID_MSG { .as_u64 = ~0 } |
Typedefs | |
typedef struct svm_msg_q_ring_ | svm_msg_q_ring_t |
typedef struct svm_msg_q_ | svm_msg_q_t |
typedef struct svm_msg_q_ring_cfg_ | svm_msg_q_ring_cfg_t |
typedef struct svm_msg_q_cfg_ | svm_msg_q_cfg_t |
Functions | |
svm_msg_q_t * | svm_msg_q_alloc (svm_msg_q_cfg_t *cfg) |
Allocate message queue. More... | |
void | svm_msg_q_free (svm_msg_q_t *mq) |
Free message queue. More... | |
svm_msg_q_msg_t | svm_msg_q_alloc_msg (svm_msg_q_t *mq, u32 nbytes) |
Allocate message buffer. More... | |
svm_msg_q_msg_t | svm_msg_q_alloc_msg_w_ring (svm_msg_q_t *mq, u32 ring_index) |
Allocate message buffer on ring. More... | |
int | svm_msg_q_lock_and_alloc_msg_w_ring (svm_msg_q_t *mq, u32 ring_index, u8 noblock, svm_msg_q_msg_t *msg) |
Lock message queue and allocate message buffer on ring. More... | |
void | svm_msg_q_free_msg (svm_msg_q_t *mq, svm_msg_q_msg_t *msg) |
Free message buffer. More... | |
int | svm_msg_q_add (svm_msg_q_t *mq, svm_msg_q_msg_t *msg, int nowait) |
Producer enqueue one message to queue. More... | |
void | svm_msg_q_add_and_unlock (svm_msg_q_t *mq, svm_msg_q_msg_t *msg) |
Producer enqueue one message to queue with mutex held. More... | |
int | svm_msg_q_sub (svm_msg_q_t *mq, svm_msg_q_msg_t *msg, svm_q_conditional_wait_t cond, u32 time) |
Consumer dequeue one message from queue. More... | |
void | svm_msg_q_sub_w_lock (svm_msg_q_t *mq, svm_msg_q_msg_t *msg) |
Consumer dequeue one message from queue with mutex held. More... | |
void * | svm_msg_q_msg_data (svm_msg_q_t *mq, svm_msg_q_msg_t *msg) |
Get data for message in queue. More... | |
svm_msg_q_ring_t * | svm_msg_q_ring (svm_msg_q_t *mq, u32 ring_index) |
Get message queue ring. More... | |
void | svm_msg_q_set_consumer_eventfd (svm_msg_q_t *mq, int fd) |
Set event fd for queue consumer. More... | |
void | svm_msg_q_set_producer_eventfd (svm_msg_q_t *mq, int fd) |
Set event fd for queue producer. More... | |
int | svm_msg_q_alloc_consumer_eventfd (svm_msg_q_t *mq) |
Allocate event fd for queue consumer. More... | |
int | svm_msg_q_alloc_producer_eventfd (svm_msg_q_t *mq) |
Allocate event fd for queue consumer. More... | |
static u8 | svm_msg_q_is_full (svm_msg_q_t *mq) |
Check if message queue is full. More... | |
static u8 | svm_msg_q_ring_is_full (svm_msg_q_t *mq, u32 ring_index) |
static u8 | svm_msg_q_is_empty (svm_msg_q_t *mq) |
Check if message queue is empty. More... | |
static u32 | svm_msg_q_size (svm_msg_q_t *mq) |
Check length of message queue. More... | |
static u8 | svm_msg_q_msg_is_invalid (svm_msg_q_msg_t *msg) |
Check if message is invalid. More... | |
static int | svm_msg_q_try_lock (svm_msg_q_t *mq) |
Try locking message queue. More... | |
static int | svm_msg_q_lock (svm_msg_q_t *mq) |
Lock, or block trying, the message queue. More... | |
static void | svm_msg_q_unlock (svm_msg_q_t *mq) |
Unlock message queue. More... | |
static void | svm_msg_q_wait (svm_msg_q_t *mq) |
Wait for message queue event. More... | |
static int | svm_msg_q_timedwait (svm_msg_q_t *mq, double timeout) |
Timed wait for message queue event. More... | |
static int | svm_msg_q_get_consumer_eventfd (svm_msg_q_t *mq) |
static int | svm_msg_q_get_producer_eventfd (svm_msg_q_t *mq) |
Unidirectional shared-memory multi-ring message queue.
Definition in file message_queue.h.
#define SVM_MQ_INVALID_MSG { .as_u64 = ~0 } |
Definition at line 68 of file message_queue.h.
typedef struct svm_msg_q_cfg_ svm_msg_q_cfg_t |
typedef struct svm_msg_q_ring_cfg_ svm_msg_q_ring_cfg_t |
typedef struct svm_msg_q_ring_ svm_msg_q_ring_t |
typedef struct svm_msg_q_ svm_msg_q_t |
int svm_msg_q_add | ( | svm_msg_q_t * | mq, |
svm_msg_q_msg_t * | msg, | ||
int | nowait | ||
) |
Producer enqueue one message to queue.
Prior to calling this, the producer should've obtained a message buffer from one of the rings by calling svm_msg_q_alloc_msg.
mq | message queue |
msg | message (pointer to ring position) to be enqueued |
nowait | flag to indicate if request is blocking or not |
Definition at line 212 of file message_queue.c.
void svm_msg_q_add_and_unlock | ( | svm_msg_q_t * | mq, |
svm_msg_q_msg_t * | msg | ||
) |
Producer enqueue one message to queue with mutex held.
Prior to calling this, the producer should've obtained a message buffer from one of the rings by calling svm_msg_q_alloc_msg. It assumes the queue mutex is held.
mq | message queue |
msg | message (pointer to ring position) to be enqueued |
Definition at line 219 of file message_queue.c.
svm_msg_q_t* svm_msg_q_alloc | ( | svm_msg_q_cfg_t * | cfg | ) |
Allocate message queue.
Allocates a message queue on the heap. Based on the configuration options, apart from the message queue this also allocates (one or multiple) shared-memory rings for the messages.
cfg | configuration options: queue len, consumer pid, ring configs |
Definition at line 40 of file message_queue.c.
int svm_msg_q_alloc_consumer_eventfd | ( | svm_msg_q_t * | mq | ) |
Allocate event fd for queue consumer.
Definition at line 252 of file message_queue.c.
svm_msg_q_msg_t svm_msg_q_alloc_msg | ( | svm_msg_q_t * | mq, |
u32 | nbytes | ||
) |
Allocate message buffer.
Message is allocated on the first available ring capable of holding the requested number of bytes.
mq | message queue |
nbytes | number of bytes needed for message |
Definition at line 146 of file message_queue.c.
svm_msg_q_msg_t svm_msg_q_alloc_msg_w_ring | ( | svm_msg_q_t * | mq, |
u32 | ring_index | ||
) |
Allocate message buffer on ring.
Message is allocated, on requested ring. The caller MUST check that the ring is not full.
mq | message queue |
ring_index | ring on which the allocation should occur |
Definition at line 102 of file message_queue.c.
int svm_msg_q_alloc_producer_eventfd | ( | svm_msg_q_t * | mq | ) |
Allocate event fd for queue consumer.
Definition at line 262 of file message_queue.c.
void svm_msg_q_free | ( | svm_msg_q_t * | mq | ) |
Free message queue.
mq | message queue to be freed |
Definition at line 95 of file message_queue.c.
void svm_msg_q_free_msg | ( | svm_msg_q_t * | mq, |
svm_msg_q_msg_t * | msg | ||
) |
Free message buffer.
Marks message buffer on ring as free.
mq | message queue |
msg | message to be freed |
Definition at line 172 of file message_queue.c.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Check if message queue is empty.
Definition at line 270 of file message_queue.h.
|
inlinestatic |
Check if message queue is full.
Definition at line 254 of file message_queue.h.
|
inlinestatic |
Lock, or block trying, the message queue.
Definition at line 306 of file message_queue.h.
int svm_msg_q_lock_and_alloc_msg_w_ring | ( | svm_msg_q_t * | mq, |
u32 | ring_index, | ||
u8 | noblock, | ||
svm_msg_q_msg_t * | msg | ||
) |
Lock message queue and allocate message buffer on ring.
This should be used when multiple writers/readers are expected to compete for the rings/queue. Message should be enqueued by calling svm_msg_q_add_w_lock and the caller MUST unlock the queue once the message in enqueued.
mq | message queue |
ring_index | ring on which the allocation should occur |
noblock | flag that indicates if request should block |
msg | pointer to message to be filled in |
Definition at line 116 of file message_queue.c.
void* svm_msg_q_msg_data | ( | svm_msg_q_t * | mq, |
svm_msg_q_msg_t * | msg | ||
) |
Get data for message in queue.
mq | message queue |
msg | message for which the data is requested |
Definition at line 165 of file message_queue.c.
|
inlinestatic |
Check if message is invalid.
Definition at line 288 of file message_queue.h.
svm_msg_q_ring_t* svm_msg_q_ring | ( | svm_msg_q_t * | mq, |
u32 | ring_index | ||
) |
Get message queue ring.
mq | message queue |
ring_index | index of ring |
Definition at line 27 of file message_queue.c.
|
inlinestatic |
void svm_msg_q_set_consumer_eventfd | ( | svm_msg_q_t * | mq, |
int | fd | ||
) |
Set event fd for queue consumer.
If set, queue will exclusively use eventfds for signaling. Moreover, afterwards, the queue should only be used in non-blocking mode. Waiting for events should be done externally using something like epoll.
mq | message queue |
fd | consumer eventfd |
Definition at line 240 of file message_queue.c.
void svm_msg_q_set_producer_eventfd | ( | svm_msg_q_t * | mq, |
int | fd | ||
) |
Set event fd for queue producer.
If set, queue will exclusively use eventfds for signaling. Moreover, afterwards, the queue should only be used in non-blocking mode. Waiting for events should be done externally using something like epoll.
mq | message queue |
fd | producer eventfd |
Definition at line 246 of file message_queue.c.
|
inlinestatic |
Check length of message queue.
Definition at line 279 of file message_queue.h.
int svm_msg_q_sub | ( | svm_msg_q_t * | mq, |
svm_msg_q_msg_t * | msg, | ||
svm_q_conditional_wait_t | cond, | ||
u32 | time | ||
) |
Consumer dequeue one message from queue.
This returns the message pointing to the data in the message rings. The consumer is expected to call svm_msg_q_free_msg once it finishes processing/copies the message data.
mq | message queue |
msg | pointer to structure where message is to be received |
cond | flag that indicates if request should block or not |
time | time to wait if condition it SVM_Q_TIMEDWAIT |
Definition at line 227 of file message_queue.c.
void svm_msg_q_sub_w_lock | ( | svm_msg_q_t * | mq, |
svm_msg_q_msg_t * | msg | ||
) |
Consumer dequeue one message from queue with mutex held.
Returns the message pointing to the data in the message rings under the assumption that the message queue lock is already held. The consumer is expected to call svm_msg_q_free_msg once it finishes processing/copies the message data.
mq | message queue |
msg | pointer to structure where message is to be received |
Definition at line 234 of file message_queue.c.
|
inlinestatic |
Timed wait for message queue event.
Must be called with mutex held.
mq | message queue |
timeout | time in seconds |
Definition at line 344 of file message_queue.h.
|
inlinestatic |
Try locking message queue.
Definition at line 297 of file message_queue.h.
|
inlinestatic |
Unlock message queue.
Definition at line 315 of file message_queue.h.
|
inlinestatic |
Wait for message queue event.
Must be called with mutex held. The queue only works non-blocking with eventfds, so handle blocking calls as an exception here.
Definition at line 330 of file message_queue.h.