From nobody Sun Sep 7 17:10:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFC57EB64DD for ; Thu, 20 Jul 2023 08:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbjGTI5w (ORCPT ); Thu, 20 Jul 2023 04:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbjGTIjs (ORCPT ); Thu, 20 Jul 2023 04:39:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB7EE26AE for ; Thu, 20 Jul 2023 01:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689842340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2if8GUFmC1eD4optUaWK9NefEn7X4sNBFHPPoUxvNAg=; b=JToTET4rn/4KJJ4UXAutdqcxLZ+6qLR9VHH4iwjEZ5MFJknE1oC4aUiSKu3s69QibVEiQU uBu7yReOZxwVvBmlgxpvAFCf4jg2ZT+jpHFfjP5dDPYQ6etowKLocEH2IAQM6upDNgrfvb wv6tk7HF0We/MZmqsaG1xkkAQRxzzaE= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-127-0nX04BiMMru-iCGC6jqJJQ-1; Thu, 20 Jul 2023 04:38:56 -0400 X-MC-Unique: 0nX04BiMMru-iCGC6jqJJQ-1 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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1FACB3803926; Thu, 20 Jul 2023 08:38:56 +0000 (UTC) Received: from dell-per430-12.lab.eng.pek2.redhat.com (dell-per430-12.lab.eng.pek2.redhat.com [10.73.196.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0D5EF6CD8; Thu, 20 Jul 2023 08:38:51 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alvaro.karsz@solid-run.com, maxime.coquelin@redhat.com Subject: [PATCH net-next v4 2/2] virtio-net: add cond_resched() to the command waiting loop Date: Thu, 20 Jul 2023 04:38:39 -0400 Message-Id: <20230720083839.481487-3-jasowang@redhat.com> In-Reply-To: <20230720083839.481487-1-jasowang@redhat.com> References: <20230720083839.481487-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adding cond_resched() to the command waiting loop for a better co-operation with the scheduler. This allows to give CPU a breath to run other task(workqueue) instead of busy looping when preemption is not allowed on a device whose CVQ might be slow. Signed-off-by: Jason Wang Reviewed-by: Shannon Nelson --- drivers/net/virtio_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9f3b1d6ac33d..e7533f29b219 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2314,8 +2314,10 @@ static bool virtnet_send_command(struct virtnet_info= *vi, u8 class, u8 cmd, * into the hypervisor, so the request should be handled immediately. */ while (!virtqueue_get_buf(vi->cvq, &tmp) && - !virtqueue_is_broken(vi->cvq)) + !virtqueue_is_broken(vi->cvq)) { + cond_resched(); cpu_relax(); + } =20 return vi->ctrl->status =3D=3D VIRTIO_NET_OK; } --=20 2.39.3