ethdev: Proposal to expand API for single-pkt-tx
cover ethdev: Proposal to expand API for single-pkt-tx
This is an RFC patch to get feedback on this change proposal before I do any further investigation work into it, looking at all the example apps - as there are a lot of them. :-)
The idea is to remove all the code in the sample applications for buffering packets on TX by moving the buffering functionality into the ethdev API, so we can just do buffered TX of packets, one packet at a time.
For more details, see description in patch 1...
Bruce Richardson (2):
ethdev: add buffered single pkt TX function to API
l2fwd: update l2fwd to use tx_buffer API
config/common_bsdapp | 1 + config/common_linuxapp | 1 + examples/l2fwd/main.c | 61 +++++------------------------------------ lib/librte_ether/rte_ethdev.c | 55 +++++++++++++++++++++++++++++++++++-- lib/librte_ether/rte_ethdev.h | 63 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 56 deletions(-)
Signature · 1 line
1.9.3
A message that is not in the archive (sent off-list or not yet received): 1403649136-23551-1-git-send-email-bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
RFC PATCH 1/2 ethdev: add buffered single pkt TX function to API
Many sample apps include internal buffering for single-packet-at-a-time operation. Since this is such a common paradigm, this functionality is better suited to being inside the core ethdev API.
The new APIs include three functions:
* rte_eth_tx_buffer - buffer up a single packet for future transmission
* rte_eth_tx_buffer_flush - flush any unsent buffered packets
* rte_eth_tx_buffer_set_err_callback - set up a callback to be called in case transmitting a buffered burst fails. By default, we just free the unsent packets.
--- config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ether/rte_ethdev.c | 55 +++++++++++++++++++++++++++++++++++-- lib/librte_ether/rte_ethdev.h | 63 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-)
config/common_bsdapp +1 -0
@@ -138,6 +138,7 @@ CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=n CONFIG_RTE_MAX_ETHPORTS=32 CONFIG_RTE_LIBRTE_IEEE1588=n CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16 +CONFIG_RTE_ETHDEV_TX_BUFSIZE=32 # # Compile burst-oriented IGB & EM PMD drivers
config/common_linuxapp +1 -0
@@ -161,6 +161,7 @@ CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=n CONFIG_RTE_MAX_ETHPORTS=32 CONFIG_RTE_LIBRTE_IEEE1588=n CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16 +CONFIG_RTE_ETHDEV_TX_BUFSIZE=32 # # Support NIC bypass logic
lib/librte_ether/rte_ethdev.c +53 -2
88 lines not on this page · raw message
lib/librte_ether/rte_ethdev.h +63 -0
87 lines not on this page · raw message
Signature · 1 line
1.9.3
A message that is not in the archive (sent off-list or not yet received): 1403649136-23551-2-git-send-email-bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [RFC PATCH DRAFT 1/2] ethdev: add buffered single pkt TX function to API
lib/librte_ether/rte_ethdev.c rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id) · line 408
Quoted 10 lines · On Tue, 24 Jun 2014 23:32:15 +0100 Bruce Richardson…
lib/librte_ether/rte_ethdev.c +9
-0+static void +free_unsent_pkts (struct rte_mbuf **pkts,uint16_t unsent, + void *userdata __rte_unused) +{ +unsigned i; +for (i =0 ; i < unsent; i++) +rte_pktmbuf_free (pkts[i]); +} +
This should be moved into mbuf layer, and there it could be optimized to do a rte_mempool_mp_put_bulk. This would speed up operations becuase it would mean a single ring operation per set rather per mbuf segment.
Of course, the optimization would have to handle the refcnt issues.
A message that is not in the archive (sent off-list or not yet received): 20140624160545.136ad9e4-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org
Re: [RFC PATCH DRAFT 1/2] ethdev: add buffered single pkt TX function to API
Quoted 27 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, June 24, 2014 4:06 PM
To: Richardson, Bruce
Cc: [email protected]
Subject: Re: [dpdk-dev] [RFC PATCH DRAFT 1/2] ethdev: add buffered single pkt TX function to APIlib/librte_ether/rte_ethdev.c rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id) · line 408
Quoted 10 lines · On Tue, 24 Jun 2014 23:32:15 +0100 Bruce Richardson…
lib/librte_ether/rte_ethdev.c +9
-0+static void +free_unsent_pkts (struct rte_mbuf **pkts,uint16_t unsent, + void *userdata __rte_unused) +{ +unsigned i; +for (i =0 ; i < unsent; i++) +rte_pktmbuf_free (pkts[i]); +} +This should be moved into mbuf layer, and there it could be optimized to do a
rte_mempool_mp_put_bulk. This would speed up operations becuase it would mean a single ring operation per set rather per mbuf segment.
Quoted 2 lines
Of course, the optimization would have to handle the refcnt issues.
I'm not sure how we can improve this by bringing it into the mbuf layer. As well as handling of refcounts, we also have no guarantee than each mbuf queued up for a particular port comes from the same mempool. Can you please clarify how you think this might be better done?
Re: [RFC PATCH DRAFT 1/2] ethdev: add buffered single pkt TX function to API
In reply to a message not in the archiveQuoted 9 lines · On Tue, 24 Jun 2014 23:32:15 +0100 Bruce Richardson…
Many sample apps include internal buffering for single-packet-at-a-time operation. Since this is such a common paradigm, this functionality is better suited to being inside the core ethdev API.
The new APIs include three functions:
*rte_eth_tx_buffer- buffer up a single packet for future transmission
*rte_eth_tx_buffer_flush- flush any unsent buffered packets
*rte_eth_tx_buffer_set_err_callback- set up a callback to be called in case transmitting a buffered burst fails. By default, we just free the unsent packets
This must be per-queue to be MP safe.
Internally, we do something similar but it proved to be fastest to user per-cpu data in some cases.
A message that is not in the archive (sent off-list or not yet received): 20140624160716.57f99bd2-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org
Re: [RFC PATCH DRAFT 1/2] ethdev: add buffered single pkt TX function to API
Quoted 21 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, June 24, 2014 4:07 PM
To: Richardson, Bruce
Cc: [email protected]
Subject: Re: [dpdk-dev] [RFC PATCH DRAFT 1/2] ethdev: add buffered single pkt TX function to APIQuoted 9 lines · On Tue, 24 Jun 2014 23:32:15 +0100 Bruce Richardson…
Many sample apps include internal buffering for single-packet-at-a-time operation. Since this is such a common paradigm, this functionality is better suited to being inside the core ethdev API.
The new APIs include three functions:
*rte_eth_tx_buffer- buffer up a single packet for future transmission
*rte_eth_tx_buffer_flush- flush any unsent buffered packets
*rte_eth_tx_buffer_set_err_callback- set up a callback to be called in case transmitting a buffered burst fails. By default, we just free the unsent packets
Quoted 4 lines
This must be per-queue to be MP safe.
Internally, we do something similar but it proved to be fastest to user per-cpu data in some cases.
The implementation is per-queue. If you look at the changes to the tx queue setup function, we set up a buffer space for each TX queue inside the eth_dev_data structure that is then used for buffering that queue. The fact that it's handled per-queue inside the eth_dev means that it's as thread-safe as the existing tx_burst function, and also is completely driver agnostic.
RFC PATCH 2/2 l2fwd: update l2fwd to use tx_buffer API
In reply to a message not in the archiveThe internal buffering of packets for TX done in l2fwd is no longer needed, so replace this code with calls to the new rte_eth_tx_buffer* APIs.
--- examples/l2fwd/main.c | 61 ++++++--------------------------------------------- 1 file changed, 7 insertions(+), 54 deletions(-)
examples/l2fwd/main.c +7 -54
@@ -231,52 +231,6 @@ print_stats(void)printf ("\n====================================================\n" ); } -/* Send the burst of packets on an output interface */ -static int -l2fwd_send_burst (struct lcore_queue_conf *qconf,unsigned n,uint8_t port) -{ -struct rte_mbuf **m_table; -unsigned ret; -unsigned queueid =0 ; - - m_table = (struct rte_mbuf **)qconf->tx_mbufs[port].m_table; - - ret =rte_eth_tx_burst (port, (uint16_t ) queueid, m_table, (uint16_t ) n); - port_statistics[port].tx += ret; -if (unlikely (ret < n)) { - port_statistics[port].dropped += (n - ret); -do { -rte_pktmbuf_free (m_table[ret]); - }while (++ret < n); - } - -return 0 ; -} - -/* Enqueue packets for TX and prepare them to be sent */ -static int -l2fwd_send_packet (struct rte_mbuf *m,uint8_t port) -{ -unsigned lcore_id, len; -struct lcore_queue_conf *qconf; - - lcore_id =rte_lcore_id (); - - qconf = &lcore_queue_conf[lcore_id]; - len = qconf->tx_mbufs[port].len; - qconf->tx_mbufs[port].m_table[len] = m; - len++; - -/* enough pkts to be sent */ -if (unlikely (len ==MAX_PKT_BURST )) { -l2fwd_send_burst (qconf,MAX_PKT_BURST , port); - len =0 ; - } - - qconf->tx_mbufs[port].len = len; -return 0 ; -} -static void l2fwd_simple_forward (struct rte_mbuf *m,unsigned portid) {
@@ -294,7 +248,7 @@ l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid)/* src addr */ ether_addr_copy (&l2fwd_ports_eth_addr[dst_port], ð->s_addr); -l2fwd_send_packet (m, (uint8_t ) dst_port); + port_statistics[dst_port].tx +=rte_eth_tx_buffer (dst_port,0 , m); }/* main processing loop */
@@ -339,13 +293,12 @@ l2fwd_main_loop(void) diff_tsc = cur_tsc - prev_tsc;if (unlikely (diff_tsc > drain_tsc)) { -for (portid =0 ; portid <RTE_MAX_ETHPORTS ; portid++) { -if (qconf->tx_mbufs[portid].len ==0 ) -continue ; -l2fwd_send_burst (&lcore_queue_conf[lcore_id], - qconf->tx_mbufs[portid].len, - (uint8_t ) portid); - qconf->tx_mbufs[portid].len =0 ; +for (i =0 ; i < qconf->n_rx_port; i++) { + + portid = qconf->rx_port_list[i]; + portid = l2fwd_dst_ports[portid]; + port_statistics[portid].tx += +rte_eth_tx_buffer_flush (portid,0 ); }/* if timer is enabled */
Signature · 1 line
1.9.3