Netdev List
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: netdev@vger.kernel.org, brouer@redhat.com, davem@davemloft.net,
	lorenzo.bianconi@redhat.com
Subject: Re: [RFC/RFT net-next] net: socionext: get rid of huge dma sync in netsec_alloc_rx_data
Date: Tue, 7 Jan 2020 15:53:13 +0200	[thread overview]
Message-ID: <20200107135313.GA121856@apalos.home> (raw)
In-Reply-To: <20094a678ea3d76fc1b8817ae0dd6d136cdc3860.1578225300.git.lorenzo@kernel.org>

Hi Lorenzo, 

Although the box using thei NIC usually runs with coherent DMA, there's a
configuration that disables that. So having this is has some meaning.
Minor comments below.

On Sun, Jan 05, 2020 at 12:57:56PM +0100, Lorenzo Bianconi wrote:
> Socionext driver can run on dma coherent and non-coherent devices.
> Get rid of huge dma_sync_single_for_device in netsec_alloc_rx_data since
> now the driver can let page_pool API to managed needed DMA sync
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/socionext/netsec.c | 60 ++++++++++++++-----------
>  1 file changed, 33 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c
> index b5a9e947a4a8..7a2eb0e71d2a 100644
> --- a/drivers/net/ethernet/socionext/netsec.c
> +++ b/drivers/net/ethernet/socionext/netsec.c
> @@ -243,6 +243,7 @@
>  			       NET_IP_ALIGN)
>  #define NETSEC_RX_BUF_NON_DATA (NETSEC_RXBUF_HEADROOM + \
>  				SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
> +#define NETSEC_RX_BUF_SIZE	(PAGE_SIZE - NETSEC_RX_BUF_NON_DATA)
>  
>  #define DESC_SZ	sizeof(struct netsec_de)
>  
> @@ -714,12 +715,11 @@ static void netsec_process_tx(struct netsec_priv *priv)
>  }
>  
>  static void *netsec_alloc_rx_data(struct netsec_priv *priv,
> -				  dma_addr_t *dma_handle, u16 *desc_len)

i'd prefer having this function fill in the size, insetad of defining it every
time we refill the descriptors
You can keep the new define for PAGE_SIZE - NETSEC_RX_BUF_NON_DATA, it looks
cleaner

> +				  dma_addr_t *dma_handle)
>  
>  {
>  
>  	struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
> -	enum dma_data_direction dma_dir;
>  	struct page *page;
>  
>  	page = page_pool_dev_alloc_pages(dring->page_pool);
> @@ -734,10 +734,6 @@ static void *netsec_alloc_rx_data(struct netsec_priv *priv,
>  	/* Make sure the incoming payload fits in the page for XDP and non-XDP
>  	 * cases and reserve enough space for headroom + skb_shared_info
>  	 */
> -	*desc_len = PAGE_SIZE - NETSEC_RX_BUF_NON_DATA;
> -	dma_dir = page_pool_get_dma_dir(dring->page_pool);
> -	dma_sync_single_for_device(priv->dev, *dma_handle, *desc_len, dma_dir);
> -
>  	return page_address(page);
>  }
>  
> @@ -883,6 +879,7 @@ static u32 netsec_xdp_xmit_back(struct netsec_priv *priv, struct xdp_buff *xdp)
>  static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
>  			  struct xdp_buff *xdp)
>  {
> +	struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
>  	u32 ret = NETSEC_XDP_PASS;
>  	int err;
>  	u32 act;
> @@ -896,7 +893,10 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
>  	case XDP_TX:
>  		ret = netsec_xdp_xmit_back(priv, xdp);
>  		if (ret != NETSEC_XDP_TX)
> -			xdp_return_buff(xdp);
> +			__page_pool_put_page(dring->page_pool,
> +				     virt_to_head_page(xdp->data),
> +				     xdp->data_end - xdp->data_hard_start,
> +				     true);
>  		break;
>  	case XDP_REDIRECT:
>  		err = xdp_do_redirect(priv->ndev, xdp, prog);
> @@ -904,7 +904,10 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
>  			ret = NETSEC_XDP_REDIR;
>  		} else {
>  			ret = NETSEC_XDP_CONSUMED;
> -			xdp_return_buff(xdp);
> +			__page_pool_put_page(dring->page_pool,
> +				     virt_to_head_page(xdp->data),
> +				     xdp->data_end - xdp->data_hard_start,
> +				     true);
>  		}
>  		break;
>  	default:
> @@ -915,7 +918,10 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
>  		/* fall through -- handle aborts by dropping packet */
>  	case XDP_DROP:
>  		ret = NETSEC_XDP_CONSUMED;
> -		xdp_return_buff(xdp);
> +		__page_pool_put_page(dring->page_pool,
> +				     virt_to_head_page(xdp->data),
> +				     xdp->data_end - xdp->data_hard_start,
> +				     true);
>  		break;
>  	}
>  
> @@ -944,10 +950,10 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
>  		struct netsec_desc *desc = &dring->desc[idx];
>  		struct page *page = virt_to_page(desc->addr);
>  		u32 xdp_result = XDP_PASS;
> -		u16 pkt_len, desc_len;
>  		dma_addr_t dma_handle;
>  		struct xdp_buff xdp;
>  		void *buf_addr;
> +		u16 pkt_len;
>  
>  		if (de->attr & (1U << NETSEC_RX_PKT_OWN_FIELD)) {
>  			/* reading the register clears the irq */
> @@ -982,8 +988,7 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
>  		/* allocate a fresh buffer and map it to the hardware.
>  		 * This will eventually replace the old buffer in the hardware
>  		 */
> -		buf_addr = netsec_alloc_rx_data(priv, &dma_handle, &desc_len);
> -
> +		buf_addr = netsec_alloc_rx_data(priv, &dma_handle);
>  		if (unlikely(!buf_addr))
>  			break;
>  
> @@ -1014,7 +1019,8 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
>  			 * cache state. Since we paid the allocation cost if
>  			 * building an skb fails try to put the page into cache
>  			 */
> -			page_pool_recycle_direct(dring->page_pool, page);
> +			__page_pool_put_page(dring->page_pool, page,
> +					     desc->len, true);
>  			netif_err(priv, drv, priv->ndev,
>  				  "rx failed to build skb\n");
>  			break;
> @@ -1037,7 +1043,7 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
>  		}
>  
>  		/* Update the descriptor with fresh buffers */
> -		desc->len = desc_len;
> +		desc->len = NETSEC_RX_BUF_SIZE;

