Skip to contentSkip to conversation

linux/kni: Added support for KNI multiple fifos

PATCH New dheemanth 1 participant 1 message Dec 8, 2020 Network drivers

lore
Share & tools
lore

dheemanth

author
#0 lore raw

PATCH 2/2 linux/kni: Added support for KNI multiple fifos

In order to improve performance, the KNI is made to support multiple fifos, So that multiple threads pinned to multiple cores can process packets in parallel.

---
 app/test/test_kni.c             |   4 +-
 drivers/net/kni/rte_eth_kni.c   |   5 +-
 examples/kni/main.c             |   4 +-
 kernel/linux/kni/kni_dev.h      |  11 +-
 kernel/linux/kni/kni_fifo.h     | 186 ++++++++++++++++++++++++++++------
 kernel/linux/kni/kni_misc.c     | 193 +++++++++++++++++++++--------------
 kernel/linux/kni/kni_net.c      |  90 +++++++++++------
 lib/librte_kni/rte_kni.c        | 218 ++++++++++++++++++++++++++--------------
 lib/librte_kni/rte_kni.h        |  11 +-
 lib/librte_kni/rte_kni_common.h |  10 +-
 lib/librte_port/rte_port_kni.c  |  12 +--
 11 files changed, 515 insertions(+), 229 deletions(-)
app/test/test_kni.c +2 -2
index f53a53e..9bbceab 100644
@@ -245,7 +245,7 @@ test_kni_loop(__rte_unused void *arg)
 			}
 
 			num = rte_kni_tx_burst(test_kni_ctx, pkts_burst,
-								nb_rx);
+						nb_rx, 0);
 			stats.ingress += num;
 			rte_kni_handle_request(test_kni_ctx);
 			if (num < nb_rx) {
@@ -260,7 +260,7 @@ test_kni_loop(__rte_unused void *arg)
 			if (test_kni_processing_flag)
 				break;
 			num = rte_kni_rx_burst(test_kni_ctx, pkts_burst,
-							PKT_BURST_SZ);
+						PKT_BURST_SZ, 0);
 			stats.egress += num;
 			for (nb_tx = 0; nb_tx < num; nb_tx++)
 				rte_pktmbuf_free(pkts_burst[nb_tx]);
drivers/net/kni/rte_eth_kni.c +3 -2
index 1696787..55711c5 100644
@@ -81,7 +81,7 @@ eth_kni_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 	uint16_t nb_pkts;
 	int i;
 
-	nb_pkts = rte_kni_rx_burst(kni, bufs, nb_bufs);
+	nb_pkts = rte_kni_rx_burst(kni, bufs, nb_bufs, 0);
 	for (i = 0; i < nb_pkts; i++)
 		bufs[i]->port = kni_q->internals->port_id;
 
@@ -97,7 +97,7 @@ eth_kni_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 	struct rte_kni *kni = kni_q->internals->kni;
 	uint16_t nb_pkts;
 
-	nb_pkts =  rte_kni_tx_burst(kni, bufs, nb_bufs);
+	nb_pkts =  rte_kni_tx_burst(kni, bufs, nb_bufs, 0);
 
 	kni_q->tx.pkts += nb_pkts;
 
@@ -129,6 +129,7 @@ eth_kni_start(struct rte_eth_dev *dev)
 
 	mb_pool = internals->rx_queues[0].mb_pool;
 	strlcpy(conf.name, name, RTE_KNI_NAMESIZE);
+	memset(&conf, 0, sizeof(conf));
 	conf.force_bind = 0;
 	conf.group_id = port_id;
 	conf.mbuf_size =
examples/kni/main.c +2 -2
index fe93b86..a34bf1a 100644
@@ -229,7 +229,7 @@ kni_ingress(struct kni_port_params *p)
 			return;
 		}
 		/* Burst tx to kni */
-		num = rte_kni_tx_burst(p->kni[i], pkts_burst, nb_rx);
+		num = rte_kni_tx_burst(p->kni[i], pkts_burst, nb_rx, 0);
 		if (num)
 			kni_stats[port_id].rx_packets += num;
 
