From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 85D75A0C43; Fri, 8 Oct 2021 00:14:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FF9E4144A; Fri, 8 Oct 2021 00:14:42 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 42F43413D1 for ; Fri, 8 Oct 2021 00:14:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644880; 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=2SOIUIjyy+S/caL7rnP5/rff1qUzjFXRF68rt+evcZc=; b=hVjuyFINzqItG/owQnaXE8Jc2s03c+lW9Cd1Gev+jAZPFhIySjZ6DKJalgDinf9XzJD3FA P+YjSh8lpnNaaVxbXFl39rWqbr5H+41u59G5i4Ku9RvjKfqn55v1ZYzQ18RcnzY1ZB5blJ pCrqxku4nNBSR6fyOXqAlQ5Z8c7HBKY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-571-9uPjsHj8Oeq9PnTI71Rjuw-1; Thu, 07 Oct 2021 18:14:37 -0400 X-MC-Unique: 9uPjsHj8Oeq9PnTI71Rjuw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD6408CE093; Thu, 7 Oct 2021 22:00:56 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C75725C1A3; Thu, 7 Oct 2021 22:00:54 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:10 +0200 Message-Id: <20211007220013.355530-12-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [RFC 11/14] vhost: simplify getting the first in-flight index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch reworks the function getting the index for the first packet in-flight. When this index turns out to be zero, let's use the simple path. Doing that avoid having to do a modulo with the virtqueue size. The patch also rename the function for better clarifty, and only pass the virtqueue metadata pointer, as all the needed information are stored there. Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index c5651f1e0f..2aa06a958c 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1489,11 +1489,14 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id, } static __rte_always_inline uint16_t -virtio_dev_rx_async_get_info_idx(uint16_t pkts_idx, - uint16_t vq_size, uint16_t n_inflight) +async_get_first_inflight_pkt_idx(struct vhost_virtqueue *vq) { - return pkts_idx > n_inflight ? (pkts_idx - n_inflight) : - (vq_size - n_inflight + pkts_idx) % vq_size; + struct vhost_async *async = vq->async; + + if (async->pkts_idx >= async->pkts_inflight_n) + return async->pkts_idx - async->pkts_inflight_n; + else + return vq->size - async->pkts_inflight_n + async->pkts_idx; } static __rte_always_inline void @@ -1931,9 +1934,6 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, uint16_t n_descs = 0, n_buffers = 0; uint16_t start_idx, from, i; - start_idx = virtio_dev_rx_async_get_info_idx(async->pkts_idx, - vq->size, async->pkts_inflight_n); - n_cpl = async->ops.check_completed_copies(dev->vid, queue_id, 0, count); if (unlikely(n_cpl < 0)) { VHOST_LOG_DATA(ERR, "(%d) %s: failed to check completed copies for queue id %d.\n", @@ -1944,6 +1944,8 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, if (n_cpl == 0) return 0; + start_idx = async_get_first_inflight_pkt_idx(vq); + for (i = 0; i < n_cpl; i++) { from = (start_idx + i) % vq->size; /* Only used with packed ring */ -- 2.31.1