Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1756970pxb; Fri, 25 Mar 2022 05:10:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYQONX3tyq2A6x5UEj0om5NiGVqqXgk68Hg9JXyWkrN3DFMe8ajjC2L37DNzhDjHTJ6KYx X-Received: by 2002:a17:907:3f86:b0:6df:ad43:583 with SMTP id hr6-20020a1709073f8600b006dfad430583mr11491272ejc.535.1648210212399; Fri, 25 Mar 2022 05:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648210212; cv=none; d=google.com; s=arc-20160816; b=OA0gpWqonumjddYuoxRiPIW3rHQecFPn9DzRe/j1FCkJd8N5thD0+Pgi8cQyellwbE nyGWmnAPmcQn40T5Uwe5wKcar74xs8DjKSK6QG1HFG6cCd8iPBRAGdSIASTZJTaqj1H7 jyfCFiPB904zfycmhsCP02iXVdwRqU83grE9AOL34Td90Mcxejl9y3VwJsHHm0fPiOoX IQDy++Vl8gLw9OHKQ4/xYQs+35K9ZA/cJ3C4lXr9AX5he9WD5oIDRaNniSZQxvTlOATG /pOBdkr2lVXrWs79scE2HQtjgSjd8EzIpHz6wnOz/ziaXPmK3suWxo3rypoTYMFk1DX8 azfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=gUQseG7p1t+Vcf7NcUJF/olzuGA7ZjIhTeIaIZ1VJTA=; b=lvbOqlScXwj5nOWdoSyXz30/TlGwnAFAmL6wXj5A5jjPmxxXJmz8SKgQPrX1VHd4Cj 2QcfQHwsjKIoDieL+gf5dbddy7JsIdjI8qVHVk3Y6EBYKuyEg/zrhhzFjKOfN3kd7YAy 9HLbyswxeUOOYPZZD/tmWDs76+cpeKmX4S3NuwyWLRzhFrZdJQwy6EBl3UUIn8JnLt1L SdhXGYpuFI5gzkwIxNxCXF03VLtyXxJOO/8bM2ccnvNL3mpHiVB6p3pPvcckpeNnQqoe fBHljqkycp+gtdfldMtyZ3/lSgYhwGuSbqm1PnHiGC5DoUAwSZ02W7B/Coynz4VRK6Gv fY6w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a17090624d300b006df76385c34si2210354ejb.212.2022.03.25.05.09.44; Fri, 25 Mar 2022 05:10:12 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345603AbiCXHfR (ORCPT + 99 others); Thu, 24 Mar 2022 03:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234254AbiCXHfQ (ORCPT ); Thu, 24 Mar 2022 03:35:16 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4F633A for ; Thu, 24 Mar 2022 00:33:44 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0V83t1Bl_1648107221; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0V83t1Bl_1648107221) by smtp.aliyun-inc.com(127.0.0.1); Thu, 24 Mar 2022 15:33:42 +0800 From: Xianting Tian To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Xianting Tian Subject: [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path Date: Thu, 24 Mar 2022 15:33:40 +0800 Message-Id: <20220324073340.632656-1-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham 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 It passes '_vq' to virtqueue_use_indirect(), which still calls to_vvq to get 'vq', let's directly pass 'vq'. It can avoid unnecessary call of to_vvq in hot path. Other tiny optimization: Add unlikely to "if (vq->vq.num_free < descs_used). Signed-off-by: Xianting Tian --- drivers/virtio/virtio_ring.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 962f1477b1fa..ab6d5f0cb579 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -205,11 +205,9 @@ struct vring_virtqueue { #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq) -static inline bool virtqueue_use_indirect(struct virtqueue *_vq, +static inline bool virtqueue_use_indirect(struct vring_virtqueue *vq, unsigned int total_sg) { - struct vring_virtqueue *vq = to_vvq(_vq); - /* * If the host supports indirect descriptor tables, and we have multiple * buffers, then go indirect. FIXME: tune this threshold @@ -507,7 +505,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, head = vq->free_head; - if (virtqueue_use_indirect(_vq, total_sg)) + if (virtqueue_use_indirect(vq, total_sg)) desc = alloc_indirect_split(_vq, total_sg, gfp); else { desc = NULL; @@ -527,7 +525,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, descs_used = total_sg; } - if (vq->vq.num_free < descs_used) { + if (unlikely(vq->vq.num_free < descs_used)) { pr_debug("Can't add buf len %i - avail = %i\n", descs_used, vq->vq.num_free); /* FIXME: for historical reasons, we force a notify here if @@ -1194,7 +1192,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, BUG_ON(total_sg == 0); - if (virtqueue_use_indirect(_vq, total_sg)) { + if (virtqueue_use_indirect(vq, total_sg)) { err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, in_sgs, data, gfp); if (err != -ENOMEM) { -- 2.17.1