Skip to contentSkip to conversation

octeontx2-pf: Add support for page pool

PATCH Superseded Ratheesh Kannoth 3 participants 5 messages May 19, 2023

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ratheesh Kannoth

author maintainer
#0 lore raw

PATCH v3 1/1 octeontx2-pf: Add support for page pool

Page pool for each rx queue enhance rx side performance by reclaiming buffers back to each queue specific pool. DMA mapping is done only for first allocation of buffers. As subsequent buffers allocation avoid DMA mapping, it results in performance improvement.

Image        |  Performance
------------ | ------------
Vannila      |   3Mpps
             |
with this    |   42Mpps

change |
---------------------------

---

ChangeLog

v2 -> v3:
* Modified commit message
* Fixed nit comments.

v1 -> v2:
* Removed GFP_DMA flag
* Returned correct err value

v0 -> v1:
* Removed CONFIG_PAGE_POOL #ifdefs in code
* Used compound page APIs
* Replaced page_pool_put_page API with page_pool_put_full_page API

---
 .../net/ethernet/marvell/octeontx2/Kconfig    |  1 +
 .../marvell/octeontx2/nic/otx2_common.c       | 74 ++++++++++++++++---
 .../marvell/octeontx2/nic/otx2_common.h       |  6 +-
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  | 11 ++-
 .../marvell/octeontx2/nic/otx2_txrx.c         | 19 +++--
 .../marvell/octeontx2/nic/otx2_txrx.h         |  1 +
 .../ethernet/marvell/octeontx2/nic/qos_sq.c   |  2 +-
 7 files changed, 93 insertions(+), 21 deletions(-)
drivers/net/ethernet/marvell/octeontx2/Kconfig +1 -0
index 993ac180a5db..a32d85d6f599 100644
@@ -32,6 +32,7 @@ config OCTEONTX2_PF
 	tristate "Marvell OcteonTX2 NIC Physical Function driver"
 	select OCTEONTX2_MBOX
 	select NET_DEVLINK
+	select PAGE_POOL
 	depends on (64BIT && COMPILE_TEST) || ARM64
 	select DIMLIB
 	depends on PCI
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +65 -9

135 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +4 -2
index b2267c8bec37..a9ed15d1793a 100644
@@ -976,7 +976,7 @@ int otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
 int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable);
 void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
 int otx2_nix_config_bp(struct otx2_nic *pfvf, bool enable);
-void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
+void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq, int qidx);
 void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
 int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura);
 int otx2_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura);
@@ -984,7 +984,7 @@ int cn10k_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura);
 int otx2_alloc_buffer(struct otx2_nic *pfvf, struct otx2_cq_queue *cq,
 		      dma_addr_t *dma);
 int otx2_pool_init(struct otx2_nic *pfvf, u16 pool_id,
-		   int stack_pages, int numptrs, int buf_size);
+		   int stack_pages, int numptrs, int buf_size, int type);
 int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
 		   int pool_id, int numptrs);
 
@@ -1054,6 +1054,8 @@ u16 otx2_get_max_mtu(struct otx2_nic *pfvf);
 int otx2_handle_ntuple_tc_features(struct net_device *netdev,
 				   netdev_features_t features);
 int otx2_smq_flush(struct otx2_nic *pfvf, int smq);
+void otx2_free_bufs(struct otx2_nic *pfvf, struct otx2_pool *pool,
+		    u64 iova, int size);
 
 /* tc support */
 int otx2_init_tc(struct otx2_nic *nic);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -1
index e1883c3edda3..db3fcab1c8cd 100644
@@ -1555,7 +1555,9 @@ static void otx2_free_hw_resources(struct otx2_nic *pf)
 	struct nix_lf_free_req *free_req;
 	struct mbox *mbox = &pf->mbox;
 	struct otx2_cq_queue *cq;
+	struct otx2_pool *pool;
 	struct msg_req *req;
+	int pool_id;
 	int qidx;
 
 	/* Ensure all SQE are processed */
@@ -1584,7 +1586,7 @@ static void otx2_free_hw_resources(struct otx2_nic *pf)
 	for (qidx = 0; qidx < qset->cq_cnt; qidx++) {
 		cq = &qset->cq[qidx];
 		if (cq->cq_type == CQ_RX)
-			otx2_cleanup_rx_cqes(pf, cq);
+			otx2_cleanup_rx_cqes(pf, cq, qidx);
 		else
 			otx2_cleanup_tx_cqes(pf, cq);
 	}
@@ -1594,6 +1596,13 @@ static void otx2_free_hw_resources(struct otx2_nic *pf)
 	/* Free RQ buffer pointers*/
 	otx2_free_aura_ptr(pf, AURA_NIX_RQ);
 
+	for (qidx = 0; qidx < pf->hw.rx_queues; qidx++) {
+		pool_id = otx2_get_pool_idx(pf, AURA_NIX_RQ, qidx);
+		pool = &pf->qset.pool[pool_id];
+		page_pool_destroy(pool->page_pool);
+		pool->page_pool = NULL;
+	}
+
 	otx2_free_cq_res(pf);
 
 	/* Free all ingress bandwidth profiles allocated */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +11 -8
