From patchwork Thu Oct 22 05:27:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 7462461 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 62DF49FC36 for ; Thu, 22 Oct 2015 05:28:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9066B2053D for ; Thu, 22 Oct 2015 05:28:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA23E208D0 for ; Thu, 22 Oct 2015 05:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756276AbbJVF2H (ORCPT ); Thu, 22 Oct 2015 01:28:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58371 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751161AbbJVF1m (ORCPT ); Thu, 22 Oct 2015 01:27:42 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 5913A8C1C0; Thu, 22 Oct 2015 05:27:42 +0000 (UTC) Received: from hp-dl380pg8-02.qe.lab.eng.nay.redhat.com (hp-dl380pg8-02.qe.lab.eng.nay.redhat.com [10.66.106.69]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9M5RWiv001050; Thu, 22 Oct 2015 01:27:39 -0400 From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jason Wang Subject: [PATCH net-next RFC 2/2] vhost_net: basic polling support Date: Thu, 22 Oct 2015 01:27:29 -0400 Message-Id: <1445491649-62614-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1445491649-62614-1-git-send-email-jasowang@redhat.com> References: <1445491649-62614-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch tries to poll for new added tx buffer for a while at the end of tx processing. The maximum time spent on polling were limited through a module parameter. To avoid block rx, the loop will end it there's new other works queued on vhost so in fact socket receive queue is also be polled. busyloop_timeout = 50 gives us following improvement on TCP_RR test: size/session/+thu%/+normalize% 1/ 1/ +5%/ -20% 1/ 50/ +17%/ +3% Signed-off-by: Jason Wang --- drivers/vhost/net.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 9eda69e..bbb522a 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -31,7 +31,9 @@ #include "vhost.h" static int experimental_zcopytx = 1; +static int busyloop_timeout = 50; module_param(experimental_zcopytx, int, 0444); +module_param(busyloop_timeout, int, 0444); MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;" " 1 -Enable; 0 - Disable"); @@ -287,12 +289,23 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success) rcu_read_unlock_bh(); } +static bool tx_can_busy_poll(struct vhost_dev *dev, + unsigned long endtime) +{ + unsigned long now = local_clock() >> 10; + + return busyloop_timeout && !need_resched() && + !time_after(now, endtime) && !vhost_has_work(dev) && + single_task_running(); +} + /* Expects to be always run from workqueue - which acts as * read-size critical section for our kind of RCU. */ static void handle_tx(struct vhost_net *net) { struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX]; struct vhost_virtqueue *vq = &nvq->vq; + unsigned long endtime; unsigned out, in; int head; struct msghdr msg = { @@ -331,6 +344,8 @@ static void handle_tx(struct vhost_net *net) % UIO_MAXIOV == nvq->done_idx)) break; + endtime = (local_clock() >> 10) + busyloop_timeout; +again: head = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov), &out, &in, @@ -340,6 +355,10 @@ static void handle_tx(struct vhost_net *net) break; /* Nothing new? Wait for eventfd to tell us they refilled. */ if (head == vq->num) { + if (tx_can_busy_poll(vq->dev, endtime)) { + cpu_relax(); + goto again; + } if (unlikely(vhost_enable_notify(&net->dev, vq))) { vhost_disable_notify(&net->dev, vq); continue;