All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Widawsky <benjamin.widawsky@intel.com>
To: Intel GFX <intel-gfx@lists.freedesktop.org>
Cc: Ben Widawsky <ben@bwidawsk.net>
Subject: [PATCH 22/48] drm/i915: Use drm_mm for PPGTT PDEs
Date: Fri,  6 Dec 2013 14:11:55 -0800	[thread overview]
Message-ID: <1386367941-7131-70-git-send-email-benjamin.widawsky@intel.com> (raw)
In-Reply-To: <1386367941-7131-1-git-send-email-benjamin.widawsky@intel.com>

From: Ben Widawsky <ben@bwidawsk.net>

When PPGTT support was originally enabled, it was only designed to
support 1 PPGTT. It therefore made sense to simply hide the GGTT space
required to enable this from the drm_mm allocator.

Since we intend to support full PPGTT, which means more than 1, and they
can be created and destroyed ad hoc it will be required to use the
proper allocation techniques we already have.

The first step here is to make the existing single PPGTT use the
allocator.

The astute observer will notice that we are reserving space in the GGTT
for the PDEs for the lifetime of the address space, and would be right
to question whether or not this is a good idea. It does not make a
difference with this current patch only the aliasing PPGTT (indeed the
PDEs should still be hidden from the shrinker). For the future, we are
allocating from top to bottom to avoid using the precious "gtt
space" The GGTT space at that point should only be used for scanout, HW
contexts, ringbuffers, HWSP, PDEs, and a couple of other small buffers
(potentially) used by the kernel. Everything else should be mapped into
a PPGTT. To put the consumption in more tangible terms, it takes
approximately 4 sets of PDEs to equal one 19x10 framebuffer (with no
fancy stride or alignment constraints). 3/4 of the total [average] GGTT
can be used for PDEs, and hopefully never touch the 1/4 that the
framebuffer needs.

The astute, and persistent observer might ask about the page tables
which are also pinned for the address space. This waste is unfortunate.
We use 2MB of memory per address space. We leave wrapping the PDEs as a
real GEM object as a TODO.

v2: Align PDEs to 64b in GTT
Allocate the node dynamically so we can use drm_mm_put_block
Now tested on IGT
Allocate node at the top to avoid fragmentation (Chris)

v3: Use Chris' top down allocator

v4: Embed drm_mm_node into ppgtt struct (Jesse)
Remove hunks which didn't belong (Jesse)

v5: Don't subtract guard page since we now killed the guard page prior
to this patch. (Ben)

v6: Rebased and removed guard page stuff.
Added a chunk to the commit message
Allow adding a context to mappable region

v7: Undo v3, so we can make the drm patch last in the series

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org> (v4)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>