@@ -261,7 +261,7 @@ kni_egress(struct kni_port_params *p)
 	port_id = p->port_id;
 	for (i = 0; i < nb_kni; i++) {
 		/* Burst rx from kni */
-		num = rte_kni_rx_burst(p->kni[i], pkts_burst, PKT_BURST_SZ);
+		num = rte_kni_rx_burst(p->kni[i], pkts_burst, PKT_BURST_SZ, 0);
 		if (unlikely(num > PKT_BURST_SZ)) {
 			RTE_LOG(ERR, APP, "Error receiving from KNI\n");
 			return;
kernel/linux/kni/kni_dev.h +7 -4
index c15da311..3f146e2 100644
@@ -55,16 +55,16 @@ struct kni_dev {
 	struct net_device *net_dev;
 
 	/* queue for packets to be sent out */
-	struct rte_kni_fifo *tx_q;
+	struct rte_kni_fifo *tx_q[RTE_MAX_LCORE];
 
 	/* queue for the packets received */
-	struct rte_kni_fifo *rx_q;
+	struct rte_kni_fifo *rx_q[RTE_MAX_LCORE];
 
 	/* queue for the allocated mbufs those can be used to save sk buffs */
-	struct rte_kni_fifo *alloc_q;
+	struct rte_kni_fifo *alloc_q[RTE_MAX_LCORE];
 
 	/* free queue for the mbufs to be freed */
-	struct rte_kni_fifo *free_q;
+	struct rte_kni_fifo *free_q[RTE_MAX_LCORE];
 
 	/* request queue */
 	struct rte_kni_fifo *req_q;
@@ -87,6 +87,9 @@ struct kni_dev {
 	void *alloc_pa[MBUF_BURST_SZ];
 	void *alloc_va[MBUF_BURST_SZ];
 
+	unsigned queues_num;
+	unsigned fifos_num;
+
 	struct task_struct *usr_tsk;
 };
 
kernel/linux/kni/kni_fifo.h +158 -28

206 lines not on this page · raw message

kernel/linux/kni/kni_misc.c +120 -73

301 lines not on this page · raw message

kernel/linux/kni/kni_net.c +61 -29

237 lines not on this page · raw message

lib/librte_kni/rte_kni.c +141 -77

372 lines not on this page · raw message

lib/librte_kni/rte_kni.h +9 -2
index b0eaf46..328024b 100644
@@ -75,6 +75,9 @@ struct rte_kni_conf {
 	uint16_t mtu;
 	uint16_t min_mtu;
 	uint16_t max_mtu;
+
+	unsigned fifos_num; 
+	unsigned queues_num;
 };
 
 /**
@@ -162,12 +165,14 @@ int rte_kni_handle_request(struct rte_kni *kni);
  *  The array to store the pointers of mbufs.
  * @param num
  *  The maximum number per burst.
+ * @param index
+ *  The rx_q fifo's index of the KNI interface.
  *
  * @return
  *  The actual number of packets retrieved.
  */
 unsigned rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
-		unsigned num);
+		unsigned num, unsigned index);
 
 /**
  * Send a burst of packets to a KNI interface. The packets to be sent out are
@@ -181,12 +186,14 @@ unsigned rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
  *  The array to store the pointers of mbufs.
  * @param num
  *  The maximum number per burst.
+ * @param index
+ *  The tx_q fifo's index of the KNI interface.
  *
  * @return
  *  The actual number of packets sent.
  */
 unsigned rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
-		unsigned num);
+		unsigned num, unsigned index);
 
 /**
  * Get the KNI context of its name.
lib/librte_kni/rte_kni_common.h +6 -4
index ffb3182..b6e6b82 100644
@@ -99,10 +99,10 @@ struct rte_kni_mbuf {
 struct rte_kni_device_info {
 	char name[RTE_KNI_NAMESIZE];  /**< Network device name for KNI */
 
