Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5604485pxb; Mon, 28 Mar 2022 14:51:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB3xI+r/+zAMxJHcRtxq5acog9TCfPIYlYH0+E7WsAJ7lpFmPcaMEf5ID5ff7yzmSUSqKD X-Received: by 2002:a05:6808:b3b:b0:2ee:f4cf:78fd with SMTP id t27-20020a0568080b3b00b002eef4cf78fdmr633887oij.213.1648504305144; Mon, 28 Mar 2022 14:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648504305; cv=none; d=google.com; s=arc-20160816; b=fHtVKdnilQFgJUSTeEYCmM/YKazmITpG3mVd3qxd2hn7Lc4zwri7AdmWXqh4TvuHOz euXRBcaAH5IiYf6Xz9M9wSmfK7qiY2XM/oYAoMUkuXl048Z4BfLqnHHJpFZhSKd/uEVj FUoIpI0lr1q+Iy13LN4io2Pine7lea8DPEalNZ4o75pTmIAhNeyFLm/c/0t9HWO4E1nI FkklK/YyeM2M0NzYucMbm6ZMUn0hU/0CKASF+EocwEhPYHzrQOS1tA6G53pciNLTWSwa aOa+nr6WIlGu3O8hpeMa2U2V8/Dux0OmpS31Jy7JSXYv1d2vXuNFz43M6kMJbD4wp7SV mYqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=+pzRQo3810r2o7zzvZmIAPZ0CVhllvu5MOfRyEa3iwo=; b=leYGtJ+4qccXSzJIcrcph77CUnHRwSEg1cyNtYzje+cXhYv4fJUBHlSJuj1wf0yp4t IMyi/RXD9Pi0HsJC1FEYiKyVw2aP71o84HP6RE0NyBMDdVFa73j1HKOPo28V3JJaJDc+ +akiLJ7nw7VOp3qLdpohXALXh/+PNKolgmxs8rdzfJ0CgCxfFKYmcwr2BcHz3zjGj+UK pjeeB2jetuvoPVd9oAeKKwjiL40Ypqw9BaoBhUmt1/jH1RsVzCsCjHZwAmuPDhxmtEL2 Er+td7HgO5C9lKxBGQJTbqNxNZXnO8iE2DCGChmGmMiBKb2hg5baV7nYVtro/4Yo4G3b HPbA== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a20-20020a544e14000000b002f73f0e847fsi7362823oiy.23.2022.03.28.14.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:51:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1421137F44; Mon, 28 Mar 2022 14:22:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239695AbiC1JPE (ORCPT + 99 others); Mon, 28 Mar 2022 05:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234016AbiC1JPD (ORCPT ); Mon, 28 Mar 2022 05:15:03 -0400 Received: from out199-2.us.a.mail.aliyun.com (out199-2.us.a.mail.aliyun.com [47.90.199.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39A94CE5 for ; Mon, 28 Mar 2022 02:13:21 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0V8QUIIa_1648458797; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0V8QUIIa_1648458797) by smtp.aliyun-inc.com(127.0.0.1); Mon, 28 Mar 2022 17:13:18 +0800 Subject: Re: [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path To: Stefano Garzarella Cc: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20220324073340.632656-1-xianting.tian@linux.alibaba.com> <20220328090503.wk5idknhwsbunkjs@sgarzare-redhat> From: Xianting Tian Message-ID: <7d0d6b08-321e-2e09-3ced-add916e6f07d@linux.alibaba.com> Date: Mon, 28 Mar 2022 17:13:16 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20220328090503.wk5idknhwsbunkjs@sgarzare-redhat> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 在 2022/3/28 下午5:05, Stefano Garzarella 写道: > On Thu, Mar 24, 2022 at 03:33:40PM +0800, Xianting Tian wrote: >> 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. > > It seems reasonable to me. > >> >> Other tiny optimization: >> Add unlikely to "if (vq->vq.num_free < descs_used). > > Better to do this change in another patch. Thanks for the reply, I will send the patchset, which contains the two patches, soon. > > Thanks, > Stefano > >> >> 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 >>