index e288f46b23a8..37d4e4b73816 100644
@@ -217,9 +217,6 @@ static bool otx2_skb_add_frag(struct otx2_nic *pfvf, struct sk_buff *skb,
 		skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
 				va - page_address(page) + off,
 				len - off, pfvf->rbsize);
-
-		otx2_dma_unmap_page(pfvf, iova - OTX2_HEAD_ROOM,
-				    pfvf->rbsize, DMA_FROM_DEVICE);
 		return true;
 	}
 
@@ -382,6 +379,8 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
 	if (pfvf->netdev->features & NETIF_F_RXCSUM)
 		skb->ip_summed = CHECKSUM_UNNECESSARY;
 
+	skb_mark_for_recycle(skb);
+
 	napi_gro_frags(napi);
 }
 
@@ -1186,11 +1185,13 @@ bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq,
 }
 EXPORT_SYMBOL(otx2_sq_append_skb);
 
-void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
+void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq, int qidx)
 {
 	struct nix_cqe_rx_s *cqe;
 	int processed_cqe = 0;
-	u64 iova, pa;
+	struct otx2_pool *pool;
+	u16 pool_id;
+	u64 iova;
 
 	if (pfvf->xdp_prog)
 		xdp_rxq_info_unreg(&cq->xdp_rxq);
@@ -1198,6 +1199,9 @@ void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
 	if (otx2_nix_cq_op_status(pfvf, cq) || !cq->pend_cqe)
 		return;
 
+	pool_id = otx2_get_pool_idx(pfvf, AURA_NIX_RQ, qidx);
+	pool = &pfvf->qset.pool[pool_id];
+
 	while (cq->pend_cqe) {
 		cqe = (struct nix_cqe_rx_s *)otx2_get_next_cqe(cq);
 		processed_cqe++;
@@ -1210,9 +1214,8 @@ void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
 			continue;
 		}
 		iova = cqe->sg.seg_addr - OTX2_HEAD_ROOM;
-		pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
-		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize, DMA_FROM_DEVICE);
-		put_page(virt_to_page(phys_to_virt(pa)));
+
+		otx2_free_bufs(pfvf, pool, iova, pfvf->rbsize);
 	}
 
 	/* Free CQEs to HW */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +1 -0
index 7ab6db9a986f..b5d689eeff80 100644
@@ -118,6 +118,7 @@ struct otx2_cq_poll {
 struct otx2_pool {
 	struct qmem		*stack;
 	struct qmem		*fc_addr;
+	struct page_pool	*page_pool;
 	u16			rbsize;
 };
 
drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c +1 -1
index d96ed29c1567..9d887bfc3108 100644
@@ -63,7 +63,7 @@ static int otx2_qos_sq_aura_pool_init(struct otx2_nic *pfvf, int qidx)
 
 	/* Initialize pool context */
 	err = otx2_pool_init(pfvf, pool_id, stack_pages,
-			     num_sqbs, hw->sqb_size);
+			     num_sqbs, hw->sqb_size, AURA_NIX_SQ);
 	if (err)
 		goto aura_free;
 
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Ratheesh Kannoth

Page pool for each rx queue enhance rx side performance by reclaiming buffers back to each queue specific pool. DMA mapping is done only for first allocation of buffers. As subsequent buffers allocation avoid DMA mapping, it results in performance improvement.

Quoted 7 lines
Image        |  Performance
------------ | ------------
Vannila      |   3Mpps
             |
with this    |   42Mpps

change |
---------------------------

LGTM.

Quoted 3 lines

---

#2 lore raw
In reply to Ratheesh Kannoth
Quoted 15 lines · Ratheesh Kannoth

Page pool for each rx queue enhance rx side performance by reclaiming buffers back to each queue specific pool. DMA mapping is done only for first allocation of buffers. As subsequent buffers allocation avoid DMA mapping, it results in performance improvement.

Image        |  Performance
------------ | ------------
Vannila      |   3Mpps
             |
with this    |   42Mpps

change |
---------------------------

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1233

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +5 -0
@@ -1205,10 +1226,28 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
 	}
 }
 
+void otx2_free_bufs(struct otx2_nic *pfvf, struct otx2_pool *pool,
+		    u64 iova, int size)
+{
+	u64 pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
+	struct page *page = virt_to_head_page(phys_to_virt(pa));

nit: please arrange local variables in networking code in reverse xmas tree

     order - longest line to shortest.

	u64 pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
	struct page *page;

	page = virt_to_head_page(phys_to_virt(pa));

     The following tool can check this:

        https://github.com/ecree-solarflare/xmastree

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq, · line 1194

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +4 -2
@@ -1186,11 +1185,13 @@ bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq,
 }
 EXPORT_SYMBOL(otx2_sq_append_skb);
 
