@@ -189,12 +189,13 @@ int odp_queue_enq(odp_queue_t queue, odp_event_t ev);
* Enqueue multiple events to a queue
*
* @param queue Queue handle
- * @param ev Event handles
- * @param num Number of event handles
+ * @param[in] events Array of event handles
+ * @param num Number of event handles to enqueue
*
- * @return 0 if succesful
+ * @return Number of events actually enqueued (0 ... num)
+ * @retval <0 on failure
*/
-int odp_queue_enq_multi(odp_queue_t queue, odp_event_t ev[], int num);
+int odp_queue_enq_multi(odp_queue_t queue, const odp_event_t events[], int num);
/**
* Queue dequeue
@@ -410,7 +410,7 @@ static int enq_loopback(pktio_entry_t *pktio_entry, odp_packet_t pkt_tbl[],
hdr_tbl[i] = odp_buf_to_hdr(_odp_packet_to_buffer(pkt_tbl[i]));
qentry = queue_to_qentry(pktio_entry->s.loopq);
- return queue_enq_multi(qentry, hdr_tbl, len) == 0 ? len : 0;
+ return queue_enq_multi(qentry, hdr_tbl, len);
}
int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
@@ -552,7 +552,7 @@ int pktout_enq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[],
pkt_tbl[i] = _odp_packet_from_buffer(buf_hdr[i]->handle.handle);
nbr = odp_pktio_send(qentry->s.pktout, pkt_tbl, num);
- return (nbr == num ? 0 : -1);
+ return nbr;
}
int pktout_deq_multi(queue_entry_t *qentry ODP_UNUSED,
@@ -369,7 +369,7 @@ int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num)
if (sched == 1)
odp_schedule_queue(queue->s.handle, queue->s.param.sched.prio);
- return 0;
+ return num; /* All events enqueued */
}
int queue_enq_dummy(queue_entry_t *queue ODP_UNUSED,
@@ -385,7 +385,7 @@ int queue_enq_multi_dummy(queue_entry_t *queue ODP_UNUSED,
return -1;
}
-int odp_queue_enq_multi(odp_queue_t handle, odp_event_t ev[], int num)
+int odp_queue_enq_multi(odp_queue_t handle, const odp_event_t ev[], int num)
{
odp_buffer_hdr_t *buf_hdr[QUEUE_MULTI_MAX];
queue_entry_t *queue;
@@ -526,7 +526,9 @@ static int test_schedule_multi(const char *str, int thr,
ev[j] = odp_buffer_to_event(buf);
}
- if (odp_queue_enq_multi(queue, ev, MULTI_BUFS_MAX)) {
+ /* Assume we can enqueue all events */
+ if (odp_queue_enq_multi(queue, ev, MULTI_BUFS_MAX) !=
+ MULTI_BUFS_MAX) {
LOG_ERR(" [%i] Queue enqueue failed.\n", thr);
return -1;
}
@@ -541,7 +543,8 @@ static int test_schedule_multi(const char *str, int thr,
tot += num;
- if (odp_queue_enq_multi(queue, ev, num)) {
+ /* Assume we can enqueue all events */
+ if (odp_queue_enq_multi(queue, ev, num) != num) {
LOG_ERR(" [%i] Queue enqueue failed.\n", thr);
return -1;
}
@@ -559,7 +562,8 @@ static int test_schedule_multi(const char *str, int thr,
tot += num;
- if (odp_queue_enq_multi(queue, ev, num)) {
+ /* Assume we can enqueue all events */
+ if (odp_queue_enq_multi(queue, ev, num) != num) {
LOG_ERR(" [%i] Queue enqueue failed.\n", thr);
return -1;
}
@@ -330,14 +330,18 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b,
}
/* send packet(s) out */
- if (num_pkts == 1)
+ if (num_pkts == 1) {
ret = odp_queue_enq(pktio_a->outq, tx_ev[0]);
- else
+ if (ret != 0) {
+ CU_FAIL("failed to enqueue test packet");
+ return;
+ }
+ } else {
ret = odp_queue_enq_multi(pktio_a->outq, tx_ev, num_pkts);
-
- if (ret != 0) {
- CU_FAIL("failed to enqueue test packets");
- return;
+ if (ret != num_pkts) {
+ CU_FAIL("failed to enqueue test packets");
+ return;
+ }
}
/* and wait for them to arrive back */
@@ -83,9 +83,10 @@ static void test_odp_queue_sunnyday(void)
/*
* odp_queue_enq_multi may return 0..n buffers due to the resource
* constraints in the implementation at that given point of time.
+ * But here we assume that we succeed in enqueuing all buffers.
*/
ret = odp_queue_enq_multi(queue_id, enev, MAX_BUFFER_QUEUE);
- CU_ASSERT(0 == ret);
+ CU_ASSERT(MAX_BUFFER_QUEUE == ret);
pev_tmp = deev;
do {
deq_ret = odp_queue_deq_multi(queue_id, pev_tmp,
Changed the definition of odp_queue_enq_multi() to support partial success (e.g. enqueued some but not all of the events specified). Returns the number of events enqueued (equivalent to odp_queue_deq_multi()). This change is necessary to support ODP implementations that use fixed size queues (e.g. ODP linux-dpdk). Updated the implementation in odp_queue.c to conform to the new semantics. Updated the necessary test/validation/performance programs. Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org> --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) platform/linux-generic/include/api/odp_queue.h | 9 +++++---- platform/linux-generic/odp_packet_io.c | 4 ++-- platform/linux-generic/odp_queue.c | 4 ++-- test/performance/odp_scheduling.c | 10 +++++++--- test/validation/odp_pktio.c | 16 ++++++++++------ test/validation/odp_queue.c | 3 ++- 6 files changed, 28 insertions(+), 18 deletions(-)