diff options
author | Jason Wang <jasowang@redhat.com> | 2014-01-16 01:45:24 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-16 20:30:42 -0500 |
commit | be121f46affce8a2ba284ef0388a8ff6ff85ec1b (patch) | |
tree | ac9a515a86987e519a8dc26ae33e06c4ee6bf525 /drivers/net/virtio_net.c | |
parent | 9b05f462b78852fcb2b0508148a855d47c6e5c02 (diff) |
virtio-net: drop rq->max and rq->num
It looks like there's no need for those two fields:
- Unless there's a failure for the first refill try, rq->max should be always
equal to the vring size.
- rq->num is only used to determine the condition that we need to do the refill,
we could check vq->num_free instead.
- rq->num was required to be increased or decreased explicitly after each
get/put which results a bad API.
So this patch removes them both to make the code simpler.
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/virtio_net.c')
-rw-r--r-- | drivers/net/virtio_net.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7b172408cff0..9bd70aa87bf7 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -72,9 +72,6 @@ struct receive_queue { | |||
72 | 72 | ||
73 | struct napi_struct napi; | 73 | struct napi_struct napi; |
74 | 74 | ||
75 | /* Number of input buffers, and max we've ever had. */ | ||
76 | unsigned int num, max; | ||
77 | |||
78 | /* Chain pages by the private ptr. */ | 75 | /* Chain pages by the private ptr. */ |
79 | struct page *pages; | 76 | struct page *pages; |
80 | 77 | ||
@@ -360,7 +357,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, | |||
360 | } | 357 | } |
361 | 358 | ||
362 | page = virt_to_head_page(buf); | 359 | page = virt_to_head_page(buf); |
363 | --rq->num; | ||
364 | 360 | ||
365 | num_skb_frags = skb_shinfo(curr_skb)->nr_frags; | 361 | num_skb_frags = skb_shinfo(curr_skb)->nr_frags; |
366 | if (unlikely(num_skb_frags == MAX_SKB_FRAGS)) { | 362 | if (unlikely(num_skb_frags == MAX_SKB_FRAGS)) { |
@@ -406,7 +402,6 @@ err_skb: | |||
406 | } | 402 | } |
407 | page = virt_to_head_page(buf); | 403 | page = virt_to_head_page(buf); |
408 | put_page(page); | 404 | put_page(page); |
409 | --rq->num; | ||
410 | } | 405 | } |
411 | err_buf: | 406 | err_buf: |
412 | dev->stats.rx_dropped++; | 407 | dev->stats.rx_dropped++; |
@@ -628,10 +623,7 @@ static bool try_fill_recv(struct receive_queue *rq, gfp_t gfp) | |||
628 | oom = err == -ENOMEM; | 623 | oom = err == -ENOMEM; |
629 | if (err) | 624 | if (err) |
630 | break; | 625 | break; |
631 | ++rq->num; | ||
632 | } while (rq->vq->num_free); | 626 | } while (rq->vq->num_free); |
633 | if (unlikely(rq->num > rq->max)) | ||
634 | rq->max = rq->num; | ||
635 | if (unlikely(!virtqueue_kick(rq->vq))) | 627 | if (unlikely(!virtqueue_kick(rq->vq))) |
636 | return false; | 628 | return false; |
637 | return !oom; | 629 | return !oom; |
@@ -699,11 +691,10 @@ again: | |||
699 | while (received < budget && | 691 | while (received < budget && |
700 | (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { | 692 | (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { |
701 | receive_buf(rq, buf, len); | 693 | receive_buf(rq, buf, len); |
702 | --rq->num; | ||
703 | received++; | 694 | received++; |
704 | } | 695 | } |
705 | 696 | ||
706 | if (rq->num < rq->max / 2) { | 697 | if (rq->vq->num_free > virtqueue_get_vring_size(rq->vq) / 2) { |
707 | if (!try_fill_recv(rq, GFP_ATOMIC)) | 698 | if (!try_fill_recv(rq, GFP_ATOMIC)) |
708 | schedule_delayed_work(&vi->refill, 0); | 699 | schedule_delayed_work(&vi->refill, 0); |
709 | } | 700 | } |
@@ -1398,9 +1389,7 @@ static void free_unused_bufs(struct virtnet_info *vi) | |||
1398 | give_pages(&vi->rq[i], buf); | 1389 | give_pages(&vi->rq[i], buf); |
1399 | else | 1390 | else |
1400 | dev_kfree_skb(buf); | 1391 | dev_kfree_skb(buf); |
1401 | --vi->rq[i].num; | ||
1402 | } | 1392 | } |
1403 | BUG_ON(vi->rq[i].num != 0); | ||
1404 | } | 1393 | } |
1405 | } | 1394 | } |
1406 | 1395 | ||
@@ -1671,7 +1660,8 @@ static int virtnet_probe(struct virtio_device *vdev) | |||
1671 | try_fill_recv(&vi->rq[i], GFP_KERNEL); | 1660 | try_fill_recv(&vi->rq[i], GFP_KERNEL); |
1672 | 1661 | ||
1673 | /* If we didn't even get one input buffer, we're useless. */ | 1662 | /* If we didn't even get one input buffer, we're useless. */ |
1674 | if (vi->rq[i].num == 0) { | 1663 | if (vi->rq[i].vq->num_free == |
1664 | virtqueue_get_vring_size(vi->rq[i].vq)) { | ||
1675 | free_unused_bufs(vi); | 1665 | free_unused_bufs(vi); |
1676 | err = -ENOMEM; | 1666 | err = -ENOMEM; |
1677 | goto free_recv_bufs; | 1667 | goto free_recv_bufs; |