Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp590766rwb; Thu, 6 Oct 2022 01:26:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FQycQE0parnxhDjojmpHvXUzdl3MWYv4WtQ13i5YN+poAaW0QuoChKt+mpg4L1PdhaDhZ X-Received: by 2002:a17:90a:3841:b0:20b:650:60d1 with SMTP id l1-20020a17090a384100b0020b065060d1mr2858262pjf.102.1665044774056; Thu, 06 Oct 2022 01:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665044774; cv=none; d=google.com; s=arc-20160816; b=UobpbXRr0Px7Rpf4eRRNdP7ayn18I15g1ipwzPfvj72GsLt+SO/QiQl5e86TzvgDeI HGJl3f1uRvjZZj82DafgkdfOB10dwN+B5A3j470/rRHXlwM5oz6jLKRMwjcNDa3wzv5V m4uORsTg4bueNrVjOfJ7Abx5skTm0h93hJvC3NosGrrMn6mj2EoOmaSn2RyKir3BSsCL QDHEnyxM3WxvxcUBK1BYllQJoFIXA1mw/htXFvETwO/h/ttSW7z8CRfl+i2EIN2ToDQZ 8hfvuVH8svX85ALRSX0MmnOe51MxmzDu6XxxPxJZq2O7cxelJTdWR+4ObHTJHfzpE6qA CUjA== 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=7k6sBZyaVBBU0uVDVGNgpE51Zx2bnnN0v581CxRue6E=; b=E31mX+35Ue6yI2qP+Nl2XNbXQaLR8a/tePG+fxsn/tUN9U72XlNeAQlojqIP2d5sz7 l3fkRp/NBUYrBDbhwSWs9cRp/HWQqNTHzfoyJsRFHHiIjGHzR69fj9SDLouCF9+GDyu0 TdXjNdpriWdrrjt+aLc36kkuiaQGPWKC9ASSAbIS5Hr1XpuiPwk0/5vdIBiSi0/U3lsv yInyBLRl+7+uiwrCRVjDR2Y1GufOeNWodIyICN7ZyLWtpOBr5Q5lHJDpCYF4j0H9uTZL Di3PM8A8WB0Dm6rgIemaaTCHySkEAJyxOT5/T7s72EJuyfOWCnFx2D6GEf0O+JpSK6du KL4A== 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 w3-20020a628203000000b005614fb190e4si10858718pfd.193.2022.10.06.01.26.01; Thu, 06 Oct 2022 01:26:14 -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 S230319AbiJFIG6 (ORCPT + 99 others); Thu, 6 Oct 2022 04:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbiJFIG4 (ORCPT ); Thu, 6 Oct 2022 04:06:56 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F5522A406 for ; Thu, 6 Oct 2022 01:06:53 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R541e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=liusong@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VRPuuLR_1665043580; Received: from localhost(mailfrom:liusong@linux.alibaba.com fp:SMTPD_---0VRPuuLR_1665043580) by smtp.aliyun-inc.com; Thu, 06 Oct 2022 16:06:51 +0800 From: Liu Song To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] virtio_ring: remove unnecessary variables in virtqueue_add_packed Date: Thu, 6 Oct 2022 16:06:20 +0800 Message-Id: <1665043580-10009-1-git-send-email-liusong@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 From: Liu Song Unlike "virtqueue_add_split", "descs_used" will only be equal to "total_sg" in the context of "virtqueue_add_packed", so it can be removed to reduce unnecessary operations. Signed-off-by: Liu Song --- drivers/virtio/virtio_ring.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 2e7689b..2f5b900 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1353,7 +1353,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, struct vring_virtqueue *vq = to_vvq(_vq); struct vring_packed_desc *desc; struct scatterlist *sg; - unsigned int i, n, c, descs_used, err_idx; + unsigned int i, n, c, err_idx; __le16 head_flags, flags; u16 head, id, prev, curr, avail_used_flags; int err; @@ -1390,11 +1390,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, desc = vq->packed.vring.desc; i = head; - descs_used = total_sg; - if (unlikely(vq->vq.num_free < descs_used)) { + if (unlikely(vq->vq.num_free < total_sg)) { pr_debug("Can't add buf len %i - avail = %i\n", - descs_used, vq->vq.num_free); + total_sg, vq->vq.num_free); END_USE(vq); return -ENOSPC; } @@ -1445,14 +1444,14 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, vq->packed.avail_wrap_counter ^= 1; /* We're using some buffers from the free list. */ - vq->vq.num_free -= descs_used; + vq->vq.num_free -= total_sg; /* Update free pointer */ vq->packed.next_avail_idx = i; vq->free_head = curr; /* Store token. */ - vq->packed.desc_state[id].num = descs_used; + vq->packed.desc_state[id].num = total_sg; vq->packed.desc_state[id].data = data; vq->packed.desc_state[id].indir_desc = ctx; vq->packed.desc_state[id].last = prev; @@ -1464,7 +1463,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, */ virtio_wmb(vq->weak_barriers); vq->packed.vring.desc[head].flags = head_flags; - vq->num_added += descs_used; + vq->num_added += total_sg; pr_debug("Added buffer head %i to %p\n", head, vq); END_USE(vq); -- 1.8.3.1