Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp341089imi; Thu, 21 Jul 2022 01:51:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+M04twB5yspI/y645SHQ3NXrhgjAx+aFkAutH+a3G4XMvzpt2pVTGPkzAM29H09J6HYUk X-Received: by 2002:a17:907:72ce:b0:72f:7b3:b9c8 with SMTP id du14-20020a17090772ce00b0072f07b3b9c8mr26376327ejc.248.1658393464771; Thu, 21 Jul 2022 01:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658393464; cv=none; d=google.com; s=arc-20160816; b=AWCsW/h8FN8NzkeD4fo0gLVdF3LWo0oudANeg//9TNb5uJd+jFYMPmxsS7mzgctxMF uMoguidPQgATfy7WLh5vJBHHbl8MqpWsTwa9UwgAgvV1t4QFfY4YIf0U1OuKJyOz5Edi VRYt9ToOxBIfabCR6iGSWSan3YaRZWtPdtszdLqUZ6UTelsfGsQ3Axsxh/bCfga2Sd1E 1Q342qfD7X3rBOAQmbrcc6SXK72eMuly9xcoXO7Q6XUVVJl776BRzu1lJrdPTE7EHqde PYrt1AsAXnFkf2O/TMG1Nj+STYwsb23myAS8IHnegRvJepUZt4C87cIoi6AsotDuGC6q wAqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=Bm7WCj0Isvv0QS/QXB5w4tVja6jsKJaLMbZBeP+uuWY=; b=gd0a1DT5czyduJkEvNRMTT3ppkaqff9OnB0uq6BQ6MhsTnnZfeBJUtKhdEw9ZTOVcc jZjGNFsja059PKxnqrf1kOup/38vgDvSEiN5UBOcqMsNJ+Macu605Z2Vm6JTHURsFpVT gRiCQZyZTSW58h8FwlKj4eu67KWI5doANIajYxiHU9J8zmsLCdtP1RgE9rQIisFgkBj3 /BQqgET5yxq/gkoax+juoohKN8x3DruqZsrtFamqI3VHwP02LO88YF/TGYBTG1uzL5A8 JZIUkFndw/CmIqr60enX0IcLe7a6G7+8+kWlTI7POhtP7U4R7hSLMh0AFm05M52ZUBlY pmFg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb32-20020a170907962000b0072e56bd2bbbsi1998807ejc.570.2022.07.21.01.50.39; Thu, 21 Jul 2022 01:51:04 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232535AbiGUIpQ (ORCPT + 99 others); Thu, 21 Jul 2022 04:45:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232526AbiGUIo7 (ORCPT ); Thu, 21 Jul 2022 04:44:59 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 190307FE6D for ; Thu, 21 Jul 2022 01:44:54 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 60E971008B38D; Thu, 21 Jul 2022 16:44:45 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 404A820089230; Thu, 21 Jul 2022 16:44:45 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ASNR1t25gaag; Thu, 21 Jul 2022 16:44:45 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 738F4200BFDA8; Thu, 21 Jul 2022 16:44:33 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC 4/5] virtio: get desc id in order Date: Thu, 21 Jul 2022 16:43:40 +0800 Message-Id: <20220721084341.24183-5-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220721084341.24183-1-qtxuning1999@sjtu.edu.cn> References: <20220721084341.24183-1-qtxuning1999@sjtu.edu.cn> X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,RCVD_IN_SORBS_WEB, SPF_HELO_NONE,SPF_PASS 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 If in order feature negotiated, we can skip the used ring to get buffer's desc id sequentially. Signed-off-by: Guo Zhi --- drivers/virtio/virtio_ring.c | 37 ++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index a5ec724c0..4d57a4edc 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -144,6 +144,9 @@ struct vring_virtqueue { /* DMA address and size information */ dma_addr_t queue_dma_addr; size_t queue_size_in_bytes; + + /* In order feature batch begin here */ + u16 next_batch_desc_begin; } split; /* Available for packed ring */ @@ -700,8 +703,10 @@ static void detach_buf_split(struct vring_virtqueue *vq, unsigned int head, } vring_unmap_one_split(vq, i); - vq->split.desc_extra[i].next = vq->free_head; - vq->free_head = head; + if (!virtio_has_feature(vq->vq.vdev, VIRTIO_F_IN_ORDER)) { + vq->split.desc_extra[i].next = vq->free_head; + vq->free_head = head; + } /* Plus final descriptor */ vq->vq.num_free++; @@ -743,7 +748,8 @@ static void *virtqueue_get_buf_ctx_split(struct virtqueue *_vq, { struct vring_virtqueue *vq = to_vvq(_vq); void *ret; - unsigned int i; + __virtio16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT); + unsigned int i, j; u16 last_used; START_USE(vq); @@ -762,11 +768,24 @@ static void *virtqueue_get_buf_ctx_split(struct virtqueue *_vq, /* Only get used array entries after they have been exposed by host. */ virtio_rmb(vq->weak_barriers); - last_used = (vq->last_used_idx & (vq->split.vring.num - 1)); - i = virtio32_to_cpu(_vq->vdev, - vq->split.vring.used->ring[last_used].id); - *len = virtio32_to_cpu(_vq->vdev, - vq->split.vring.used->ring[last_used].len); + if (virtio_has_feature(_vq->vdev, VIRTIO_F_IN_ORDER)) { + /* Skip used ring and get used desc in order*/ + i = vq->split.next_batch_desc_begin; + j = i; + while (vq->split.vring.desc[j].flags & nextflag) + j = (j + 1) % vq->split.vring.num; + /* move to next */ + j = (j + 1) % vq->split.vring.num; + vq->split.next_batch_desc_begin = j; + + /* TODO: len of buffer */ + } else { + last_used = (vq->last_used_idx & (vq->split.vring.num - 1)); + i = virtio32_to_cpu(_vq->vdev, + vq->split.vring.used->ring[last_used].id); + *len = virtio32_to_cpu(_vq->vdev, + vq->split.vring.used->ring[last_used].len); + } if (unlikely(i >= vq->split.vring.num)) { BAD_RING(vq, "id %u out of range\n", i); @@ -2234,6 +2253,8 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->split.avail_flags_shadow = 0; vq->split.avail_idx_shadow = 0; + vq->split.next_batch_desc_begin = 0; + /* No callback? Tell other side not to bother us. */ if (!callback) { vq->split.avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT; -- 2.17.1