Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1804791imu; Wed, 21 Nov 2018 02:09:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/XCIMGxsnW+6D70MDmZ/LpRDdybpzTc8kylHaENOgr7zCeS2LPJJzR0jq85LAywyGvb7Fw6 X-Received: by 2002:a63:d34a:: with SMTP id u10mr5439692pgi.301.1542794956221; Wed, 21 Nov 2018 02:09:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542794956; cv=none; d=google.com; s=arc-20160816; b=p8qCWOT3NKw6YO38FQPfh+UgACqy+szzTzYD0VACo8qswbrjEr0ANYjo1jOmYT9qY2 mkZz4/zKnK02cp5u65rlAtKuck+i2hIxZlrWC2QzsZkO4pCye6T3TajwbFN2vdSHpfMJ TQ9OmJs7xJYF9S+7uwQdnAZTlojlDhosPOeZpuI/Ym1LLWW1V0EM/qTNncSurkSkdUpy AT45zDTjhLOuxInVAo1LpC1bUVnyJ4jkKUIMHwYkLQX1DIfP1C4HIZveE40Oz501cYxf QbWbpHX8/7907epdtdMPDrM6qlUP1ou8Z3f4YqOB8Bnx1PsouWFh4Pb6rjAeoa3VgKyz Xgyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=M8nMnismsoWgSi76/D4Iv/erzgvua1WE36M9XdjNr9o=; b=ViO8jP4nTxGYTYrmoC1G4pZl++iZx2NG3CPwWRW3Irgq8h9njzgIng2OM4FUxgHAd4 mfTwUtRdlwF0FuYbFFmIOnn+ExpVa5WSVS4hT/jEwsc4QNe2OGiofB7XcwAnvhmepLpW fpnzrMs/lN1XfHQOE8x0ed7BdxED753sWaMaDRC22mosjjinQND3GUu1zeb1+6n3V6kk Vygc2o5PjOSoD3PygGUNwQmBVYbeG2srvwhumm3jTDAL7IsHMM3V50ju4EKSODP8Pvf3 evNBf9UCWAQ2jIdrc6rDijsXXQJGFxcW96PmhoFPCeGH7vaFP11P7DI9mGMmjxEzwqmA qhWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si45087937plt.349.2018.11.21.02.08.59; Wed, 21 Nov 2018 02:09:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729665AbeKUUj1 (ORCPT + 99 others); Wed, 21 Nov 2018 15:39:27 -0500 Received: from mga18.intel.com ([134.134.136.126]:14789 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729575AbeKUUj0 (ORCPT ); Wed, 21 Nov 2018 15:39:26 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2018 02:05:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,260,1539673200"; d="scan'208";a="275727064" Received: from btwcube1.sh.intel.com ([10.67.104.173]) by orsmga005.jf.intel.com with ESMTP; 21 Nov 2018 02:05:35 -0800 From: Tiwei Bie To: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, virtio-dev@lists.oasis-open.org Cc: wexu@redhat.com, jfreimann@redhat.com, maxime.coquelin@redhat.com, tiwei.bie@intel.com Subject: [PATCH net-next v3 06/13] virtio_ring: introduce helper for indirect feature Date: Wed, 21 Nov 2018 18:03:23 +0800 Message-Id: <20181121100330.24846-7-tiwei.bie@intel.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20181121100330.24846-1-tiwei.bie@intel.com> References: <20181121100330.24846-1-tiwei.bie@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a helper to check whether we will use indirect feature. It will be used by packed ring too. Signed-off-by: Tiwei Bie --- drivers/virtio/virtio_ring.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 10d407910aa2..d1076f28c7e9 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -145,6 +145,18 @@ struct vring_virtqueue { #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq) +static inline bool virtqueue_use_indirect(struct 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 + */ + return (vq->indirect && total_sg > 1 && vq->vq.num_free); +} + /* * Modern virtio devices have feature bits to specify whether they need a * quirk and bypass the IOMMU. If not there, just use the DMA API. @@ -324,9 +336,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, head = vq->free_head; - /* If the host supports indirect descriptor tables, and we have multiple - * buffers, then go indirect. FIXME: tune this threshold */ - if (vq->indirect && total_sg > 1 && vq->vq.num_free) + if (virtqueue_use_indirect(_vq, total_sg)) desc = alloc_indirect_split(_vq, total_sg, gfp); else { desc = NULL; -- 2.14.5