From patchwork Fri Jul 29 22:44:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirley Ma X-Patchwork-Id: 1021902 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6TMiZYD017540 for ; Fri, 29 Jul 2011 22:44:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752829Ab1G2WoR (ORCPT ); Fri, 29 Jul 2011 18:44:17 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:48367 "EHLO e39.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752193Ab1G2WoQ (ORCPT ); Fri, 29 Jul 2011 18:44:16 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e39.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p6TMTJE1024653; Fri, 29 Jul 2011 16:29:20 -0600 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6TMiCXA116436; Fri, 29 Jul 2011 16:44:12 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6TGiAKs013150; Fri, 29 Jul 2011 10:44:11 -0600 Received: from [9.65.234.110] (sig-9-65-234-110.mts.ibm.com [9.65.234.110]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p6TGi9Gs013111; Fri, 29 Jul 2011 10:44:09 -0600 Subject: [PATCH RFC net-next] virtio_net: refill buffer right after being used From: Shirley Ma To: Rusty Russell , mst@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.osdl.org, netdev@vger.kernel.org Date: Fri, 29 Jul 2011 15:44:08 -0700 Message-ID: <1311979448.24300.28.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-1.fc12) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 29 Jul 2011 22:44:35 +0000 (UTC) To even the latency, refill buffer right after being used. Sign-off-by: Shirley Ma --- -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0c7321c..c8201d4 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -429,6 +429,22 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, gfp_t gfp) return err; } +static bool fill_one(struct virtio_net *vi, gfp_t gfp) +{ + int err; + + if (vi->mergeable_rx_bufs) + err = add_recvbuf_mergeable(vi, gfp); + else if (vi->big_packets) + err = add_recvbuf_big(vi, gfp); + else + err = add_recvbuf_small(vi, gfp); + + if (err >= 0) + ++vi->num; + return err; +} + /* Returns false if we couldn't fill entirely (OOM). */ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp) { @@ -436,17 +452,10 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp) bool oom; do { - if (vi->mergeable_rx_bufs) - err = add_recvbuf_mergeable(vi, gfp); - else if (vi->big_packets) - err = add_recvbuf_big(vi, gfp); - else - err = add_recvbuf_small(vi, gfp); - + err = fill_one(vi, gfp); oom = err == -ENOMEM; if (err < 0) break; - ++vi->num; } while (err > 0); if (unlikely(vi->num > vi->max)) vi->max = vi->num; @@ -506,13 +515,13 @@ again: receive_buf(vi->dev, buf, len); --vi->num; received++; - } - - if (vi->num < vi->max / 2) { - if (!try_fill_recv(vi, GFP_ATOMIC)) + if (fill_one(vi, GFP_ATOMIC) < 0) schedule_delayed_work(&vi->refill, 0); } + /* notify buffers are refilled */ + virtqueue_kick(vi->rvq); + /* Out of packets? */ if (received < budget) { napi_complete(napi);