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 B70D8594E for ; Thu, 12 Mar 2015 17:54:35 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 12 Mar 2015 09:54:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,389,1422950400"; d="scan'208";a="540033526" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 12 Mar 2015 09:53:51 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t2CGsXtZ001901; Thu, 12 Mar 2015 16:54:33 GMT Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t2CGsWWK022210; Thu, 12 Mar 2015 16:54:32 GMT Received: (from jmcnam2x@localhost) by sivswdev02.ir.intel.com with id t2CGsWJc022206; Thu, 12 Mar 2015 16:54:32 GMT From: John McNamara To: dev@dpdk.org Date: Thu, 12 Mar 2015 16:54:28 +0000 Message-Id: <1426179268-22164-2-git-send-email-john.mcnamara@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1426179268-22164-1-git-send-email-john.mcnamara@intel.com> References: <1426179268-22164-1-git-send-email-john.mcnamara@intel.com> Subject: [dpdk-dev] [PATCH] ethdev: added additional packet count parameter to RX callbacks X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Mar 2015 16:54:37 -0000 Added a parameter to the RX callback to pass in the number of available RX packets in addition to the number of dequeued packets. This provides the RX callback functions with additional information that can be used to decide how packets from a burst are handled. The TX callback doesn't require this additional parameter so the RX and TX callbacks no longer have the same function parameters. As such the single RX/TX callback has been refactored into two separate callbacks. Signed-off-by: John McNamara --- examples/rxtx_callbacks/main.c | 3 +- lib/librte_ether/rte_ethdev.c | 8 ++-- lib/librte_ether/rte_ethdev.h | 74 ++++++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c index 9e5e68e..21117ce 100644 --- a/examples/rxtx_callbacks/main.c +++ b/examples/rxtx_callbacks/main.c @@ -61,7 +61,8 @@ static struct { static uint16_t add_timestamps(uint8_t port __rte_unused, uint16_t qidx __rte_unused, - struct rte_mbuf **pkts, uint16_t nb_pkts, void *_ __rte_unused) + struct rte_mbuf **pkts, uint16_t nb_pkts, + uint16_t max_pkts __rte_unused, void *_ __rte_unused) { unsigned i; uint64_t now = rte_rdtsc(); diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 03fce08..e142920 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -3533,7 +3533,7 @@ rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type, void * rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, - rte_rxtx_callback_fn fn, void *user_param) + rte_rx_callback_fn fn, void *user_param) { #ifndef RTE_ETHDEV_RXTX_CALLBACKS rte_errno = ENOTSUP; @@ -3553,7 +3553,7 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, return NULL; } - cb->fn = fn; + cb->fn.rx = fn; cb->param = user_param; cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb; @@ -3562,7 +3562,7 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, void * rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id, - rte_rxtx_callback_fn fn, void *user_param) + rte_tx_callback_fn fn, void *user_param) { #ifndef RTE_ETHDEV_RXTX_CALLBACKS rte_errno = ENOTSUP; @@ -3582,7 +3582,7 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id, return NULL; } - cb->fn = fn; + cb->fn.tx = fn; cb->param = user_param; cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id]; rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb; diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 21aa359..e0b0b8d 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1384,33 +1384,52 @@ struct eth_dev_ops { }; /** - * Function type used for callbacks for processing packets on RX and TX + * Function type used for RX packet processing packet callbacks. * - * If configured for RX, it is called with a burst of packets that have just - * been received on the given port and queue. On TX, it is called with a burst - * of packets immediately before those packets are put onto the hardware queue - * for transmission. + * The callback function is called on RX with a burst of packets that have + * been received on the given port and queue. * * @param port - * The ethernet port on which rx or tx is being performed + * The Ethernet port on which RX is being performed. * @param queue - * The queue on the ethernet port which is being used to receive or transmit - * the packets. + * The queue on the Ethernet port which is being used to receive the packets. * @param pkts - * The burst of packets on which processing is to be done. On RX, these - * packets have just been received. On TX, they are about to be transmitted. + * The burst of packets that have just been received. * @param nb_pkts - * The number of packets in the burst pointed to by "pkts" + * The number of packets in the burst pointed to by "pkts". + * @param max_pkts + * The max number of packets that can be stored in the "pkts" array. * @param user_param * The arbitrary user parameter passed in by the application when the callback * was originally configured. * @return - * The number of packets remaining in pkts are processing. - * * On RX, this will be returned to the user as the return value from - * rte_eth_rx_burst. - * * On TX, this will be the number of packets actually written to the NIC. + * The number of packets returned to the user. */ -typedef uint16_t (*rte_rxtx_callback_fn)(uint8_t port, uint16_t queue, +typedef uint16_t (*rte_rx_callback_fn)(uint8_t port, uint16_t queue, + struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t max_pkts, + void *user_param); + +/** + * Function type used for TX packet processing packet callbacks. + * + * The callback function is called on TX with a burst of packets immediately + * before the packets are put onto the hardware queue for transmission. + * + * @param port + * The Ethernet port on which TX is being performed. + * @param queue + * The queue on the Ethernet port which is being used to transmit the packets. + * @param pkts + * The burst of packets that are about to be transmitted. + * @param nb_pkts + * The number of packets in the burst pointed to by "pkts". + * @param user_param + * The arbitrary user parameter passed in by the application when the callback + * was originally configured. + * @return + * The number of packets to be written to the NIC. + */ +typedef uint16_t (*rte_tx_callback_fn)(uint8_t port, uint16_t queue, struct rte_mbuf *pkts[], uint16_t nb_pkts, void *user_param); /** @@ -1420,7 +1439,10 @@ typedef uint16_t (*rte_rxtx_callback_fn)(uint8_t port, uint16_t queue, */ struct rte_eth_rxtx_callback { struct rte_eth_rxtx_callback *next; - rte_rxtx_callback_fn fn; + union{ + rte_rx_callback_fn rx; + rte_tx_callback_fn tx; + } fn; void *param; }; @@ -2386,28 +2408,28 @@ extern uint16_t rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, #else static inline uint16_t rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, - struct rte_mbuf **rx_pkts, uint16_t nb_pkts) + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { struct rte_eth_dev *dev; dev = &rte_eth_devices[port_id]; - nb_pkts = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id], rx_pkts, - nb_pkts); + int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id], + rx_pkts, nb_pkts); #ifdef RTE_ETHDEV_RXTX_CALLBACKS struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id]; if (unlikely(cb != NULL)) { do { - nb_pkts = cb->fn(port_id, queue_id, rx_pkts, nb_pkts, - cb->param); + nb_rx = cb->fn.rx(port_id, queue_id, rx_pkts, nb_rx, + nb_pkts, cb->param); cb = cb->next; } while (cb != NULL); } #endif - return nb_pkts; + return nb_rx; } #endif @@ -2540,7 +2562,7 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id, if (unlikely(cb != NULL)) { do { - nb_pkts = cb->fn(port_id, queue_id, tx_pkts, nb_pkts, + nb_pkts = cb->fn.tx(port_id, queue_id, tx_pkts, nb_pkts, cb->param); cb = cb->next; } while (cb != NULL); @@ -3490,7 +3512,7 @@ int rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type, * On success, a pointer value which can later be used to remove the callback. */ void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, - rte_rxtx_callback_fn fn, void *user_param); + rte_rx_callback_fn fn, void *user_param); /** * Add a callback to be called on packet TX on a given port and queue. @@ -3515,7 +3537,7 @@ void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, * On success, a pointer value which can later be used to remove the callback. */ void *rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id, - rte_rxtx_callback_fn fn, void *user_param); + rte_tx_callback_fn fn, void *user_param); /** * Remove an RX packet callback from a given port and queue. -- 1.7.4.1