From patchwork Sat Jul 21 18:04:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 947405 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Wudr6W50"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41XwfG1LlTz9s29 for ; Sun, 22 Jul 2018 04:05:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728418AbeGUS7O (ORCPT ); Sat, 21 Jul 2018 14:59:14 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39893 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbeGUS7O (ORCPT ); Sat, 21 Jul 2018 14:59:14 -0400 Received: by mail-pg1-f193.google.com with SMTP id g2-v6so9344627pgs.6 for ; Sat, 21 Jul 2018 11:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xwCfOzA8GWxUM/VcWZ//sLoLyZDT3gUi7utdPfd7H+8=; b=Wudr6W50VP7R3O4L5wAw7Vs9IAGIIYX8qV2tx3fLt71F0nE2kNIUGuST0ODmbfQv2o rm4yI24hiJHCRmDHzxeQ+2e/DmsCa66Dp1FSOSv2zFYI5bUFUsLrm0bD/9svv7SEkXdu yciZmNgFmn8JvlaAb74Mwxpz3fILFK02J3TE773FbVchst4sWRQnpMZ9zexbv8ywJsWT TakUHGl0CAn5VowhQZhjTAoEsJhewLquXpEnkA4vaRGA2nPOipm+8VxcuGRlu/dDewaQ xaTMjfxxjA5XMSlJErFxY6d0pXyptUhmF68dNwnnkiq67AXePjbsY7mUtvOMSr/HYwI6 auXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xwCfOzA8GWxUM/VcWZ//sLoLyZDT3gUi7utdPfd7H+8=; b=AkD3uJqiA1/suVDEuCzGyrL4XIVMFFRusdwY4pnYYpSKA79IRtJJZOm/2X8/RJKjN3 YaOq7CwrQgF4hw8MQCOJAFo8BajaqUKmDfph5cE47MUXcuA9h3SijbUNjGqoQVYrkaHF ZNQtL8GiZ8lPOqV41yiEqrAa6aBN/IRFlt/0QyW/XPiaWP/i6PzUGPgLRLtVv6oT5hvH hz+68ccjtce0rPc4CUbjzB7jM9wQelonHtGJN+5R8F97Qbrex53aHGu9wCuMeFKlKZtM 3P14RdpVg44wSiQ6ogOPAILm/e7JOI7jiv/3cYCIEQZV0UAre8LGq4RCrVddovFv6Ggx 0Zfg== X-Gm-Message-State: AOUpUlGIoUvB0Jlslgdd5UqGOr7aaQiKjxKOfnXWdTTfS7dlfPVM+phE +SU3+lQu+OgGsK9HxVkPFWA= X-Google-Smtp-Source: AAOMgpex8H2MOgwd0WrnJR+hWrO95F8bXCcTA9L6l15IaYbm4HcmAYwb96TPAFv1Np8I7MtsQtumqQ== X-Received: by 2002:a62:198e:: with SMTP id 136-v6mr6852983pfz.103.1532196339897; Sat, 21 Jul 2018 11:05:39 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([36.102.208.98]) by smtp.gmail.com with ESMTPSA id l71-v6sm7063679pgd.70.2018.07.21.11.05.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 11:05:39 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: jasowang@redhat.com Cc: mst@redhat.com, makita.toshiaki@lab.ntt.co.jp, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, Tonghao Zhang Subject: [PATCH net-next v6 4/4] net: vhost: add rx busy polling in tx path Date: Sat, 21 Jul 2018 11:04:02 -0700 Message-Id: <1532196242-2998-5-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1532196242-2998-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1532196242-2998-1-git-send-email-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang This patch improves the guest receive performance. On the handle_tx side, we poll the sock receive queue at the same time. handle_rx do that in the same way. We set the poll-us=100us and use the netperf to test throughput and mean latency. When running the tests, the vhost-net kthread of that VM, is alway 100% CPU. The commands are shown as below. Rx performance is greatly improved by this patch. There is not notable performance change on tx with this series though. This patch is useful for bi-directional traffic. netperf -H IP -t TCP_STREAM -l 20 -- -O "THROUGHPUT, THROUGHPUT_UNITS, MEAN_LATENCY" Topology: [Host] ->linux bridge -> tap vhost-net ->[Guest] TCP_STREAM: * Without the patch: 19842.95 Mbps, 6.50 us mean latency * With the patch: 37373.10 Mbps, 3.43 us mean latency Signed-off-by: Tonghao Zhang --- drivers/vhost/net.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 2dc937e..a562828 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -501,29 +501,21 @@ static void vhost_net_busy_poll(struct vhost_net *net, } static int vhost_net_tx_get_vq_desc(struct vhost_net *net, - struct vhost_virtqueue *vq, + struct vhost_virtqueue *tvq, struct iovec iov[], unsigned int iov_size, unsigned int *out_num, unsigned int *in_num, bool *busyloop_intr) { - unsigned long uninitialized_var(endtime); - int r = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov), - out_num, in_num, NULL, NULL); - - if (r == vq->num && vq->busyloop_timeout) { - preempt_disable(); - endtime = busy_clock() + vq->busyloop_timeout; - while (vhost_can_busy_poll(endtime)) { - if (vhost_has_work(vq->dev)) { - *busyloop_intr = true; - break; - } - if (!vhost_vq_avail_empty(vq->dev, vq)) - break; - cpu_relax(); - } - preempt_enable(); - r = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov), + struct vhost_net_virtqueue *rnvq = &net->vqs[VHOST_NET_VQ_RX]; + struct vhost_virtqueue *rvq = &rnvq->vq; + + int r = vhost_get_vq_desc(tvq, tvq->iov, ARRAY_SIZE(tvq->iov), + out_num, in_num, NULL, NULL); + + if (r == tvq->num && tvq->busyloop_timeout) { + vhost_net_busy_poll(net, rvq, tvq, busyloop_intr, false); + + r = vhost_get_vq_desc(tvq, tvq->iov, ARRAY_SIZE(tvq->iov), out_num, in_num, NULL, NULL); }