-	phys_addr_t tx_phys;
-	phys_addr_t rx_phys;
-	phys_addr_t alloc_phys;
-	phys_addr_t free_phys;
+	phys_addr_t tx_phys[RTE_MAX_LCORE];
+	phys_addr_t rx_phys[RTE_MAX_LCORE];
+	phys_addr_t alloc_phys[RTE_MAX_LCORE];
+	phys_addr_t free_phys[RTE_MAX_LCORE];
 
 	/* Used by Ethtool */
 	phys_addr_t req_phys;
@@ -127,6 +127,8 @@ struct rte_kni_device_info {
 	unsigned int max_mtu;
 	uint8_t mac_addr[6];
 	uint8_t iova_mode;
+	unsigned fifos_num;
+	unsigned queues_num;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_port/rte_port_kni.c +6 -6
index 7b370f9..648b832 100644
@@ -67,7 +67,7 @@ rte_port_kni_reader_rx(void *port, struct rte_mbuf **pkts, uint32_t n_pkts)
 			port;
 	uint16_t rx_pkt_cnt;
 
-	rx_pkt_cnt = rte_kni_rx_burst(p->kni, pkts, n_pkts);
+	rx_pkt_cnt = rte_kni_rx_burst(p->kni, pkts, n_pkts, 0);
 	RTE_PORT_KNI_READER_STATS_PKTS_IN_ADD(p, rx_pkt_cnt);
 	return rx_pkt_cnt;
 }
@@ -165,7 +165,7 @@ send_burst(struct rte_port_kni_writer *p)
 {
 	uint32_t nb_tx;
 
-	nb_tx = rte_kni_tx_burst(p->kni, p->tx_buf, p->tx_buf_count);
+	nb_tx = rte_kni_tx_burst(p->kni, p->tx_buf, p->tx_buf_count, 0);
 
 	RTE_PORT_KNI_WRITER_STATS_PKTS_DROP_ADD(p, p->tx_buf_count - nb_tx);
 	for (; nb_tx < p->tx_buf_count; nb_tx++)
@@ -208,7 +208,7 @@ rte_port_kni_writer_tx_bulk(void *port,
 			send_burst(p);
 
 		RTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(p, n_pkts);
-		n_pkts_ok = rte_kni_tx_burst(p->kni, pkts, n_pkts);
+		n_pkts_ok = rte_kni_tx_burst(p->kni, pkts, n_pkts, 0);
 
 		RTE_PORT_KNI_WRITER_STATS_PKTS_DROP_ADD(p, n_pkts - n_pkts_ok);
 		for (; n_pkts_ok < n_pkts; n_pkts_ok++) {
@@ -349,7 +349,7 @@ send_burst_nodrop(struct rte_port_kni_writer_nodrop *p)
 {
 	uint32_t nb_tx = 0, i;
 
-	nb_tx = rte_kni_tx_burst(p->kni, p->tx_buf, p->tx_buf_count);
+	nb_tx = rte_kni_tx_burst(p->kni, p->tx_buf, p->tx_buf_count, 0);
 
 	/* We sent all the packets in a first try */
 	if (nb_tx >= p->tx_buf_count) {
@@ -360,7 +360,7 @@ send_burst_nodrop(struct rte_port_kni_writer_nodrop *p)
 	for (i = 0; i < p->n_retries; i++) {
 		nb_tx += rte_kni_tx_burst(p->kni,
 			p->tx_buf + nb_tx,
-			p->tx_buf_count - nb_tx);
+			p->tx_buf_count - nb_tx, 0);
 
 		/* We sent all the packets in more than one try */
 		if (nb_tx >= p->tx_buf_count) {
@@ -412,7 +412,7 @@ rte_port_kni_writer_nodrop_tx_bulk(void *port,
 			send_burst_nodrop(p);
 
 		RTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_IN_ADD(p, n_pkts);
-		n_pkts_ok = rte_kni_tx_burst(p->kni, pkts, n_pkts);
+		n_pkts_ok = rte_kni_tx_burst(p->kni, pkts, n_pkts, 0);
 
 		if (n_pkts_ok >= n_pkts)
 			return 0;
Signature · 1 line
2.7.4