squash: drm/i915: allow PPGTT to use mappable
---
 drivers/gpu/drm/i915/i915_drv.h     |  1 +
 drivers/gpu/drm/i915/i915_gem_gtt.c | 56 ++++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 571a0a7..c86f3fd 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -654,6 +654,7 @@ struct i915_gtt {
 
 struct i915_hw_ppgtt {
 	struct i915_address_space base;
+	struct drm_mm_node node;
 	unsigned num_pd_entries;
 	union {
 		struct page **pt_pages;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 7561efc..4c0b865 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -620,6 +620,7 @@ static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
 	int i;
 
 	drm_mm_takedown(&ppgtt->base.mm);
+	drm_mm_remove_node(&ppgtt->node);
 
 	if (ppgtt->pt_dma_addr) {
 		for (i = 0; i < ppgtt->num_pd_entries; i++)
@@ -637,16 +638,27 @@ static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
 
 static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 {
+#define GEN6_PD_ALIGN (PAGE_SIZE * 16)
+#define GEN6_PD_SIZE (GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE)
 	struct drm_device *dev = ppgtt->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	unsigned first_pd_entry_in_global_pt;
-	int i;
-	int ret = -ENOMEM;
+	int i, ret;
 
-	/* ppgtt PDEs reside in the global gtt pagetable, which has 512*1024
-	 * entries. For aliasing ppgtt support we just steal them at the end for
-	 * now. */
-	first_pd_entry_in_global_pt = gtt_total_entries(dev_priv->gtt);
+	/* PPGTT PDEs reside in the GGTT and consists of 512 entries. The
+	 * allocator works in address space sizes, so it's multiplied by page
+	 * size. We allocate at the top of the GTT to avoid fragmentation.
+	 */
+	BUG_ON(!drm_mm_initialized(&dev_priv->gtt.base.mm));
+	ret = drm_mm_insert_node_in_range_generic(&dev_priv->gtt.base.mm,
+						  &ppgtt->node, GEN6_PD_SIZE,
+						  GEN6_PD_ALIGN, 0,
+						  0, dev_priv->gtt.base.total,
+						  DRM_MM_SEARCH_DEFAULT);
+	if (ret)
+		return ret;
+
+	if (ppgtt->node.start < dev_priv->gtt.mappable_end)
+		DRM_DEBUG("Forced to use aperture for PDEs\n");
 
 	ppgtt->base.pte_encode = dev_priv->gtt.base.pte_encode;
 	ppgtt->num_pd_entries = GEN6_PPGTT_PD_ENTRIES;
@@ -659,8 +671,10 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	ppgtt->base.total = GEN6_PPGTT_PD_ENTRIES * I915_PPGTT_PT_ENTRIES * PAGE_SIZE;
 	ppgtt->pt_pages = kcalloc(ppgtt->num_pd_entries, sizeof(struct page *),
 				  GFP_KERNEL);
-	if (!ppgtt->pt_pages)
+	if (!ppgtt->pt_pages) {
+		drm_mm_remove_node(&ppgtt->node);
 		return -ENOMEM;
+	}
 
 	for (i = 0; i < ppgtt->num_pd_entries; i++) {
 		ppgtt->pt_pages[i] = alloc_page(GFP_KERNEL);
@@ -690,7 +704,11 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	ppgtt->base.clear_range(&ppgtt->base, 0,
 				ppgtt->num_pd_entries * I915_PPGTT_PT_ENTRIES, true);
 
-	ppgtt->pd_offset = first_pd_entry_in_global_pt * sizeof(gen6_gtt_pte_t);
+	DRM_DEBUG_DRIVER("Allocated pde space (%ldM) at GTT entry: %lx\n",
+			 ppgtt->node.size >> 20,
+			 ppgtt->node.start / PAGE_SIZE);
+	ppgtt->pd_offset =
+		ppgtt->node.start / PAGE_SIZE * sizeof(gen6_gtt_pte_t);
 
 	return 0;
 
@@ -707,6 +725,7 @@ err_pt_alloc:
 			__free_page(ppgtt->pt_pages[i]);
 	}
 	kfree(ppgtt->pt_pages);
+	drm_mm_remove_node(&ppgtt->node);
 
 	return ret;
 }
@@ -1251,27 +1270,14 @@ void i915_gem_init_global_gtt(struct drm_device *dev)
 	gtt_size = dev_priv->gtt.base.total;
 	mappable_size = dev_priv->gtt.mappable_end;
 
+	i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
 	if (intel_enable_ppgtt(dev) && HAS_ALIASING_PPGTT(dev)) {
 		int ret;
 
-		if (INTEL_INFO(dev)->gen <= 7) {
-			/* PPGTT pdes are stolen from global gtt ptes, so shrink the
-			 * aperture accordingly when using aliasing ppgtt. */
-			gtt_size -= GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE;
-		}
-
-		i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
-
 		ret = i915_gem_init_aliasing_ppgtt(dev);
-		if (!ret)
-			return;
-
-		DRM_ERROR("Aliased PPGTT setup failed %d\n", ret);
-		drm_mm_takedown(&dev_priv->gtt.base.mm);
-		if (INTEL_INFO(dev)->gen < 8)
-			gtt_size += GEN6_PPGTT_PD_ENTRIES*PAGE_SIZE;
+		if (ret)
+			DRM_ERROR("Aliased PPGTT setup failed %d\n", ret);
 	}
-	i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
 }
 
 static int setup_scratch_page(struct drm_device *dev)
-- 
1.8.4.2

  parent reply	other threads:[~2013-12-06 22:17 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-06 21:55 [PULL] PPGTT Ben Widawsky
2013-12-06 22:10 ` [PATCH 01/48] drm/i915: Fix bad refcounting on execbuf failures Ben Widawsky
2013-12-06 22:10   ` [PATCH 02/48] drm/i915: Provide PDP updates via MMIO Ben Widawsky
2013-12-06 22:10   ` [PATCH 03/48] drm/i915: Don't unconditionally try to deref aliasing ppgtt Ben Widawsky
2013-12-18 13:50     ` Daniel Vetter
2013-12-06 22:10   ` [PATCH 04/48] drm/i915: Allow ggtt lookups to not WARN Ben Widawsky
2013-12-06 22:10   ` [PATCH 05/48] drm/i915: Takedown drm_mm on failed gtt setup Ben Widawsky
2013-12-06 22:10   ` [PATCH 06/48] drm/i915: Handle inactivating objects for all VMAs Ben Widawsky
2013-12-06 22:10   ` [PATCH 07/48] drm/i915: Add vm to error BO capture Ben Widawsky
2013-12-06 22:10   ` [PATCH 08/48] drm/i915: Don't use gtt mapping for !gtt error objects Ben Widawsky
2013-12-06 22:10   ` [PATCH 09/48] drm/i915: Identify active VM for batchbuffer capture Ben Widawsky
2013-12-06 22:10   ` [PATCH 10/48] drm/i915: Make pin count per VMA Ben Widawsky
2013-12-06 22:10   ` [PATCH 11/48] drm/i915: Create bind/unbind abstraction for VMAs Ben Widawsky
2013-12-06 22:10   ` [PATCH 12/48] drm/i915: Remove vm arg from relocate entry Ben Widawsky
2013-12-06 22:10   ` [PATCH 13/48] drm/i915: Add a context open function Ben Widawsky
2013-12-06 22:10   ` [PATCH 14/48] drm/i915: relax context alignment Ben Widawsky
2013-12-06 22:11   ` [PATCH 15/48] drm/i915: Simplify ring handling in execbuf Ben Widawsky
2013-12-06 22:11   ` [PATCH 16/48] drm/i915: Permit contexts on all rings Ben Widawsky
2013-12-06 22:11   ` [PATCH 17/48] drm/i915: Track which ring a context ran on Ben Widawsky
2014-04-18  9:51     ` Chris Wilson
2014-04-22 14:25       ` Daniel Vetter
2014-04-22 14:54         ` Chris Wilson
2013-12-06 22:11   ` [PATCH 18/48] drm/i915: Better reset handling for contexts Ben Widawsky
2013-12-18 14:21     ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 19/48] drm/i915: Split context enabling from init Ben Widawsky
2013-12-06 22:11   ` [PATCH 20/48] drm/i915: Generalize default context setup Ben Widawsky
2013-12-06 22:11   ` [PATCH 21/48] drm/i915: PPGTT vfuncs should take a ppgtt argument Ben Widawsky
2013-12-06 22:11   ` [PATCH 22/48] drm/i915: Use drm_mm for PPGTT PDEs Ben Widawsky
2013-12-06 22:11   ` [PATCH 23/48] drm/i915: One hopeful eviction on PPGTT alloc Ben Widawsky
2013-12-06 22:11   ` [PATCH 24/48] drm/i915: Use platform specific ppgtt enable Ben Widawsky
2013-12-06 22:11   ` [PATCH 25/48] drm/i915: Extract mm switching to function Ben Widawsky
2013-12-06 22:11   ` [PATCH 26/48] drm/i915: Use LRI for switching PP_DIR_BASE Ben Widawsky
2013-12-06 22:11   ` [PATCH 27/48] drm/i915: Flush TLBs after !RCS PP_DIR_BASE Ben Widawsky
2013-12-06 22:11   ` [PATCH 28/48] drm/i915: Generalize PPGTT init Ben Widawsky
2013-12-06 22:11   ` [PATCH 29/48] drm/i915: Reorganize intel_enable_ppgtt Ben Widawsky
2013-12-06 22:11   ` [PATCH 30/48] drm/i915: Add VM to context Ben Widawsky
2013-12-06 22:11   ` [PATCH 31/48] drm/i915: Write PDEs at init instead of enable Ben Widawsky
2013-12-06 22:11   ` [PATCH 32/48] drm/i915: Restore PDEs for all VMs Ben Widawsky
2013-12-06 22:11   ` [PATCH 33/48] drm/i915: Do aliasing PPGTT init with contexts Ben Widawsky
2013-12-06 22:11   ` [PATCH 34/48] drm/i915: Create a per file_priv default context Ben Widawsky
2013-12-06 22:11   ` [PATCH 35/48] drm/i915: Piggy back hangstats off of contexts Ben Widawsky
2013-12-06 22:11   ` [PATCH 36/48] drm/i915: Get context early in execbuf Ben Widawsky
2013-12-06 22:11   ` [PATCH 37/48] drm/i915: Defer request freeing Ben Widawsky
2013-12-12 11:08     ` Chris Wilson
2013-12-18 14:39       ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 38/48] drm/i915: Clean up VMAs before freeing Ben Widawsky
2013-12-18 14:55     ` Daniel Vetter
2013-12-18 14:56       ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 39/48] drm/i915: Do not allow buffers at offset 0 Ben Widawsky
2013-12-12 10:59     ` Chris Wilson
2013-12-18 14:58       ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 40/48] drm/i915: Add a tracepoint for new VMs Ben Widawsky
2013-12-18 14:59     ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 41/48] drm/i915: Use multiple VMs -- the point of no return Ben Widawsky
2013-12-06 22:11   ` [PATCH 42/48] drm/i915: Remove extraneous mm_switch in ppgtt enable Ben Widawsky
2013-12-06 22:11   ` [PATCH 43/48] drm/i915: Warn on gem_pin usage Ben Widawsky
2013-12-18 15:25     ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 44/48] drm/i915: Add PPGTT dumper Ben Widawsky
2013-12-06 22:11   ` [PATCH 45/48] drm/i915: Dump all ppgtt Ben Widawsky
2013-12-18 15:26     ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 46/48] drm: Optionally create mm blocks from top-to-bottom Ben Widawsky
2013-12-08 14:28     ` David Herrmann
2013-12-06 22:11   ` [PATCH 47/48] drm/i915: Use topdown allocation for PPGTT Ben Widawsky
2013-12-06 22:11   ` [PATCH 48/48] page allocator: Tmp OOM deadlock w/a from Chris Ben Widawsky
2013-12-06 22:11   ` [PATCH 01/48] drm/i915: Fix bad refcounting on execbuf failures Ben Widawsky
2013-12-06 22:11   ` [PATCH 02/48] drm/i915: Provide PDP updates via MMIO Ben Widawsky
2013-12-06 22:11   ` [PATCH 03/48] drm/i915: Don't unconditionally try to deref aliasing ppgtt Ben Widawsky
2013-12-06 22:11   ` [PATCH 04/48] drm/i915: Allow ggtt lookups to not WARN Ben Widawsky
2013-12-06 22:11   ` [PATCH 05/48] drm/i915: Takedown drm_mm on failed gtt setup Ben Widawsky
2013-12-06 22:11   ` [PATCH 06/48] drm/i915: Handle inactivating objects for all VMAs Ben Widawsky
2013-12-06 22:11   ` [PATCH 07/48] drm/i915: Add vm to error BO capture Ben Widawsky
2013-12-06 22:11   ` [PATCH 08/48] drm/i915: Don't use gtt mapping for !gtt error objects Ben Widawsky
2013-12-06 22:11   ` [PATCH 09/48] drm/i915: Identify active VM for batchbuffer capture Ben Widawsky
2013-12-06 22:11   ` [PATCH 10/48] drm/i915: Make pin count per VMA Ben Widawsky
2013-12-06 22:11   ` [PATCH 11/48] drm/i915: Create bind/unbind abstraction for VMAs Ben Widawsky
2013-12-06 22:11   ` [PATCH 12/48] drm/i915: Remove vm arg from relocate entry Ben Widawsky
2013-12-06 22:11   ` [PATCH 13/48] drm/i915: Add a context open function Ben Widawsky
2013-12-06 22:11   ` [PATCH 14/48] drm/i915: relax context alignment Ben Widawsky
2013-12-06 22:11   ` [PATCH 15/48] drm/i915: Simplify ring handling in execbuf Ben Widawsky
2013-12-06 22:11   ` [PATCH 16/48] drm/i915: Permit contexts on all rings Ben Widawsky
2013-12-06 22:11   ` [PATCH 17/48] drm/i915: Track which ring a context ran on Ben Widawsky
2013-12-06 22:11   ` [PATCH 18/48] drm/i915: Better reset handling for contexts Ben Widawsky
2013-12-06 22:11   ` [PATCH 19/48] drm/i915: Split context enabling from init Ben Widawsky
2013-12-06 22:11   ` [PATCH 20/48] drm/i915: Generalize default context setup Ben Widawsky
2013-12-06 22:11   ` [PATCH 21/48] drm/i915: PPGTT vfuncs should take a ppgtt argument Ben Widawsky
2013-12-06 22:11   ` Ben Widawsky [this message]
2014-03-20 11:10     ` [PATCH 22/48] drm/i915: Use drm_mm for PPGTT PDEs Chris Wilson
2014-03-24 19:36       ` Ben Widawsky
2014-03-24 19:45         ` Chris Wilson
2014-03-24 20:02           ` Ben Widawsky
2014-03-25 13:41             ` Chris Wilson
2014-03-25 15:33               ` Daniel Vetter
2013-12-06 22:11   ` [PATCH 23/48] drm/i915: One hopeful eviction on PPGTT alloc Ben Widawsky
2014-03-20 11:12     ` Chris Wilson
2013-12-06 22:11   ` [PATCH 24/48] drm/i915: Use platform specific ppgtt enable Ben Widawsky
2013-12-06 22:11   ` [PATCH 25/48] drm/i915: Extract mm switching to function Ben Widawsky
2013-12-06 22:11   ` [PATCH 26/48] drm/i915: Use LRI for switching PP_DIR_BASE Ben Widawsky
2013-12-06 22:12   ` [PATCH 27/48] drm/i915: Flush TLBs after !RCS PP_DIR_BASE Ben Widawsky
2013-12-06 22:12   ` [PATCH 28/48] drm/i915: Generalize PPGTT init Ben Widawsky
2013-12-06 22:12   ` [PATCH 29/48] drm/i915: Reorganize intel_enable_ppgtt Ben Widawsky
2013-12-06 22:12   ` [PATCH 30/48] drm/i915: Add VM to context Ben Widawsky
2013-12-06 22:12   ` [PATCH 31/48] drm/i915: Write PDEs at init instead of enable Ben Widawsky
2013-12-06 22:12   ` [PATCH 32/48] drm/i915: Restore PDEs for all VMs Ben Widawsky
2013-12-06 22:12   ` [PATCH 33/48] drm/i915: Do aliasing PPGTT init with contexts Ben Widawsky
2013-12-06 22:12   ` [PATCH 34/48] drm/i915: Create a per file_priv default context Ben Widawsky
2013-12-06 22:12   ` [PATCH 35/48] drm/i915: Piggy back hangstats off of contexts Ben Widawsky
2013-12-06 22:12   ` [PATCH 36/48] drm/i915: Get context early in execbuf Ben Widawsky
2013-12-06 22:12   ` [PATCH 37/48] drm/i915: Defer request freeing Ben Widawsky
2013-12-06 22:12   ` [PATCH 38/48] drm/i915: Clean up VMAs before freeing Ben Widawsky
2013-12-06 22:12   ` [PATCH 39/48] drm/i915: Do not allow buffers at offset 0 Ben Widawsky
2013-12-06 22:12   ` [PATCH 40/48] drm/i915: Add a tracepoint for new VMs Ben Widawsky
2013-12-06 22:12   ` [PATCH 41/48] drm/i915: Use multiple VMs -- the point of no return Ben Widawsky
2013-12-06 22:12   ` [PATCH 42/48] drm/i915: Remove extraneous mm_switch in ppgtt enable Ben Widawsky
2013-12-06 22:12   ` [PATCH 43/48] drm/i915: Warn on gem_pin usage Ben Widawsky
2013-12-06 22:12   ` [PATCH 44/48] drm/i915: Add PPGTT dumper Ben Widawsky
2013-12-06 22:12   ` [PATCH 45/48] drm/i915: Dump all ppgtt Ben Widawsky
2013-12-06 22:12   ` [PATCH 46/48] drm: Optionally create mm blocks from top-to-bottom Ben Widawsky
2013-12-06 22:12   ` [PATCH 47/48] drm/i915: Use topdown allocation for PPGTT Ben Widawsky
2013-12-06 22:12   ` [PATCH 48/48] page allocator: Tmp OOM deadlock w/a from Chris Ben Widawsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386367941-7131-70-git-send-email-benjamin.widawsky@intel.com \
    --to=benjamin.widawsky@intel.com \
    --cc=ben@bwidawsk.net \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.