Skip to contentSkip to conversation

linux/kni: Added support for KNI multiple fifos

PATCH In review dheemanth 4 participants 6 messages Dec 11, 2020 – Jun 13, 2023 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     | 190 ++++++++++++++++++++++++++++++-----
 kernel/linux/kni/kni_misc.c     | 189 +++++++++++++++++++++--------------
 kernel/linux/kni/kni_net.c      |  88 ++++++++++------
 lib/librte_kni/rte_kni.c        | 216 ++++++++++++++++++++++++++--------------
 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, 514 insertions(+), 226 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..f782ec1 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 int queues_num;
+	unsigned int fifos_num;
+
 	struct task_struct *usr_tsk;
 };
 
kernel/linux/kni/kni_fifo.h +164 -26

212 lines not on this page · raw message

kernel/linux/kni/kni_misc.c +117 -72

296 lines not on this page · raw message

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

235 lines not on this page · raw message

lib/librte_kni/rte_kni.c +139 -77

370 lines not on this page · raw message

lib/librte_kni/rte_kni.h +9 -2
index b0eaf46..31fe42a 100644
@@ -75,6 +75,9 @@ struct rte_kni_conf {
 	uint16_t mtu;
 	uint16_t min_mtu;
 	uint16_t max_mtu;
+
+	unsigned int fifos_num;
+	unsigned int 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 int num, unsigned int 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 int num, unsigned int index);
 
 /**
  * Get the KNI context of its name.
lib/librte_kni/rte_kni_common.h +6 -4
index ffb3182..35afebf 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 int fifos_num;
+	unsigned int 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
#1 lore raw

11/12/2020 00:15, dheemanth:

Quoted 5 lines

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.

Is there a patch 1/2?

Cc Ferruh, KNI maintainer.

#2 lore raw

No, this is the only patch.

Regards,
Dheemanth

On 1/17/21, 2:02 PM, "Thomas Monjalon" <[email protected]> wrote:

11/12/2020 00:15, dheemanth:
> 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. >
> Signed-off-by: dheemanth <[email protected]>

Is there a patch 1/2?

Cc Ferruh, KNI maintainer.

#3 lore raw
In reply to dheemanth
Quoted 5 lines · dheemanth

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.

Hi Dheemanth,

I didn't check the patch yet but as a very high level comment,
it is possible to create multiple KNI interface and use multiple cores for each, instead of multiple FIFO in a single interface. KNI example uses this approach. Did you investigate this approach? What is the benefit of multiple FIFO against multiple KNI interface?

Thanks,
ferruh

#4 lore raw
In reply to dheemanth
Quoted 4 lines · dheemanth

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.

Hi Dheemanth,

As far as I know, in KNI the bottle neck is in the kernel thread. In this patch FIFO between userspace and kernelspace converted into multiple FIFOs but in kernel side still same thread process all FIFOs, so only userspace can scale to more cores, I wonder how this imporves the performance, can you please share use case and some numbers?

Also FIFOs seems converted from simple single producer, single consumer to multi producer and multi consumer. What is the performance impact of this? And why this is needed? In the dpdk application, is there N-N relation between cores and fifos, again can you please clarifiy your usecase?

In the kernel to userspace transfer, packets distributed to multiple FIFOs based on packet hash, this should be additional load to the kernel thread.

The sample application and unit test (also kni pmd) is not using this new feature but they only use single fifo. They also should be updated to use this feature, that helps as sample and helps to demonstrade the usecase.

Btw, can you please clarify why 'queues_num' is used? Is it expected to be same with 'fifos_num'?

Also documentation needs to be updated, but before more change I think the benefit of the work needs to be clarified to decide to proceed or not with the set.

Quoted 15 lines
---
 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     | 190 ++++++++++++++++++++++++++++++-----
 kernel/linux/kni/kni_misc.c     | 189 +++++++++++++++++++++--------------
 kernel/linux/kni/kni_net.c      |  88 ++++++++++------
 lib/librte_kni/rte_kni.c        | 216 ++++++++++++++++++++++++++--------------
 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, 514 insertions(+), 226 deletions(-)

<...>

Quoted 5 lines
kernel/linux/kni/kni_misc.c +0 -1
@@ -292,51 +292,69 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 {
 	struct kni_net *knet = net_generic(net, kni_net_id);
 	int ret;
-	struct rte_kni_device_info dev_info;

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 304

Quoted 10 lines
kernel/linux/kni/kni_misc.c +6 -0
+	unsigned int i, tx_queues_num;
+	struct rte_kni_device_info *dev_info;
 	struct net_device *net_dev = NULL;
 	struct kni_dev *kni, *dev, *n;
 
 	pr_info("Creating kni...\n");
+
+	/* allocate dev_info from stack to avoid Wframe-larger-than=1024
+	 * compile error.
+	 */

s/stack/heap

Quoted 4 lines
kernel/linux/kni/kni_misc.c +4 -0
+	dev_info = kzalloc(sizeof(struct rte_kni_device_info), GFP_KERNEL);
+	if (!dev_info)
+		return -ENOMEM;
+

<...>