-void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
+void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq, int qidx)
 {
 	struct nix_cqe_rx_s *cqe;
 	int processed_cqe = 0;
-	u64 iova, pa;
+	struct otx2_pool *pool;
+	u16 pool_id;
+	u64 iova;

Likewise here.

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
 	if (pfvf->xdp_prog)
 		xdp_rxq_info_unreg(&cq->xdp_rxq);

...

author maintainer
#3 lore raw
Quoted 41 lines

-----Original Message-----
From: Simon Horman <[email protected]>
Sent: Friday, May 19, 2023 3:33 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Subbaraya Sundeep Bhatta <[email protected]>; Geethasowjanya Akula <[email protected]>; Srujana Challa <[email protected]>; Hariprasad Kelam <[email protected]>
Subject: [EXT] Re: [PATCH net-next v3] octeontx2-pf: Add support for page pool

External Email

----------------------------------------------------------------------

Quoted 15 lines · Ratheesh Kannoth

Page pool for each rx queue enhance rx side performance by reclaiming buffers back to each queue specific pool. DMA mapping is done only for first allocation of buffers.
As subsequent buffers allocation avoid DMA mapping, it results in performance improvement.

Image        |  Performance
------------ | ------------
Vannila      |   3Mpps
             |
with this    |   42Mpps

change |
---------------------------

...

Quoted 4 lines
(quoted diff) +0 -0
@@ -1205,10 +1226,28 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
 	}
 }
 
Quoted 8 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1233

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +5 -0
+void otx2_free_bufs(struct otx2_nic *pfvf, struct otx2_pool *pool,
+		    u64 iova, int size)
+{
+	u64 pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
+	struct page *page = virt_to_head_page(phys_to_virt(pa));

nit: please arrange local variables in networking code in reverse xmas tree
order - longest line to shortest.

Variable "pa" is used in second line. Are you suggesting to defer assignment later; and only declare variables here in reverse xmas tree style ?

Quoted 21 lines
	u64 pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
	struct page *page;

	page = virt_to_head_page(phys_to_virt(pa));

     The following tool can check this:

        https://urldefense.proofpoint.com/v2/url?u=https-

3A__github.com_ecree- 2Dsolarflare_xmastree&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=aekcsy BCH00_LewrEDcQBzsRw8KCpUR0vZb_auTHk4M&m=EAM7f8UtMNRC57jfDp gqNsIClttVw6HHyCL7XecFBync-LgDwxIm9_45n-w- WvjY&s=x_0EQ5wG1cZv01ySk_vzRX3kc8Bd2OALcpI8NgxYXTI&e=

...

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
@@ -1186,11 +1185,13 @@ bool otx2_sq_append_skb(struct net_device
 *netdev, struct otx2_snd_queue *sq,  }
 EXPORT_SYMBOL(otx2_sq_append_skb);
 
Quoted 13 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq, · line 1194

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +5 -2
-void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue
 *cq)
+void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue
+*cq, int qidx)
 {
 	struct nix_cqe_rx_s *cqe;
 	int processed_cqe = 0;
-	u64 iova, pa;
+	struct otx2_pool *pool;
+	u16 pool_id;
+	u64 iova;

Likewise here.

Okay

Quoted 5 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq, · line 1197

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
 	if (pfvf->xdp_prog)
 		xdp_rxq_info_unreg(&cq->xdp_rxq);

-Ratheesh

#4 lore raw
Quoted 49 lines · Ratheesh Kannoth
Quoted 41 lines

-----Original Message-----
From: Simon Horman <[email protected]>
Sent: Friday, May 19, 2023 3:33 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Subbaraya Sundeep Bhatta <[email protected]>; Geethasowjanya Akula <[email protected]>; Srujana Challa <[email protected]>; Hariprasad Kelam <[email protected]>
Subject: [EXT] Re: [PATCH net-next v3] octeontx2-pf: Add support for page pool

External Email

----------------------------------------------------------------------

Quoted 15 lines · Ratheesh Kannoth

Page pool for each rx queue enhance rx side performance by reclaiming buffers back to each queue specific pool. DMA mapping is done only for first allocation of buffers.
As subsequent buffers allocation avoid DMA mapping, it results in performance improvement.

Image        |  Performance
------------ | ------------
Vannila      |   3Mpps
             |
with this    |   42Mpps

change |
---------------------------

...

Quoted 4 lines
(quoted diff) +0 -0
@@ -1205,10 +1226,28 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
 	}
 }
 
Quoted 8 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1233

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +5 -0
+void otx2_free_bufs(struct otx2_nic *pfvf, struct otx2_pool *pool,
+		    u64 iova, int size)
+{
+	u64 pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
+	struct page *page = virt_to_head_page(phys_to_virt(pa));

nit: please arrange local variables in networking code in reverse xmas tree
order - longest line to shortest.

Quoted 1 line

Variable "pa" is used in second line. Are you suggesting to defer assignment later; and only declare variables here in reverse xmas tree style ?

Yes, that is my suggestion.