From patchwork Fri Nov 11 08:59:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9422611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B6886047D for ; Fri, 11 Nov 2016 08:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 914F529980 for ; Fri, 11 Nov 2016 08:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8504729983; Fri, 11 Nov 2016 08:59:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D13A329980 for ; Fri, 11 Nov 2016 08:59:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 68E306E81E; Fri, 11 Nov 2016 08:59:29 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6122D6E8AD for ; Fri, 11 Nov 2016 08:59:27 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id m203so6291956wma.3 for ; Fri, 11 Nov 2016 00:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L8Hvfkclrh11Z3u91vT/JJw8Z9jOPcfN6NgKaIj67aQ=; b=y2O7ZJrqTFEIGIJQOAspzBoLMloCt+SomORxd4f2iHg3+1RPN37qmMBPpHSFLPyRK+ EnhSb4tXma2KQG5cHjo3WOYxugYkIjHuL3Pj/23Ak8CQRU1dS2GWgtY2P161wkRnfs1Y s1ialV79CmtEhyj1lxLcg00CF4XV/OHKrKpH4bleNoc5rjaBKCyg89S9wMBn6WgmUyhk POEjF1iMqOM5oKblWgKMRhFdvck/DcpiDyXVdLwytM38zlcdeJ/slcgOzbAh9HXjWefA hOkWuCXQvfwz7Gpo/cseiqnidP8cGqnAghnAq0Zv1Fgbt0cI0RJK2xPEfdD/RgKUoTYk PAuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L8Hvfkclrh11Z3u91vT/JJw8Z9jOPcfN6NgKaIj67aQ=; b=c7yoOgpSB3Zl3e9QMal6DFUHal/2Hqdi8F3UnfqZOcxgxi1kp5ZN0LKNE9OcPjvDEV /sdyRRgKtmyjcKnMDUk8s/K5DxBRiz16xLWe0R/lD0Yr/MfPUw7oxXH3vj9TS889HC5m 7w9xAHuc9uJW+yaD9sEVoP7kToqYr1Pp/BgMHacVFpXYCGqSB32bOd3hbX/rEV3srMzF MZSuxm0LmQDq1p6zchLvV7XmQt2iTQAfo4c1RUnowxN5bqCcoNWvK72BnPJ0x3tXV9LN 3vzTHXDwrilvi+uhJ4pzwkvX4xcm/XwE2WA3jpmfUryR3kH6upDmAOKfGUIg4KEwtPWX HUXA== X-Gm-Message-State: ABUngveEspsARirJ2HMaDosXKNFeC7myLS2IvKC/DCJZJ6t0631myJh1kAh1UWZE7DapuA== X-Received: by 10.194.102.100 with SMTP id fn4mr7965446wjb.199.1478854765944; Fri, 11 Nov 2016 00:59:25 -0800 (PST) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id d17sm7925240wjr.14.2016.11.11.00.59.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 00:59:25 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 11 Nov 2016 08:59:17 +0000 Message-Id: <1478854757-8479-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478854220-3255-5-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1478854220-3255-5-git-send-email-tvrtko.ursulin@linux.intel.com> Cc: linux-kernel@vger.kernel.org Subject: [Intel-gfx] [PATCH v3 4/4] drm/i915: Use __sg_alloc_table_from_pages for userptr allocations X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin With the addition of __sg_alloc_table_from_pages we can control the maximum coallescing size and eliminate a separate path for allocating backing store here. Similar to 871dfbd67d4e ("drm/i915: Allow compaction upto SWIOTLB max segment size") this enables more compact sg lists to be created and so has a beneficial effect on workloads with many and/or large objects of this class. v2: * Rename helper to i915_sg_segment_size and fix swiotlb override. * Commit message update. v3: * Actually include the swiotlb override fix. Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson --- drivers/gpu/drm/i915/i915_drv.h | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem.c | 15 +-------------- drivers/gpu/drm/i915/i915_gem_userptr.c | 28 ++++++---------------------- 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 30777dee3f9c..38a555c9c44b 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -4175,4 +4175,15 @@ int remap_io_mapping(struct vm_area_struct *vma, __T; \ }) +static inline unsigned int i915_sg_segment_size(void) +{ +#if IS_ENABLED(CONFIG_SWIOTLB) + unsigned int nr_tbl = swiotlb_nr_tbl(); + + return nr_tbl > 0 ? nr_tbl << IO_TLB_SHIFT : UINT_MAX; +#else + return UINT_MAX; +#endif +} + #endif diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 1c20edba7f2a..cb4c188a395c 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2223,15 +2223,6 @@ void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj, mutex_unlock(&obj->mm.lock); } -static unsigned int swiotlb_max_size(void) -{ -#if IS_ENABLED(CONFIG_SWIOTLB) - return rounddown(swiotlb_nr_tbl() << IO_TLB_SHIFT, PAGE_SIZE); -#else - return 0; -#endif -} - static void i915_sg_trim(struct sg_table *orig_st) { struct sg_table new_st; @@ -2267,7 +2258,7 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj) struct sgt_iter sgt_iter; struct page *page; unsigned long last_pfn = 0; /* suppress gcc warning */ - unsigned int max_segment; + unsigned int max_segment = rounddown(i915_sg_segment_size(), PAGE_SIZE); int ret; gfp_t gfp; @@ -2278,10 +2269,6 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj) GEM_BUG_ON(obj->base.read_domains & I915_GEM_GPU_DOMAINS); GEM_BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS); - max_segment = swiotlb_max_size(); - if (!max_segment) - max_segment = rounddown(UINT_MAX, PAGE_SIZE); - st = kmalloc(sizeof(*st), GFP_KERNEL); if (st == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c index 64261639f547..b4461f1832a6 100644 --- a/drivers/gpu/drm/i915/i915_gem_userptr.c +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c @@ -390,36 +390,20 @@ struct get_pages_work { struct task_struct *task; }; -#if IS_ENABLED(CONFIG_SWIOTLB) -#define swiotlb_active() swiotlb_nr_tbl() -#else -#define swiotlb_active() 0 -#endif - static int st_set_pages(struct sg_table **st, struct page **pvec, int num_pages) { - struct scatterlist *sg; - int ret, n; + int ret; *st = kmalloc(sizeof(**st), GFP_KERNEL); if (*st == NULL) return -ENOMEM; - if (swiotlb_active()) { - ret = sg_alloc_table(*st, num_pages, GFP_KERNEL); - if (ret) - goto err; - - for_each_sg((*st)->sgl, sg, num_pages, n) - sg_set_page(sg, pvec[n], PAGE_SIZE, 0); - } else { - ret = sg_alloc_table_from_pages(*st, pvec, num_pages, - 0, num_pages << PAGE_SHIFT, - GFP_KERNEL); - if (ret) - goto err; - } + ret = __sg_alloc_table_from_pages(*st, pvec, num_pages, 0, + num_pages << PAGE_SHIFT, + GFP_KERNEL, i915_sg_segment_size()); + if (ret) + goto err; return 0;