Similar comment here, i'd prefer having a sinlge fucntion calculate the length.

>  		desc->dma_addr = dma_handle;
>  		desc->addr = buf_addr;
>  
> @@ -1272,17 +1278,19 @@ static int netsec_setup_rx_dring(struct netsec_priv *priv)
>  {
>  	struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
>  	struct bpf_prog *xdp_prog = READ_ONCE(priv->xdp_prog);
> -	struct page_pool_params pp_params = { 0 };
> +	struct page_pool_params pp_params = {
> +		.order = 0,
> +		/* internal DMA mapping in page_pool */
> +		.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
> +		.pool_size = DESC_NUM,
> +		.nid = NUMA_NO_NODE,
> +		.dev = priv->dev,
> +		.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
> +		.offset = NETSEC_RXBUF_HEADROOM,
> +		.max_len = NETSEC_RX_BUF_SIZE,
> +	};
>  	int i, err;
>  
> -	pp_params.order = 0;
> -	/* internal DMA mapping in page_pool */
> -	pp_params.flags = PP_FLAG_DMA_MAP;
> -	pp_params.pool_size = DESC_NUM;
> -	pp_params.nid = NUMA_NO_NODE;
> -	pp_params.dev = priv->dev;
> -	pp_params.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
> -
>  	dring->page_pool = page_pool_create(&pp_params);
>  	if (IS_ERR(dring->page_pool)) {
>  		err = PTR_ERR(dring->page_pool);
> @@ -1303,17 +1311,15 @@ static int netsec_setup_rx_dring(struct netsec_priv *priv)
>  		struct netsec_desc *desc = &dring->desc[i];
>  		dma_addr_t dma_handle;
>  		void *buf;
> -		u16 len;
> -
> -		buf = netsec_alloc_rx_data(priv, &dma_handle, &len);
>  
> +		buf = netsec_alloc_rx_data(priv, &dma_handle);
>  		if (!buf) {
>  			err = -ENOMEM;
>  			goto err_out;
>  		}
> +		desc->len = NETSEC_RX_BUF_SIZE;
>  		desc->dma_addr = dma_handle;
>  		desc->addr = buf;
> -		desc->len = len;
>  	}
>  
>  	netsec_rx_fill(priv, 0, DESC_NUM);
> -- 
> 2.21.1
> 

Other than that this looks good, re-send it as a non RFC patch and i can test it


Thanks!
/Ilias

      reply	other threads:[~2020-01-07 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-05 11:57 [RFC/RFT net-next] net: socionext: get rid of huge dma sync in netsec_alloc_rx_data Lorenzo Bianconi
2020-01-07 13:53 ` Ilias Apalodimas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200107135313.GA121856@apalos.home \
    --to=ilias.apalodimas@linaro.org \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox