Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5433221rwd; Wed, 24 May 2023 01:28:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hAmYtID56qsHq8zaDqManEAZCmEF33J2LidSSpQ53ZILYXPRgdVcTm8SSyyTH8g0vFNL0 X-Received: by 2002:a05:6a20:c89b:b0:f2:57da:7f45 with SMTP id hb27-20020a056a20c89b00b000f257da7f45mr19280152pzb.8.1684916931589; Wed, 24 May 2023 01:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684916931; cv=none; d=google.com; s=arc-20160816; b=dF23yfDpwc6N4v30TYN4EYakb0sRe/PHiITtwbQFlHgb0oFPLqnkjC6OoRto8LTvJ9 jXyxo4AwHP9yqhYPgsNUowJuzq2VHjxX27IXv6pgBSMGVmrdqSco0ldtFYslD4v66btN x+FfBZOwd2whXQS67UOi6Y91qZOoFUmYXIRUWaV5jg8tNO0jQFg7S4JqsYGIfoEIvmYE ztGGvH84++IAn+3X9vzo11JWpLzG/hsj9VN3pI6Y3nYMQwwukLj3iA4PxO5g+L70cL5o FzKhSLm4XJuR8MLOZi8nrA4VWy/sD2m/AAlIzuuk8bEbmUCJ/n+M2Vt1diBaN6fn/Y/5 tAug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5tp/q1PP1rmEvhRQH+UYUnVd2qhSdAOgLuVIB9ywpVA=; b=cb+MQNRbr80dbBpIdc2NPC2E/GJh0EulFziFSisipRP5IEvV+Zspj0qdCmEXuV7VL8 aJLAz6PXTUIp1DibLUuKg+6IsaF2sBsZM/MUzP1/aqRl/xGimTEjYNNmHkeF913OA5UI sao0Bv7Ak1w5UiFyewNVHJeEqlth19rGR3hUAVm0zGnzI+voxtGZ9VSIGG7ThADVXP8j oHyLvo/m35vSnxsIsK2loPyVW1H0F5NPAPLGTx54WBNFbYv6eog2kxLVOvAn+47Zc+qz 6cB+DQswzyQZXqZv1PFYg01uLAt123fIOh0GSOb5UNcfUqO3WzYSZZ21wU014OuEatLX UMhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vb3Z+pyw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t22-20020a63b256000000b00524eefa6d61si2929148pgo.736.2023.05.24.01.28.39; Wed, 24 May 2023 01:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vb3Z+pyw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239236AbjEXIT7 (ORCPT + 99 others); Wed, 24 May 2023 04:19:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240168AbjEXITx (ORCPT ); Wed, 24 May 2023 04:19:53 -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 CC8CC184 for ; Wed, 24 May 2023 01:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684916346; 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=5tp/q1PP1rmEvhRQH+UYUnVd2qhSdAOgLuVIB9ywpVA=; b=Vb3Z+pyw1wIpaurGegVD4paKCBvCxpyKnnd4jXLb2oIw4EfTS1klY9Ibdqt5sZCRV+RVrI q3Onp/O0PSvQQ5yZozk1rj0Kr+fdov3g87kclz91Q3myLHGiffcxmpWmThNvAahcIUUwWR mRAdAaRIFRTXEUvYSzzTJIdNGR+CFVQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-319-Z1G78wGxMOGbs01QHEqnVg-1; Wed, 24 May 2023 04:19:02 -0400 X-MC-Unique: Z1G78wGxMOGbs01QHEqnVg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5C65802A55; Wed, 24 May 2023 08:19:00 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-76.pek2.redhat.com [10.72.13.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A48F140E95D; Wed, 24 May 2023 08:18:54 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alvaro.karsz@solid-run.com Subject: [PATCH V3 net-next 2/2] virtio-net: add cond_resched() to the command waiting loop Date: Wed, 24 May 2023 16:18:42 +0800 Message-Id: <20230524081842.3060-3-jasowang@redhat.com> In-Reply-To: <20230524081842.3060-1-jasowang@redhat.com> References: <20230524081842.3060-1-jasowang@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 5d2f1da4eaa0..de498dbbf0d4 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2207,8 +2207,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(); + } return vi->ctrl->status == VIRTIO_NET_OK; } -- 2.25.1