Re: [net PATCH v5 4/6] virtio_net: remove duplicate queue pair binding in XDP

2017-01-18 Thread Michael S. Tsirkin
On Tue, Jan 17, 2017 at 02:21:44PM -0800, John Fastabend wrote:
> Factor out qp assignment.
> 
> Signed-off-by: John Fastabend 

Acked-by: Michael S. Tsirkin 

> ---
>  drivers/net/virtio_net.c |   18 +++---
>  1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 6de0cbe..922ca66 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -332,15 +332,19 @@ static struct sk_buff *page_to_skb(struct virtnet_info 
> *vi,
>  
>  static void virtnet_xdp_xmit(struct virtnet_info *vi,
>struct receive_queue *rq,
> -  struct send_queue *sq,
>struct xdp_buff *xdp,
>void *data)
>  {
>   struct virtio_net_hdr_mrg_rxbuf *hdr;
>   unsigned int num_sg, len;
> + struct send_queue *sq;
> + unsigned int qp;
>   void *xdp_sent;
>   int err;
>  
> + qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id();
> + sq = &vi->sq[qp];
> +
>   /* Free up any pending old buffers before queueing new ones. */
>   while ((xdp_sent = virtqueue_get_buf(sq->vq, &len)) != NULL) {
>   if (vi->mergeable_rx_bufs) {
> @@ -404,7 +408,6 @@ static struct sk_buff *receive_small(struct net_device 
> *dev,
>   if (xdp_prog) {
>   struct virtio_net_hdr_mrg_rxbuf *hdr = buf;
>   struct xdp_buff xdp;
> - unsigned int qp;
>   u32 act;
>  
>   if (unlikely(hdr->hdr.gso_type || hdr->hdr.flags))
> @@ -417,10 +420,7 @@ static struct sk_buff *receive_small(struct net_device 
> *dev,
>   case XDP_PASS:
>   break;
>   case XDP_TX:
> - qp = vi->curr_queue_pairs -
> - vi->xdp_queue_pairs +
> - smp_processor_id();
> - virtnet_xdp_xmit(vi, rq, &vi->sq[qp], &xdp, skb);
> + virtnet_xdp_xmit(vi, rq, &xdp, skb);
>   rcu_read_unlock();
>   goto xdp_xmit;
>   default:
> @@ -545,7 +545,6 @@ static struct sk_buff *receive_mergeable(struct 
> net_device *dev,
>   if (xdp_prog) {
>   struct page *xdp_page;
>   struct xdp_buff xdp;
> - unsigned int qp;
>   void *data;
>   u32 act;
>  
> @@ -586,10 +585,7 @@ static struct sk_buff *receive_mergeable(struct 
> net_device *dev,
>   }
>   break;
>   case XDP_TX:
> - qp = vi->curr_queue_pairs -
> - vi->xdp_queue_pairs +
> - smp_processor_id();
> - virtnet_xdp_xmit(vi, rq, &vi->sq[qp], &xdp, data);
> + virtnet_xdp_xmit(vi, rq, &xdp, data);
>   ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
>   if (unlikely(xdp_page != page))
>   goto err_xdp;


[net PATCH v5 4/6] virtio_net: remove duplicate queue pair binding in XDP

2017-01-17 Thread John Fastabend
Factor out qp assignment.

Signed-off-by: John Fastabend 
---
 drivers/net/virtio_net.c |   18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 6de0cbe..922ca66 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -332,15 +332,19 @@ static struct sk_buff *page_to_skb(struct virtnet_info 
*vi,
 
 static void virtnet_xdp_xmit(struct virtnet_info *vi,
 struct receive_queue *rq,
-struct send_queue *sq,
 struct xdp_buff *xdp,
 void *data)
 {
struct virtio_net_hdr_mrg_rxbuf *hdr;
unsigned int num_sg, len;
+   struct send_queue *sq;
+   unsigned int qp;
void *xdp_sent;
int err;
 
+   qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id();
+   sq = &vi->sq[qp];
+
/* Free up any pending old buffers before queueing new ones. */
while ((xdp_sent = virtqueue_get_buf(sq->vq, &len)) != NULL) {
if (vi->mergeable_rx_bufs) {
@@ -404,7 +408,6 @@ static struct sk_buff *receive_small(struct net_device *dev,
if (xdp_prog) {
struct virtio_net_hdr_mrg_rxbuf *hdr = buf;
struct xdp_buff xdp;
-   unsigned int qp;
u32 act;
 
if (unlikely(hdr->hdr.gso_type || hdr->hdr.flags))
@@ -417,10 +420,7 @@ static struct sk_buff *receive_small(struct net_device 
*dev,
case XDP_PASS:
break;
case XDP_TX:
-   qp = vi->curr_queue_pairs -
-   vi->xdp_queue_pairs +
-   smp_processor_id();
-   virtnet_xdp_xmit(vi, rq, &vi->sq[qp], &xdp, skb);
+   virtnet_xdp_xmit(vi, rq, &xdp, skb);
rcu_read_unlock();
goto xdp_xmit;
default:
@@ -545,7 +545,6 @@ static struct sk_buff *receive_mergeable(struct net_device 
*dev,
if (xdp_prog) {
struct page *xdp_page;
struct xdp_buff xdp;
-   unsigned int qp;
void *data;
u32 act;
 
@@ -586,10 +585,7 @@ static struct sk_buff *receive_mergeable(struct net_device 
*dev,
}
break;
case XDP_TX:
-   qp = vi->curr_queue_pairs -
-   vi->xdp_queue_pairs +
-   smp_processor_id();
-   virtnet_xdp_xmit(vi, rq, &vi->sq[qp], &xdp, data);
+   virtnet_xdp_xmit(vi, rq, &xdp, data);
ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
if (unlikely(xdp_page != page))
goto err_xdp;