Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp55100imm; Mon, 21 May 2018 02:05:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZocQ0trvwuU2jN9FIp9iCmS1TZem2Lgx773aigkkYAmM9RZnvXkA9vkSJ9j78q6gXsdXVEF X-Received: by 2002:a17:902:164:: with SMTP id 91-v6mr19833308plb.134.1526893525107; Mon, 21 May 2018 02:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526893525; cv=none; d=google.com; s=arc-20160816; b=jZRyAqr1s5KtOQ+UI6V6/iYVbLvS2Jxi06fpTz+QO3OkKETDELBIEMu3G5iaOhNOIx 1vI3LoXwbBVLD+rLZ7jpJqoF/98iUvu0YxQwBVtbzjslSSQKviMhDJQYzRN7jQp+alUh 7VL3BSsHurEwvHVJECxe28OLU/XMGSfwB5Zp+84qKT7qtwo7l8W4Az2ABaORbRjzkkDI pdKOM/oslRnP72OVjNYxcHoWc+1fX7p3s32778JI8k4dOFNsnug4P6UtNJ4mjw62OxQF tzlRYluG74Jmb+Anuq8wGkKvU8WHugMNGZAxw4D62lnVWJqM9mbIoZejkbzubN4jqqgt Y7Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=BFaAxFFz5ZXHt9cmup+dR769gZXv2ypvjwsySXzi/tY=; b=HTwKvFSLTXXFwUjS2tii1huRFKPrC6fzk/vdEWZ2E9MLzNOg+JS8FZ27pQdiqybAXi VWjXDc4fSW0NXI6Zv+WyWnvT1SS5XEoLaKdnKbuMT7Qa908MrTnJZsBJufmuw5EHej3A YtzeEyuuB8gxA7nvjPkoByYmoVYGUX+PBc3bMowf9iKuOd8oci8GKGCj1E9rrlfl+Xtu 0gIg8ybe2kU4DAPDbuqRC4PS+cbMAuOehfyrH2aOl2jXe4KenVrQnHwgMKpXDc4R29Cn uVMt/afKdCWSG+Kf7bbRoysngSHFBdlo3liveQEmb8VG5u8F6UTvNnz7mOQsY/V5m1f2 Oa6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5-v6si13566386pfi.285.2018.05.21.02.05.10; Mon, 21 May 2018 02:05:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522AbeEUJE6 (ORCPT + 99 others); Mon, 21 May 2018 05:04:58 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43670 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751685AbeEUJEt (ORCPT ); Mon, 21 May 2018 05:04:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FFCA7C6A9; Mon, 21 May 2018 09:04:48 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D58FB4AF1; Mon, 21 May 2018 09:04:45 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next 02/12] vhost_net: introduce vhost_exceeds_weight() Date: Mon, 21 May 2018 17:04:23 +0800 Message-Id: <1526893473-20128-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1526893473-20128-1-git-send-email-jasowang@redhat.com> References: <1526893473-20128-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 21 May 2018 09:04:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 21 May 2018 09:04:48 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Jason Wang --- drivers/vhost/net.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 15d191a..de544ee 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -479,6 +479,12 @@ static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, return len; } +static bool vhost_exceeds_weight(int pkts, int total_len) +{ + return unlikely(total_len >= VHOST_NET_WEIGHT) || + unlikely(pkts >= VHOST_NET_PKT_WEIGHT); +} + /* 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) @@ -570,7 +576,6 @@ static void handle_tx(struct vhost_net *net) msg.msg_control = NULL; ubufs = NULL; } - total_len += len; if (total_len < VHOST_NET_WEIGHT && !vhost_vq_avail_empty(&net->dev, vq) && @@ -600,8 +605,7 @@ static void handle_tx(struct vhost_net *net) else vhost_zerocopy_signal_used(net, vq); vhost_net_tx_packet(net); - if (unlikely(total_len >= VHOST_NET_WEIGHT) || - unlikely(++sent_pkts >= VHOST_NET_PKT_WEIGHT)) { + if (unlikely(vhost_exceeds_weight(++sent_pkts, total_len))) { vhost_poll_queue(&vq->poll); break; } @@ -887,8 +891,7 @@ static void handle_rx(struct vhost_net *net) if (unlikely(vq_log)) vhost_log_write(vq, vq_log, log, vhost_len); total_len += vhost_len; - if (unlikely(total_len >= VHOST_NET_WEIGHT) || - unlikely(++recv_pkts >= VHOST_NET_PKT_WEIGHT)) { + if (unlikely(vhost_exceeds_weight(++recv_pkts, total_len))) { vhost_poll_queue(&vq->poll); goto out; } -- 2.7.4