From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86EFFC3A5AA for ; Wed, 4 Sep 2019 18:27:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 555E620882 for ; Wed, 4 Sep 2019 18:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567621634; bh=SObJ3poV/ig/tkiYS3lV8SbYdKIUI3tnmVs/3gFZtng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lwUvWqakNGGbwsx6rSslgo/he1LqSq3S6xF/EEyVIor//xaPXdNYb/N2gWgTAazgV 6kALRO81vTKyOwi6qNE9kcsL/QsXnZI2Uixu69sjzF62PqHjqPgqbsKl7ZjlML6Lut ToGHQAH99R+lLjnUjjtT4bOjix5sayDJgulCZYoI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387641AbfIDR4k (ORCPT ); Wed, 4 Sep 2019 13:56:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:34092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387631AbfIDR4j (ORCPT ); Wed, 4 Sep 2019 13:56:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AABE822CEA; Wed, 4 Sep 2019 17:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567619799; bh=SObJ3poV/ig/tkiYS3lV8SbYdKIUI3tnmVs/3gFZtng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tcak1oTRl0tR+vAzX0IbJMylcVUlZp6la/UHl++3oAj6iYt34EBw0mwgZQbKxsVd+ 5OyT7q2aBI9Hg2wUG/GtfGWOFuHcjsgW/motsq7+YrrqKG85CgrdcsA6kv/cA/DRvu rbVPDzWWdyTTZkpn8H3b0qIKb2d6YRe1iEVQxRmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Wang , "David S. Miller" , Ben Hutchings , Sasha Levin Subject: [PATCH 4.4 38/77] vhost_net: introduce vhost_exceeds_weight() Date: Wed, 4 Sep 2019 19:53:25 +0200 Message-Id: <20190904175307.172203458@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175303.317468926@linuxfoundation.org> References: <20190904175303.317468926@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit 272f35cba53d088085e5952fd81d7a133ab90789 upstream. Signed-off-by: Jason Wang Signed-off-by: David S. Miller [bwh: Backported to 4.4: adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Sasha Levin --- drivers/vhost/net.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index c1b5bccab293f..38c3120f92be4 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -293,6 +293,12 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success) rcu_read_unlock_bh(); } +static bool vhost_exceeds_weight(int pkts, int total_len) +{ + return total_len >= VHOST_NET_WEIGHT || + 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) @@ -415,8 +421,7 @@ static void handle_tx(struct vhost_net *net) vhost_zerocopy_signal_used(net, vq); total_len += len; 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; } @@ -640,8 +645,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); break; } -- 2.20.1