From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 41E035A68 for ; Tue, 7 Mar 2017 12:33:23 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Mar 2017 03:33:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,258,1484035200"; d="scan'208";a="831864292" Received: from sivswdev01.ir.intel.com ([10.237.217.45]) by FMSMGA003.fm.intel.com with ESMTP; 07 Mar 2017 03:33:21 -0800 From: Bruce Richardson To: olivier.matz@6wind.com Cc: jerin.jacob@caviumnetworks.com, dev@dpdk.org, Bruce Richardson Date: Tue, 7 Mar 2017 11:32:10 +0000 Message-Id: <20170307113217.11077-8-bruce.richardson@intel.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170307113217.11077-1-bruce.richardson@intel.com> References: <20170223172407.27664-1-bruce.richardson@intel.com> <20170307113217.11077-1-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH v2 07/14] ring: make bulk and burst fn return vals consistent X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Mar 2017 11:33:24 -0000 The bulk fns for rings returns 0 for all elements enqueued and negative for no space. Change that to make them consistent with the burst functions in returning the number of elements enqueued/dequeued, i.e. 0 or N. This change also allows the return value from enq/deq to be used directly without a branch for error checking. Signed-off-by: Bruce Richardson --- doc/guides/rel_notes/release_17_05.rst | 11 +++ doc/guides/sample_app_ug/server_node_efd.rst | 2 +- examples/load_balancer/runtime.c | 16 ++- .../client_server_mp/mp_client/client.c | 8 +- .../client_server_mp/mp_server/main.c | 2 +- examples/qos_sched/app_thread.c | 8 +- examples/server_node_efd/node/node.c | 2 +- examples/server_node_efd/server/main.c | 2 +- lib/librte_mempool/rte_mempool_ring.c | 12 ++- lib/librte_ring/rte_ring.h | 109 +++++++-------------- test/test-pipeline/pipeline_hash.c | 2 +- test/test-pipeline/runtime.c | 8 +- test/test/test_ring.c | 46 +++++---- test/test/test_ring_perf.c | 8 +- 14 files changed, 106 insertions(+), 130 deletions(-) diff --git a/doc/guides/rel_notes/release_17_05.rst b/doc/guides/rel_notes/release_17_05.rst index 4e748dc..2b11765 100644 --- a/doc/guides/rel_notes/release_17_05.rst +++ b/doc/guides/rel_notes/release_17_05.rst @@ -120,6 +120,17 @@ API Changes * removed the build-time setting ``CONFIG_RTE_RING_PAUSE_REP_COUNT`` * removed the function ``rte_ring_set_water_mark`` as part of a general removal of watermarks support in the library. + * changed the return value of the enqueue and dequeue bulk functions to + match that of the burst equivalents. In all cases, ring functions which + operate on multiple packets now return the number of elements enqueued + or dequeued, as appropriate. The updated functions are: + + - ``rte_ring_mp_enqueue_bulk`` + - ``rte_ring_sp_enqueue_bulk`` + - ``rte_ring_enqueue_bulk`` + - ``rte_ring_mc_dequeue_bulk`` + - ``rte_ring_sc_dequeue_bulk`` + - ``rte_ring_dequeue_bulk`` ABI Changes ----------- diff --git a/doc/guides/sample_app_ug/server_node_efd.rst b/doc/guides/sample_app_ug/server_node_efd.rst index 9b69cfe..e3a63c8 100644 --- a/doc/guides/sample_app_ug/server_node_efd.rst +++ b/doc/guides/sample_app_ug/server_node_efd.rst @@ -286,7 +286,7 @@ repeated infinitely. cl = &nodes[node]; if (rte_ring_enqueue_bulk(cl->rx_q, (void **)cl_rx_buf[node].buffer, - cl_rx_buf[node].count) != 0){ + cl_rx_buf[node].count) != cl_rx_buf[node].count){ for (j = 0; j < cl_rx_buf[node].count; j++) rte_pktmbuf_free(cl_rx_buf[node].buffer[j]); cl->stats.rx_drop += cl_rx_buf[node].count; diff --git a/examples/load_balancer/runtime.c b/examples/load_balancer/runtime.c index 6944325..82b10bc 100644 --- a/examples/load_balancer/runtime.c +++ b/examples/load_balancer/runtime.c @@ -146,7 +146,7 @@ app_lcore_io_rx_buffer_to_send ( (void **) lp->rx.mbuf_out[worker].array, bsz); - if (unlikely(ret == -ENOBUFS)) { + if (unlikely(ret == 0)) { uint32_t k; for (k = 0; k < bsz; k ++) { struct rte_mbuf *m = lp->rx.mbuf_out[worker].array[k]; @@ -312,7 +312,7 @@ app_lcore_io_rx_flush(struct app_lcore_params_io *lp, uint32_t n_workers) (void **) lp->rx.mbuf_out[worker].array, lp->rx.mbuf_out[worker].n_mbufs); - if (unlikely(ret < 0)) { + if (unlikely(ret == 0)) { uint32_t k; for (k = 0; k < lp->rx.mbuf_out[worker].n_mbufs; k ++) { struct rte_mbuf *pkt_to_free = lp->rx.mbuf_out[worker].array[k]; @@ -349,9 +349,8 @@ app_lcore_io_tx( (void **) &lp->tx.mbuf_out[port].array[n_mbufs], bsz_rd); - if (unlikely(ret == -ENOENT)) { + if (unlikely(ret == 0)) continue; - } n_mbufs += bsz_rd; @@ -505,9 +504,8 @@ app_lcore_worker( (void **) lp->mbuf_in.array, bsz_rd); - if (unlikely(ret == -ENOENT)) { + if (unlikely(ret == 0)) continue; - } #if APP_WORKER_DROP_ALL_PACKETS for (j = 0; j < bsz_rd; j ++) { @@ -559,7 +557,7 @@ app_lcore_worker( #if APP_STATS lp->rings_out_iters[port] ++; - if (ret == 0) { + if (ret > 0) { lp->rings_out_count[port] += 1; } if (lp->rings_out_iters[port] == APP_STATS){ @@ -572,7 +570,7 @@ app_lcore_worker( } #endif - if (unlikely(ret == -ENOBUFS)) { + if (unlikely(ret == 0)) { uint32_t k; for (k = 0; k < bsz_wr; k ++) { struct rte_mbuf *pkt_to_free = lp->mbuf_out[port].array[k]; @@ -609,7 +607,7 @@ app_lcore_worker_flush(struct app_lcore_params_worker *lp) (void **) lp->mbuf_out[port].array, lp->mbuf_out[port].n_mbufs); - if (unlikely(ret < 0)) { + if (unlikely(ret == 0)) { uint32_t k; for (k = 0; k < lp->mbuf_out[port].n_mbufs; k ++) { struct rte_mbuf *pkt_to_free = lp->mbuf_out[port].array[k]; diff --git a/examples/multi_process/client_server_mp/mp_client/client.c b/examples/multi_process/client_server_mp/mp_client/client.c index d4f9ca3..dca9eb9 100644 --- a/examples/multi_process/client_server_mp/mp_client/client.c +++ b/examples/multi_process/client_server_mp/mp_client/client.c @@ -276,14 +276,10 @@ main(int argc, char *argv[]) printf("[Press Ctrl-C to quit ...]\n"); for (;;) { - uint16_t i, rx_pkts = PKT_READ_SIZE; + uint16_t i, rx_pkts; uint8_t port; - /* try dequeuing max possible packets first, if that fails, get the - * most we can. Loop body should only execute once, maximum */ - while (rx_pkts > 0 && - unlikely(rte_ring_dequeue_bulk(rx_ring, pkts, rx_pkts) != 0)) - rx_pkts = (uint16_t)RTE_MIN(rte_ring_count(rx_ring), PKT_READ_SIZE); + rx_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE); if (unlikely(rx_pkts == 0)){ if (need_flush) diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c index a6dc12d..19c95b2 100644 --- a/examples/multi_process/client_server_mp/mp_server/main.c +++ b/examples/multi_process/client_server_mp/mp_server/main.c @@ -227,7 +227,7 @@ flush_rx_queue(uint16_t client) cl = &clients[client]; if (rte_ring_enqueue_bulk(cl->rx_q, (void **)cl_rx_buf[client].buffer, - cl_rx_buf[client].count) != 0){ + cl_rx_buf[client].count) == 0){ for (j = 0; j < cl_rx_buf[client].count; j++) rte_pktmbuf_free(cl_rx_buf[client].buffer[j]); cl->stats.rx_drop += cl_rx_buf[client].count; diff --git a/examples/qos_sched/app_thread.c b/examples/qos_sched/app_thread.c index 70fdcdb..dab4594 100644 --- a/examples/qos_sched/app_thread.c +++ b/examples/qos_sched/app_thread.c @@ -107,7 +107,7 @@ app_rx_thread(struct thread_conf **confs) } if (unlikely(rte_ring_sp_enqueue_bulk(conf->rx_ring, - (void **)rx_mbufs, nb_rx) != 0)) { + (void **)rx_mbufs, nb_rx) == 0)) { for(i = 0; i < nb_rx; i++) { rte_pktmbuf_free(rx_mbufs[i]); @@ -180,7 +180,7 @@ app_tx_thread(struct thread_conf **confs) while ((conf = confs[conf_idx])) { retval = rte_ring_sc_dequeue_bulk(conf->tx_ring, (void **)mbufs, burst_conf.qos_dequeue); - if (likely(retval == 0)) { + if (likely(retval != 0)) { app_send_packets(conf, mbufs, burst_conf.qos_dequeue); conf->counter = 0; /* reset empty read loop counter */ @@ -230,7 +230,9 @@ app_worker_thread(struct thread_conf **confs) nb_pkt = rte_sched_port_dequeue(conf->sched_port, mbufs, burst_conf.qos_dequeue); if (likely(nb_pkt > 0)) - while (rte_ring_sp_enqueue_bulk(conf->tx_ring, (void **)mbufs, nb_pkt) != 0); + while (rte_ring_sp_enqueue_bulk(conf->tx_ring, + (void **)mbufs, nb_pkt) == 0) + ; /* empty body */ conf_idx++; if (confs[conf_idx] == NULL) diff --git a/examples/server_node_efd/node/node.c b/examples/server_node_efd/node/node.c index a6c0c70..9ec6a05 100644 --- a/examples/server_node_efd/node/node.c +++ b/examples/server_node_efd/node/node.c @@ -392,7 +392,7 @@ main(int argc, char *argv[]) */ while (rx_pkts > 0 && unlikely(rte_ring_dequeue_bulk(rx_ring, pkts, - rx_pkts) != 0)) + rx_pkts) == 0)) rx_pkts = (uint16_t)RTE_MIN(rte_ring_count(rx_ring), PKT_READ_SIZE); diff --git a/examples/server_node_efd/server/main.c b/examples/server_node_efd/server/main.c index 1a54d1b..3eb7fac 100644 --- a/examples/server_node_efd/server/main.c +++ b/examples/server_node_efd/server/main.c @@ -247,7 +247,7 @@ flush_rx_queue(uint16_t node) cl = &nodes[node]; if (rte_ring_enqueue_bulk(cl->rx_q, (void **)cl_rx_buf[node].buffer, - cl_rx_buf[node].count) != 0){ + cl_rx_buf[node].count) != cl_rx_buf[node].count){ for (j = 0; j < cl_rx_buf[node].count; j++) rte_pktmbuf_free(cl_rx_buf[node].buffer[j]); cl->stats.rx_drop += cl_rx_buf[node].count; diff --git a/lib/librte_mempool/rte_mempool_ring.c b/lib/librte_mempool/rte_mempool_ring.c index b9aa64d..409b860 100644 --- a/lib/librte_mempool/rte_mempool_ring.c +++ b/lib/librte_mempool/rte_mempool_ring.c @@ -42,26 +42,30 @@ static int common_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table, unsigned n) { - return rte_ring_mp_enqueue_bulk(mp->pool_data, obj_table, n); + return rte_ring_mp_enqueue_bulk(mp->pool_data, + obj_table, n) == 0 ? -ENOBUFS : 0; } static int common_ring_sp_enqueue(struct rte_mempool *mp, void * const *obj_table, unsigned n) { - return rte_ring_sp_enqueue_bulk(mp->pool_data, obj_table, n); + return rte_ring_sp_enqueue_bulk(mp->pool_data, + obj_table, n) == 0 ? -ENOBUFS : 0; } static int common_ring_mc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n) { - return rte_ring_mc_dequeue_bulk(mp->pool_data, obj_table, n); + return rte_ring_mc_dequeue_bulk(mp->pool_data, + obj_table, n) == 0 ? -ENOBUFS : 0; } static int common_ring_sc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n) { - return rte_ring_sc_dequeue_bulk(mp->pool_data, obj_table, n); + return rte_ring_sc_dequeue_bulk(mp->pool_data, + obj_table, n) == 0 ? -ENOBUFS : 0; } static unsigned diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index e7061be..5f6589f 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -352,14 +352,10 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r); * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring * RTE_RING_QUEUE_VARIABLE: Enqueue as many items a possible from ring * @return - * Depend on the behavior value - * if behavior = RTE_RING_QUEUE_FIXED - * - 0: Success; objects enqueue. - * - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued. - * if behavior = RTE_RING_QUEUE_VARIABLE - * - n: Actual number of objects enqueued. + * Actual number of objects enqueued. + * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only. */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table, unsigned n, enum rte_ring_queue_behavior behavior) { @@ -391,7 +387,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table, /* check that we have enough room in ring */ if (unlikely(n > free_entries)) { if (behavior == RTE_RING_QUEUE_FIXED) - return -ENOBUFS; + return 0; else { /* No free entry available */ if (unlikely(free_entries == 0)) @@ -417,7 +413,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table, rte_pause(); r->prod.tail = prod_next; - return (behavior == RTE_RING_QUEUE_FIXED) ? 0 : n; + return n; } /** @@ -433,14 +429,10 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table, * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring * RTE_RING_QUEUE_VARIABLE: Enqueue as many items a possible from ring * @return - * Depend on the behavior value - * if behavior = RTE_RING_QUEUE_FIXED - * - 0: Success; objects enqueue. - * - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued. - * if behavior = RTE_RING_QUEUE_VARIABLE - * - n: Actual number of objects enqueued. + * Actual number of objects enqueued. + * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only. */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) __rte_ring_sp_do_enqueue(struct rte_ring *r, void * const *obj_table, unsigned n, enum rte_ring_queue_behavior behavior) { @@ -460,7 +452,7 @@ __rte_ring_sp_do_enqueue(struct rte_ring *r, void * const *obj_table, /* check that we have enough room in ring */ if (unlikely(n > free_entries)) { if (behavior == RTE_RING_QUEUE_FIXED) - return -ENOBUFS; + return 0; else { /* No free entry available */ if (unlikely(free_entries == 0)) @@ -477,7 +469,7 @@ __rte_ring_sp_do_enqueue(struct rte_ring *r, void * const *obj_table, rte_smp_wmb(); r->prod.tail = prod_next; - return (behavior == RTE_RING_QUEUE_FIXED) ? 0 : n; + return n; } /** @@ -498,16 +490,11 @@ __rte_ring_sp_do_enqueue(struct rte_ring *r, void * const *obj_table, * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring * RTE_RING_QUEUE_VARIABLE: Dequeue as many items a possible from ring * @return - * Depend on the behavior value - * if behavior = RTE_RING_QUEUE_FIXED - * - 0: Success; objects dequeued. - * - -ENOENT: Not enough entries in the ring to dequeue; no object is - * dequeued. - * if behavior = RTE_RING_QUEUE_VARIABLE - * - n: Actual number of objects dequeued. + * - Actual number of objects dequeued. + * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only. */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table, unsigned n, enum rte_ring_queue_behavior behavior) { @@ -539,7 +526,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table, /* Set the actual entries for dequeue */ if (n > entries) { if (behavior == RTE_RING_QUEUE_FIXED) - return -ENOENT; + return 0; else { if (unlikely(entries == 0)) return 0; @@ -565,7 +552,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table, r->cons.tail = cons_next; - return behavior == RTE_RING_QUEUE_FIXED ? 0 : n; + return n; } /** @@ -583,15 +570,10 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table, * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring * RTE_RING_QUEUE_VARIABLE: Dequeue as many items a possible from ring * @return - * Depend on the behavior value - * if behavior = RTE_RING_QUEUE_FIXED - * - 0: Success; objects dequeued. - * - -ENOENT: Not enough entries in the ring to dequeue; no object is - * dequeued. - * if behavior = RTE_RING_QUEUE_VARIABLE - * - n: Actual number of objects dequeued. + * - Actual number of objects dequeued. + * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only. */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) __rte_ring_sc_do_dequeue(struct rte_ring *r, void **obj_table, unsigned n, enum rte_ring_queue_behavior behavior) { @@ -610,7 +592,7 @@ __rte_ring_sc_do_dequeue(struct rte_ring *r, void **obj_table, if (n > entries) { if (behavior == RTE_RING_QUEUE_FIXED) - return -ENOENT; + return 0; else { if (unlikely(entries == 0)) return 0; @@ -626,7 +608,7 @@ __rte_ring_sc_do_dequeue(struct rte_ring *r, void **obj_table, rte_smp_rmb(); r->cons.tail = cons_next; - return behavior == RTE_RING_QUEUE_FIXED ? 0 : n; + return n; } /** @@ -642,10 +624,9 @@ __rte_ring_sc_do_dequeue(struct rte_ring *r, void **obj_table, * @param n * The number of objects to add in the ring from the obj_table. * @return - * - 0: Success; objects enqueue. - * - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued. + * The number of objects enqueued, either 0 or n */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, unsigned n) { @@ -662,10 +643,9 @@ rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, * @param n * The number of objects to add in the ring from the obj_table. * @return - * - 0: Success; objects enqueued. - * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued. + * The number of objects enqueued, either 0 or n */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, unsigned n) { @@ -686,10 +666,9 @@ rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, * @param n * The number of objects to add in the ring from the obj_table. * @return - * - 0: Success; objects enqueued. - * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued. + * The number of objects enqueued, either 0 or n */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table, unsigned n) { @@ -716,7 +695,7 @@ rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table, static inline int __attribute__((always_inline)) rte_ring_mp_enqueue(struct rte_ring *r, void *obj) { - return rte_ring_mp_enqueue_bulk(r, &obj, 1); + return rte_ring_mp_enqueue_bulk(r, &obj, 1) ? 0 : -ENOBUFS; } /** @@ -733,7 +712,7 @@ rte_ring_mp_enqueue(struct rte_ring *r, void *obj) static inline int __attribute__((always_inline)) rte_ring_sp_enqueue(struct rte_ring *r, void *obj) { - return rte_ring_sp_enqueue_bulk(r, &obj, 1); + return rte_ring_sp_enqueue_bulk(r, &obj, 1) ? 0 : -ENOBUFS; } /** @@ -754,10 +733,7 @@ rte_ring_sp_enqueue(struct rte_ring *r, void *obj) static inline int __attribute__((always_inline)) rte_ring_enqueue(struct rte_ring *r, void *obj) { - if (r->prod.sp_enqueue) - return rte_ring_sp_enqueue(r, obj); - else - return rte_ring_mp_enqueue(r, obj); + return rte_ring_enqueue_bulk(r, &obj, 1) ? 0 : -ENOBUFS; } /** @@ -773,11 +749,9 @@ rte_ring_enqueue(struct rte_ring *r, void *obj) * @param n * The number of objects to dequeue from the ring to the obj_table. * @return - * - 0: Success; objects dequeued. - * - -ENOENT: Not enough entries in the ring to dequeue; no object is - * dequeued. + * The number of objects dequeued, either 0 or n */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n) { return __rte_ring_mc_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED); @@ -794,11 +768,9 @@ rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n) * The number of objects to dequeue from the ring to the obj_table, * must be strictly positive. * @return - * - 0: Success; objects dequeued. - * - -ENOENT: Not enough entries in the ring to dequeue; no object is - * dequeued. + * The number of objects dequeued, either 0 or n */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n) { return __rte_ring_sc_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED); @@ -818,11 +790,9 @@ rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n) * @param n * The number of objects to dequeue from the ring to the obj_table. * @return - * - 0: Success; objects dequeued. - * - -ENOENT: Not enough entries in the ring to dequeue, no object is - * dequeued. + * The number of objects dequeued, either 0 or n */ -static inline int __attribute__((always_inline)) +static inline unsigned int __attribute__((always_inline)) rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n) { if (r->cons.sc_dequeue) @@ -849,7 +819,7 @@ rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n) static inline int __attribute__((always_inline)) rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p) { - return rte_ring_mc_dequeue_bulk(r, obj_p, 1); + return rte_ring_mc_dequeue_bulk(r, obj_p, 1) ? 0 : -ENOBUFS; } /** @@ -867,7 +837,7 @@ rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p) static inline int __attribute__((always_inline)) rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p) { - return rte_ring_sc_dequeue_bulk(r, obj_p, 1); + return rte_ring_sc_dequeue_bulk(r, obj_p, 1) ? 0 : -ENOBUFS; } /** @@ -889,10 +859,7 @@ rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p) static inline int __attribute__((always_inline)) rte_ring_dequeue(struct rte_ring *r, void **obj_p) { - if (r->cons.sc_dequeue) - return rte_ring_sc_dequeue(r, obj_p); - else - return rte_ring_mc_dequeue(r, obj_p); + return rte_ring_dequeue_bulk(r, obj_p, 1) ? 0 : -ENOBUFS; } /** diff --git a/test/test-pipeline/pipeline_hash.c b/test/test-pipeline/pipeline_hash.c index 10d2869..1ac0aa8 100644 --- a/test/test-pipeline/pipeline_hash.c +++ b/test/test-pipeline/pipeline_hash.c @@ -547,6 +547,6 @@ app_main_loop_rx_metadata(void) { app.rings_rx[i], (void **) app.mbuf_rx.array, n_mbufs); - } while (ret < 0); + } while (ret == 0); } } diff --git a/test/test-pipeline/runtime.c b/test/test-pipeline/runtime.c index 42a6142..4e20669 100644 --- a/test/test-pipeline/runtime.c +++ b/test/test-pipeline/runtime.c @@ -98,7 +98,7 @@ app_main_loop_rx(void) { app.rings_rx[i], (void **) app.mbuf_rx.array, n_mbufs); - } while (ret < 0); + } while (ret == 0); } } @@ -123,7 +123,7 @@ app_main_loop_worker(void) { (void **) worker_mbuf->array, app.burst_size_worker_read); - if (ret == -ENOENT) + if (ret == 0) continue; do { @@ -131,7 +131,7 @@ app_main_loop_worker(void) { app.rings_tx[i ^ 1], (void **) worker_mbuf->array, app.burst_size_worker_write); - } while (ret < 0); + } while (ret == 0); } } @@ -152,7 +152,7 @@ app_main_loop_tx(void) { (void **) &app.mbuf_tx[i].array[n_mbufs], app.burst_size_tx_read); - if (ret == -ENOENT) + if (ret == 0) continue; n_mbufs += app.burst_size_tx_read; diff --git a/test/test/test_ring.c b/test/test/test_ring.c index 666a451..112433b 100644 --- a/test/test/test_ring.c +++ b/test/test/test_ring.c @@ -117,20 +117,18 @@ test_ring_basic_full_empty(void * const src[], void *dst[]) rand = RTE_MAX(rte_rand() % RING_SIZE, 1UL); printf("%s: iteration %u, random shift: %u;\n", __func__, i, rand); - TEST_RING_VERIFY(-ENOBUFS != rte_ring_enqueue_bulk(r, src, - rand)); - TEST_RING_VERIFY(0 == rte_ring_dequeue_bulk(r, dst, rand)); + TEST_RING_VERIFY(rte_ring_enqueue_bulk(r, src, rand) != 0); + TEST_RING_VERIFY(rte_ring_dequeue_bulk(r, dst, rand) == rand); /* fill the ring */ - TEST_RING_VERIFY(-ENOBUFS != rte_ring_enqueue_bulk(r, src, - rsz)); + TEST_RING_VERIFY(rte_ring_enqueue_bulk(r, src, rsz) != 0); TEST_RING_VERIFY(0 == rte_ring_free_count(r)); TEST_RING_VERIFY(rsz == rte_ring_count(r)); TEST_RING_VERIFY(rte_ring_full(r)); TEST_RING_VERIFY(0 == rte_ring_empty(r)); /* empty the ring */ - TEST_RING_VERIFY(0 == rte_ring_dequeue_bulk(r, dst, rsz)); + TEST_RING_VERIFY(rte_ring_dequeue_bulk(r, dst, rsz) == rsz); TEST_RING_VERIFY(rsz == rte_ring_free_count(r)); TEST_RING_VERIFY(0 == rte_ring_count(r)); TEST_RING_VERIFY(0 == rte_ring_full(r)); @@ -171,37 +169,37 @@ test_ring_basic(void) printf("enqueue 1 obj\n"); ret = rte_ring_sp_enqueue_bulk(r, cur_src, 1); cur_src += 1; - if (ret != 0) + if (ret == 0) goto fail; printf("enqueue 2 objs\n"); ret = rte_ring_sp_enqueue_bulk(r, cur_src, 2); cur_src += 2; - if (ret != 0) + if (ret == 0) goto fail; printf("enqueue MAX_BULK objs\n"); ret = rte_ring_sp_enqueue_bulk(r, cur_src, MAX_BULK); cur_src += MAX_BULK; - if (ret != 0) + if (ret == 0) goto fail; printf("dequeue 1 obj\n"); ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 1); cur_dst += 1; - if (ret != 0) + if (ret == 0) goto fail; printf("dequeue 2 objs\n"); ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 2); cur_dst += 2; - if (ret != 0) + if (ret == 0) goto fail; printf("dequeue MAX_BULK objs\n"); ret = rte_ring_sc_dequeue_bulk(r, cur_dst, MAX_BULK); cur_dst += MAX_BULK; - if (ret != 0) + if (ret == 0) goto fail; /* check data */ @@ -217,37 +215,37 @@ test_ring_basic(void) printf("enqueue 1 obj\n"); ret = rte_ring_mp_enqueue_bulk(r, cur_src, 1); cur_src += 1; - if (ret != 0) + if (ret == 0) goto fail; printf("enqueue 2 objs\n"); ret = rte_ring_mp_enqueue_bulk(r, cur_src, 2); cur_src += 2; - if (ret != 0) + if (ret == 0) goto fail; printf("enqueue MAX_BULK objs\n"); ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); cur_src += MAX_BULK; - if (ret != 0) + if (ret == 0) goto fail; printf("dequeue 1 obj\n"); ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 1); cur_dst += 1; - if (ret != 0) + if (ret == 0) goto fail; printf("dequeue 2 objs\n"); ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 2); cur_dst += 2; - if (ret != 0) + if (ret == 0) goto fail; printf("dequeue MAX_BULK objs\n"); ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); cur_dst += MAX_BULK; - if (ret != 0) + if (ret == 0) goto fail; /* check data */ @@ -264,11 +262,11 @@ test_ring_basic(void) for (i = 0; i