Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1804568imu; Wed, 21 Nov 2018 02:09:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/VduGT4DkJKO8SiUmtkUbefND2q3o6viF6Q/ejFjs8Ik9xvlNEymhimd77BOvNJRnvIsqcI X-Received: by 2002:a63:7418:: with SMTP id p24mr5441317pgc.196.1542794940340; Wed, 21 Nov 2018 02:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542794940; cv=none; d=google.com; s=arc-20160816; b=u/Hyzo2ScqU0BikEdGSHAGSYj/qlAhTdMEqy2BtOlbIxjBxpbCjW7RC5RwkQ6se4L9 vfWHNbu36SFLJTfuXOcb6mGYi89whsEQfLRubX5Xq5Kn8ermTqAVgfwK509SSilo1KHT u0HSl1b33bCC//bte0eTYscqsgeNYkki0qmbrk14M36vl2jhtI6PrXNiDGO7/oKyZp8T GXofqtuiohfYa2xWXw6eHa8rSWrEZ/8E7jYLtEESkMZ44raZM8DdAnbp+3a/niGmvucJ sJLGVU33sh1Hy7RvqzDTLANhrJ1nsEfvixbATBh6gRmpyPCDw+BvxUEZj+vlXJWzm6ht YK8A== 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=6sjZD6xgd5V9chztF6z00eI/QgmjE3kXjWFkq6kIy80=; b=potRZ7cLHFebm7Q5zGMUEl07fDJ1GxRCQXCPOnuEikw+FoTg/e2ptOByaujIP3oZXt JdrCibBcPg4xMGxe9LYZzJRKxl95iFrOdu9Z2O7VCTOo5NgD66qd5addc57jSMVIFON9 mwUddixfmGOh5nN/tjNMoXxdltRbrtMMw2xA2Z73/8NAY3qSHo+8RiN2d7izu+Go87D3 c7tk4PwgxaG72KVJcKkr5T2RlQ/HqpsWqMtzog8PhoPEjL/rKcQ10dXuXBqYAHS4VcOW uiCWgZs6Ytqml5XyvR6ox1UiiGtByk2h00lkIleE1CM+KMmuxGj94Ht24Qk0pt/go01i cDbA== 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 h32si10219853pgh.276.2018.11.21.02.08.43; Wed, 21 Nov 2018 02:09:00 -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 S1729833AbeKUUjd (ORCPT + 99 others); Wed, 21 Nov 2018 15:39:33 -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 S1729792AbeKUUjc (ORCPT ); Wed, 21 Nov 2018 15:39:32 -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:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,260,1539673200"; d="scan'208";a="275727086" Received: from btwcube1.sh.intel.com ([10.67.104.173]) by orsmga005.jf.intel.com with ESMTP; 21 Nov 2018 02:05:41 -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 09/13] virtio_ring: cache whether we will use DMA API Date: Wed, 21 Nov 2018 18:03:26 +0800 Message-Id: <20181121100330.24846-10-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 Cache whether we will use DMA API, instead of doing the check every time. We are going to check whether DMA API is used more often in packed ring. Signed-off-by: Tiwei Bie --- drivers/virtio/virtio_ring.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index d00a87909a7e..aafe1969b45e 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -86,6 +86,9 @@ struct vring_desc_state_split { struct vring_virtqueue { struct virtqueue vq; + /* Is DMA API used? */ + bool use_dma_api; + /* Can we use weak barriers? */ bool weak_barriers; @@ -262,7 +265,7 @@ static dma_addr_t vring_map_one_sg(const struct vring_virtqueue *vq, struct scatterlist *sg, enum dma_data_direction direction) { - if (!vring_use_dma_api(vq->vq.vdev)) + if (!vq->use_dma_api) return (dma_addr_t)sg_phys(sg); /* @@ -279,7 +282,7 @@ static dma_addr_t vring_map_single(const struct vring_virtqueue *vq, void *cpu_addr, size_t size, enum dma_data_direction direction) { - if (!vring_use_dma_api(vq->vq.vdev)) + if (!vq->use_dma_api) return (dma_addr_t)virt_to_phys(cpu_addr); return dma_map_single(vring_dma_dev(vq), @@ -289,7 +292,7 @@ static dma_addr_t vring_map_single(const struct vring_virtqueue *vq, static int vring_mapping_error(const struct vring_virtqueue *vq, dma_addr_t addr) { - if (!vring_use_dma_api(vq->vq.vdev)) + if (!vq->use_dma_api) return 0; return dma_mapping_error(vring_dma_dev(vq), addr); @@ -305,7 +308,7 @@ static void vring_unmap_one_split(const struct vring_virtqueue *vq, { u16 flags; - if (!vring_use_dma_api(vq->vq.vdev)) + if (!vq->use_dma_api) return; flags = virtio16_to_cpu(vq->vq.vdev, desc->flags); @@ -1202,6 +1205,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->broken = false; vq->last_used_idx = 0; vq->num_added = 0; + vq->use_dma_api = vring_use_dma_api(vdev); list_add_tail(&vq->vq.list, &vdev->vqs); #ifdef DEBUG vq->in_use = false; -- 2.14.5