FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
message_queue.c File Reference
+ Include dependency graph for message_queue.c:

Go to the source code of this file.

Functions

static svm_msg_q_ring_tsvm_msg_q_ring_inline (svm_msg_q_t *mq, u32 ring_index)
 
svm_msg_q_ring_tsvm_msg_q_ring (svm_msg_q_t *mq, u32 ring_index)
 Get message queue ring. More...
 
static void * svm_msg_q_ring_data (svm_msg_q_ring_t *ring, u32 elt_index)
 
svm_msg_q_tsvm_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_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...
 
svm_msg_q_msg_t svm_msg_q_alloc_msg (svm_msg_q_t *mq, u32 nbytes)
 Allocate message buffer. 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...
 
void svm_msg_q_free_msg (svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
 Free message buffer. More...
 
static int svm_msq_q_msg_is_valid (svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
 
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_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...
 

Function Documentation

◆ svm_msg_q_add()

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.

Parameters
mqmessage queue
msgmessage (pointer to ring position) to be enqueued
nowaitflag to indicate if request is blocking or not
Returns
success status

Definition at line 215 of file message_queue.c.

+ Here is the call graph for this function:

◆ svm_msg_q_add_and_unlock()

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.

Parameters
mqmessage queue
msgmessage (pointer to ring position) to be enqueued
Returns
success status

Definition at line 222 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_alloc()

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.

Parameters
cfgconfiguration options: queue len, consumer pid, ring configs
Returns
message queue

Definition at line 40 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_alloc_consumer_eventfd()

int svm_msg_q_alloc_consumer_eventfd ( svm_msg_q_t mq)

Allocate event fd for queue consumer.

Definition at line 255 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_alloc_msg()

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.

Parameters
mqmessage queue
nbytesnumber of bytes needed for message
Returns
message structure pointing to the ring and position allocated

Definition at line 143 of file message_queue.c.

◆ svm_msg_q_alloc_msg_w_ring()

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.

Parameters
mqmessage queue
ring_indexring on which the allocation should occur
Returns
message structure pointing to the ring and position allocated

Definition at line 102 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_alloc_producer_eventfd()

int svm_msg_q_alloc_producer_eventfd ( svm_msg_q_t mq)

Allocate event fd for queue consumer.

Definition at line 265 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_free()

void svm_msg_q_free ( svm_msg_q_t mq)

Free message queue.

Parameters
mqmessage queue to be freed

Definition at line 95 of file message_queue.c.

+ Here is the call graph for this function:

◆ svm_msg_q_free_msg()

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.

Parameters
mqmessage queue
msgmessage to be freed

Definition at line 169 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_lock_and_alloc_msg_w_ring()

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.

Parameters
mqmessage queue
ring_indexring on which the allocation should occur
noblockflag that indicates if request should block
msgpointer to message to be filled in
Returns
0 on success, negative number otherwise

Definition at line 116 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_msg_data()

void* svm_msg_q_msg_data ( svm_msg_q_t mq,
svm_msg_q_msg_t msg 
)

Get data for message in queue.

Parameters
mqmessage queue
msgmessage for which the data is requested
Returns
pointer to data

Definition at line 162 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_ring()

svm_msg_q_ring_t* svm_msg_q_ring ( svm_msg_q_t mq,
u32  ring_index 
)

Get message queue ring.

Parameters
mqmessage queue
ring_indexindex of ring
Returns
pointer to ring

Definition at line 27 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msg_q_ring_data()

static void* svm_msg_q_ring_data ( svm_msg_q_ring_t ring,
u32  elt_index 
)
inlinestatic

Definition at line 33 of file message_queue.c.

+ Here is the caller graph for this function:

◆ svm_msg_q_ring_inline()

static svm_msg_q_ring_t* svm_msg_q_ring_inline ( svm_msg_q_t mq,
u32  ring_index 
)
inlinestatic

Definition at line 21 of file message_queue.c.

+ Here is the caller graph for this function:

◆ svm_msg_q_set_consumer_eventfd()

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.

Parameters
mqmessage queue
fdconsumer eventfd

Definition at line 243 of file message_queue.c.

+ Here is the caller graph for this function:

◆ svm_msg_q_set_producer_eventfd()

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.

Parameters
mqmessage queue
fdproducer eventfd

Definition at line 249 of file message_queue.c.

+ Here is the caller graph for this function:

◆ svm_msg_q_sub()

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.

Parameters
mqmessage queue
msgpointer to structure where message is to be received
condflag that indicates if request should block or not
timetime to wait if condition it SVM_Q_TIMEDWAIT
Returns
success status

Definition at line 230 of file message_queue.c.

+ Here is the call graph for this function:

◆ svm_msg_q_sub_w_lock()

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.

Parameters
mqmessage queue
msgpointer to structure where message is to be received
Returns
success status

Definition at line 237 of file message_queue.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ svm_msq_q_msg_is_valid()

static int svm_msq_q_msg_is_valid ( svm_msg_q_t mq,
svm_msg_q_msg_t msg 
)
static

Definition at line 195 of file message_queue.c.

+ Here is the caller graph for this function: