[dpdk-dev] [PATCH 1/6] ethdev: add Tx preparation
Jerin Jacob
jerin.jacob at caviumnetworks.com
Thu Sep 8 09:28:47 CEST 2016
On Fri, Aug 26, 2016 at 06:22:53PM +0200, Tomasz Kulasek wrote:
> Added API for `rte_eth_tx_prep`
>
> uint16_t rte_eth_tx_prep(uint8_t port_id, uint16_t queue_id,
> struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
>
> Added fields to the `struct rte_eth_desc_lim`:
>
> uint16_t nb_seg_max;
> /**< Max number of segments per whole packet. */
>
> uint16_t nb_mtu_seg_max;
> /**< Max number of segments per one MTU */
>
> Created `rte_pkt.h` header with common used functions:
>
> int rte_validate_tx_offload(struct rte_mbuf *m)
> to validate general requirements for tx offload in packet such a
> flag completness. In current implementation this function is called
> optionaly when RTE_LIBRTE_ETHDEV_DEBUG is enabled.
>
> int rte_phdr_cksum_fix(struct rte_mbuf *m)
> to fix pseudo header checksum for TSO and non-TSO tcp/udp packets
> before hardware tx checksum offload.
> - for non-TSO tcp/udp packets full pseudo-header checksum is
> counted and set.
> - for TSO the IP payload length is not included.
>
> Signed-off-by: Tomasz Kulasek <tomaszx.kulasek at intel.com>
> ---
> lib/librte_ether/rte_ethdev.h | 74 +++++++++++++++++++++++
> lib/librte_mbuf/rte_mbuf.h | 8 +++
> lib/librte_net/Makefile | 2 +-
> lib/librte_net/rte_pkt.h | 132 +++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 215 insertions(+), 1 deletion(-)
> create mode 100644 lib/librte_net/rte_pkt.h
>
> diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
> index b0fe033..02569ca 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -182,6 +182,7 @@ extern "C" {
> #include <rte_pci.h>
> #include <rte_dev.h>
> #include <rte_devargs.h>
> +#include <rte_errno.h>
> #include "rte_ether.h"
> #include "rte_eth_ctrl.h"
> #include "rte_dev_info.h"
> @@ -696,6 +697,8 @@ struct rte_eth_desc_lim {
> uint16_t nb_max; /**< Max allowed number of descriptors. */
> uint16_t nb_min; /**< Min allowed number of descriptors. */
> uint16_t nb_align; /**< Number of descriptors should be aligned to. */
> + uint16_t nb_seg_max; /**< Max number of segments per whole packet. */
> + uint16_t nb_mtu_seg_max; /**< Max number of segments per one MTU */
> };
>
> /**
> @@ -1181,6 +1184,12 @@ typedef uint16_t (*eth_tx_burst_t)(void *txq,
> uint16_t nb_pkts);
> /**< @internal Send output packets on a transmit queue of an Ethernet device. */
>
> +typedef uint16_t (*eth_tx_prep_t)(void *txq,
> + struct rte_mbuf **tx_pkts,
> + uint16_t nb_pkts);
> +/**< @internal Prepare output packets on a transmit queue of an Ethernet
> + device. */
> +
> typedef int (*flow_ctrl_get_t)(struct rte_eth_dev *dev,
> struct rte_eth_fc_conf *fc_conf);
> /**< @internal Get current flow control parameter on an Ethernet device */
> @@ -1626,6 +1635,7 @@ enum rte_eth_dev_type {
> struct rte_eth_dev {
> eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
> eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
> + eth_tx_prep_t tx_pkt_prep; /**< Pointer to PMD transmit prepare function. */
> struct rte_eth_dev_data *data; /**< Pointer to device data */
> const struct eth_driver *driver;/**< Driver for this device */
> const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
> @@ -2833,6 +2843,70 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
> return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
> }
>
> +/**
> + * Process a burst of output packets on a transmit queue of an Ethernet device.
> + *
> + * The rte_eth_tx_prep() function is invoked to prepare output packets to be
> + * transmitted on the output queue *queue_id* of the Ethernet device designated
> + * by its *port_id*.
> + * The *nb_pkts* parameter is the number of packets to be prepared which are
> + * supplied in the *tx_pkts* array of *rte_mbuf* structures, each of them
> + * allocated from a pool created with rte_pktmbuf_pool_create().
> + * For each packet to send, the rte_eth_tx_prep() function performs
> + * the following operations:
> + *
> + * - Check if packet meets devices requirements for tx offloads.
> + *
> + * - Check limitations about number of segments.
> + *
> + * - Check additional requirements when debug is enabled.
> + *
> + * - Update and/or reset required checksums when tx offload is set for packet.
> + *
> + * The rte_eth_tx_prep() function returns the number of packets ready to be
> + * sent. A return value equal to *nb_pkts* means that all packets are valid and
> + * ready to be sent.
> + *
> + * @param port_id
> + * The port identifier of the Ethernet device.
> + * @param queue_id
> + * The index of the transmit queue through which output packets must be
> + * sent.
> + * The value must be in the range [0, nb_tx_queue - 1] previously supplied
> + * to rte_eth_dev_configure().
> + * @param tx_pkts
> + * The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
> + * which contain the output packets.
> + * @param nb_pkts
> + * The maximum number of packets to process.
> + * @return
> + * The number of packets correct and ready to be sent. The return value can be
> + * less than the value of the *tx_pkts* parameter when some packet doesn't
> + * meet devices requirements with rte_errno set appropriately.
> + */
> +static inline uint16_t
> +rte_eth_tx_prep(uint8_t port_id, uint16_t queue_id, struct rte_mbuf **tx_pkts,
> + uint16_t nb_pkts)
> +{
> + struct rte_eth_dev *dev = &rte_eth_devices[port_id];
> +
> + if (!dev->tx_pkt_prep) {
> + rte_errno = -ENOTSUP;
rte_errno update may not be necessary here. see below
> + return 0;
IMO, We should return "nb_pkts" here instead of 0(i.e, all the packets
are valid in-case PMD does not have tx_prep function) and in-case of "0"
the following check in the application also will fail for no reason
if (nb_prep < nb_pkts) {
printf("tx_prep failed\n");
}
> + }
> +
> +#ifdef RTE_LIBRTE_ETHDEV_DEBUG
> + if (queue_id >= dev->data->nb_tx_queues) {
> + RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
> + rte_errno = -EINVAL;
> + return 0;
> + }
> +#endif
> +
> + return (*dev->tx_pkt_prep)(dev->data->tx_queues[queue_id],
> + tx_pkts, nb_pkts);
> +}
> +
IMO, We need to provide a compile time option for rte_eth_tx_prep as
NOOP. Default option should be non NOOP but incase a _target_ want to
override to NOOP it should be possible, the reasons is:
- Low-end ARMv7,ARMv8 targets may not have PCIE-RC support and it may
have only integrated NIC controller. On those targets, where integrated
NIC controller does not use tx_prep service it can made it as NOOP to
save cycles on following "rte_eth_tx_prep" and associated "if
(unlikely(nb_prep < nb_rx))" checks in the application.
/* Prepare burst of TX packets */
nb_prep = rte_eth_tx_prep(fs->rx_port, 0, pkts_burst, nb_rx);
if (unlikely(nb_prep < nb_rx)) {
int i;
for (i = nb_prep; i < nb_rx; i++)
rte_pktmbuf_free(pkts_burst[i]);
}
Jerin
More information about the dev
mailing list