intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jesse Barnes <jbarnes@virtuousgeek.org>
To: Ben Widawsky <ben@bwidawsk.net>
Cc: Intel GFX <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 07/66] drm/i915: Use drm_mm for PPGTT PDEs
Date: Fri, 28 Jun 2013 11:01:13 -0700	[thread overview]
Message-ID: <20130628110113.2a07de59@jbarnes-desktop> (raw)
In-Reply-To: <1372375867-1003-8-git-send-email-ben@bwidawsk.net>

On Thu, 27 Jun 2013 16:30:08 -0700
Ben Widawsky <ben@bwidawsk.net> wrote:

> 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.
> 
> 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)
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>
> Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
> ---
>  drivers/gpu/drm/i915/i915_drv.h     |  1 +
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 45 ++++++++++++++++++++++++-------------
>  2 files changed, 31 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index c677d6c..659b4aa 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -484,6 +484,7 @@ struct i915_gtt {
>  #define gtt_total_entries(gtt) ((gtt).total >> PAGE_SHIFT)
>  
>  struct i915_hw_ppgtt {
> +	struct drm_mm_node node;
>  	struct drm_device *dev;
>  	unsigned num_pd_entries;
>  	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 fb30d65..5284dc5 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -247,6 +247,8 @@ static void gen6_ppgtt_cleanup(struct i915_hw_ppgtt *ppgtt)
>  {
>  	int i;
>  
> +	drm_mm_remove_node(&ppgtt->node);
> +
>  	if (ppgtt->pt_dma_addr) {
>  		for (i = 0; i < ppgtt->num_pd_entries; i++)
>  			pci_unmap_page(ppgtt->dev->pdev,
> @@ -263,16 +265,27 @@ static void gen6_ppgtt_cleanup(struct i915_hw_ppgtt *ppgtt)
>  
>  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->dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> -	unsigned first_pd_entry_in_global_pt;
>  	int i;
>  	int ret = -ENOMEM;
>  
> -	/* 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 stolen space, 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->mm.gtt_space));
> +	ret = drm_mm_insert_node_in_range_generic(&dev_priv->mm.gtt_space,
> +						  &ppgtt->node, GEN6_PD_SIZE,
> +						  GEN6_PD_ALIGN, 0,
> +						  dev_priv->gtt.mappable_end,
> +						  dev_priv->gtt.total,
> +						  DRM_MM_TOPDOWN);
> +	if (ret)
> +		return ret;
>  
>  	if (IS_HASWELL(dev)) {
>  		ppgtt->pte_encode = hsw_pte_encode;
> @@ -288,8 +301,10 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
>  	ppgtt->cleanup = gen6_ppgtt_cleanup;
>  	ppgtt->pt_pages = kzalloc(sizeof(struct page *)*ppgtt->num_pd_entries,
>  				  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);
> @@ -319,7 +334,11 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
>  	ppgtt->clear_range(ppgtt, 0,
>  			   ppgtt->num_pd_entries*I915_PPGTT_PT_ENTRIES);
>  
> -	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;
>  
> @@ -336,6 +355,7 @@ err_pt_alloc:
>  			__free_page(ppgtt->pt_pages[i]);
>  	}
>  	kfree(ppgtt->pt_pages);
> +	drm_mm_remove_node(&ppgtt->node);
>  
>  	return ret;
>  }
> @@ -442,6 +462,9 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
>  	dev_priv->gtt.gtt_clear_range(dev, dev_priv->gtt.start / PAGE_SIZE,
>  				      dev_priv->gtt.total / PAGE_SIZE);
>  
> +	if (dev_priv->mm.aliasing_ppgtt)
> +		gen6_write_pdes(dev_priv->mm.aliasing_ppgtt);
> +
>  	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
>  		i915_gem_clflush_object(obj);
>  		i915_gem_gtt_bind_object(obj, obj->cache_level);
> @@ -711,21 +734,13 @@ void i915_gem_init_global_gtt(struct drm_device *dev)
>  	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, 0);
> -
>  		ret = i915_gem_init_aliasing_ppgtt(dev);
>  		if (!ret)
>  			return;
>  
>  		DRM_ERROR("Aliased PPGTT setup failed %d\n", ret);
>  		drm_mm_takedown(&dev_priv->mm.gtt_space);
> -		gtt_size += GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE;
>  	}
>  	i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size, PAGE_SIZE);
>  }

Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>

-- 
Jesse Barnes, Intel Open Source Technology Center

  reply	other threads:[~2013-06-28 18:56 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27 23:30 [PATCH 00/66] [v1] Full PPGTT minus soft pin Ben Widawsky
2013-06-27 23:30 ` [PATCH 01/66] drm/i915: Remove extra error state NULL Ben Widawsky
2013-06-27 23:30 ` [PATCH 02/66] drm/i915: Extract error buffer capture Ben Widawsky
2013-06-27 23:30 ` [PATCH 03/66] drm/i915: make PDE|PTE platform specific Ben Widawsky
2013-06-28 16:53   ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 04/66] drm: Optionally create mm blocks from top-to-bottom Ben Widawsky
2013-06-30 12:30   ` Daniel Vetter
2013-06-30 12:40     ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 05/66] drm/i915: Don't clear gtt with 0 entries Ben Widawsky
2013-06-27 23:30 ` [PATCH 06/66] drm/i915: Conditionally use guard page based on PPGTT Ben Widawsky
2013-06-28 17:57   ` Jesse Barnes
2013-06-27 23:30 ` [PATCH 07/66] drm/i915: Use drm_mm for PPGTT PDEs Ben Widawsky
2013-06-28 18:01   ` Jesse Barnes [this message]
2013-06-27 23:30 ` [PATCH 08/66] drm/i915: cleanup context fini Ben Widawsky
2013-06-27 23:30 ` [PATCH 09/66] drm/i915: Do a fuller init after reset Ben Widawsky
2013-06-27 23:30 ` [PATCH 10/66] drm/i915: Split context enabling from init Ben Widawsky
2013-06-27 23:30 ` [PATCH 11/66] drm/i915: destroy i915_gem_init_global_gtt Ben Widawsky
2013-06-27 23:30 ` [PATCH 12/66] drm/i915: Embed PPGTT into the context Ben Widawsky
2013-06-27 23:30 ` [PATCH 13/66] drm/i915: Unify PPGTT codepaths on gen6+ Ben Widawsky
2013-06-27 23:30 ` [PATCH 14/66] drm/i915: Move ppgtt initialization down Ben Widawsky
2013-06-27 23:30 ` [PATCH 15/66] drm/i915: Tie context to PPGTT Ben Widawsky
2013-06-27 23:30 ` [PATCH 16/66] drm/i915: Really share scratch page Ben Widawsky
2013-06-27 23:30 ` [PATCH 17/66] drm/i915: Combine scratch members into a struct Ben Widawsky
2013-06-27 23:30 ` [PATCH 18/66] drm/i915: Drop dev from pte_encode Ben Widawsky
2013-06-27 23:30 ` [PATCH 19/66] drm/i915: Use gtt shortform where possible Ben Widawsky
2013-06-27 23:30 ` [PATCH 20/66] drm/i915: Move fbc members out of line Ben Widawsky
2013-06-30 13:10   ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 21/66] drm/i915: Move gtt and ppgtt under address space umbrella Ben Widawsky
2013-06-30 13:12   ` Daniel Vetter
2013-07-01 18:40     ` Ben Widawsky
2013-07-01 18:48       ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 22/66] drm/i915: Move gtt_mtrr to i915_gtt Ben Widawsky
2013-06-27 23:30 ` [PATCH 23/66] drm/i915: Move stolen stuff " Ben Widawsky
2013-06-30 13:18   ` Daniel Vetter
2013-07-01 18:43     ` Ben Widawsky
2013-07-01 18:51       ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 24/66] drm/i915: Move aliasing_ppgtt Ben Widawsky
2013-06-30 13:27   ` Daniel Vetter
2013-07-01 18:52     ` Ben Widawsky
2013-07-01 19:06       ` Daniel Vetter
2013-07-01 19:48         ` Ben Widawsky
2013-07-01 19:54           ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 25/66] drm/i915: Put the mm in the parent address space Ben Widawsky
2013-06-27 23:30 ` [PATCH 26/66] drm/i915: Move active/inactive lists to new mm Ben Widawsky
2013-06-30 15:38   ` Daniel Vetter
2013-07-01 22:56     ` Ben Widawsky
2013-07-02  7:26       ` Daniel Vetter
2013-07-02 16:47         ` Ben Widawsky
2013-06-27 23:30 ` [PATCH 27/66] drm/i915: Create a global list of vms Ben Widawsky
2013-06-27 23:30 ` [PATCH 28/66] drm/i915: Remove object's gtt_offset Ben Widawsky
2013-06-27 23:30 ` [PATCH 29/66] drm: pre allocate node for create_block Ben Widawsky
2013-06-30 12:34   ` Daniel Vetter
2013-07-01 18:30     ` Ben Widawsky
2013-06-27 23:30 ` [PATCH 30/66] drm/i915: Getter/setter for object attributes Ben Widawsky
2013-06-30 13:00   ` Daniel Vetter
2013-07-01 18:32     ` Ben Widawsky
2013-07-01 18:43       ` Daniel Vetter
2013-07-01 19:08         ` Daniel Vetter
2013-07-01 22:59           ` Ben Widawsky
2013-07-02  7:28             ` Daniel Vetter
2013-07-02 16:51               ` Ben Widawsky
2013-07-02 17:07                 ` Daniel Vetter
2013-06-27 23:30 ` [PATCH 31/66] drm/i915: Create VMAs (part 1) Ben Widawsky
2013-06-27 23:30 ` [PATCH 32/66] drm/i915: Create VMAs (part 2) - kill gtt space Ben Widawsky
2013-06-27 23:30 ` [PATCH 33/66] drm/i915: Create VMAs (part 3) - plumbing Ben Widawsky
2013-06-27 23:30 ` [PATCH 34/66] drm/i915: Create VMAs (part 3.5) - map and fenceable tracking Ben Widawsky
2013-06-27 23:30 ` [PATCH 35/66] drm/i915: Create VMAs (part 4) - Error capture Ben Widawsky
2013-06-27 23:30 ` [PATCH 36/66] drm/i915: Create VMAs (part 5) - move mm_list Ben Widawsky
2013-06-27 23:30 ` [PATCH 37/66] drm/i915: Create VMAs (part 6) - finish error plumbing Ben Widawsky
2013-06-27 23:30 ` [PATCH 38/66] drm/i915: create an object_is_active() Ben Widawsky
2013-06-27 23:30 ` [PATCH 39/66] drm/i915: Move active to vma Ben Widawsky
2013-06-27 23:30 ` [PATCH 40/66] drm/i915: Track all VMAs per VM Ben Widawsky
2013-06-30 15:35   ` Daniel Vetter
2013-07-01 19:04     ` Ben Widawsky
2013-06-27 23:30 ` [PATCH 41/66] drm/i915: Defer request freeing Ben Widawsky
2013-06-27 23:30 ` [PATCH 42/66] drm/i915: Clean up VMAs before freeing Ben Widawsky
2013-07-02 10:59   ` Ville Syrjälä
2013-07-02 16:58     ` Ben Widawsky
2013-06-27 23:30 ` [PATCH 43/66] drm/i915: Replace has_bsd/blt with a mask Ben Widawsky
2013-06-27 23:30 ` [PATCH 44/66] drm/i915: Catch missed context unref earlier Ben Widawsky
2013-06-27 23:30 ` [PATCH 45/66] drm/i915: Add a context open function Ben Widawsky
2013-06-27 23:30 ` [PATCH 46/66] drm/i915: Permit contexts on all rings Ben Widawsky
2013-06-27 23:30 ` [PATCH 47/66] drm/i915: Fix context fini refcounts Ben Widawsky
2013-06-27 23:30 ` [PATCH 48/66] drm/i915: Better reset handling for contexts Ben Widawsky
2013-06-27 23:30 ` [PATCH 49/66] drm/i915: Create a per file_priv default context Ben Widawsky
2013-06-27 23:30 ` [PATCH 50/66] drm/i915: Remove ring specificity from contexts Ben Widawsky
2013-06-27 23:30 ` [PATCH 51/66] drm/i915: Track which ring a context ran on Ben Widawsky
2013-06-27 23:30 ` [PATCH 52/66] drm/i915: dump error state based on capture Ben Widawsky
2013-06-27 23:30 ` [PATCH 53/66] drm/i915: PPGTT should take a ppgtt argument Ben Widawsky
2013-06-27 23:30 ` [PATCH 54/66] drm/i915: USE LRI for switching PP_DIR_BASE Ben Widawsky
2013-06-27 23:30 ` [PATCH 55/66] drm/i915: Extract mm switching to function Ben Widawsky
2013-06-27 23:30 ` [PATCH 56/66] drm/i915: Write PDEs at init instead of enable Ben Widawsky
2013-06-27 23:30 ` [PATCH 57/66] drm/i915: Disallow pin with full ppgtt Ben Widawsky
2013-06-28  8:55   ` Chris Wilson
2013-06-29  5:43     ` Ben Widawsky
2013-06-29  6:44       ` Chris Wilson
2013-06-29 14:34         ` Daniel Vetter
2013-06-30  6:56           ` Ben Widawsky
2013-06-30 11:06             ` Daniel Vetter
2013-06-30 11:31               ` Chris Wilson
2013-06-30 11:36                 ` Daniel Vetter
2013-07-01 18:27                   ` Ben Widawsky
2013-06-27 23:30 ` [PATCH 58/66] drm/i915: Get context early in execbuf Ben Widawsky
2013-06-27 23:31 ` [PATCH 59/66] drm/i915: Pass ctx directly to switch/hangstat Ben Widawsky
2013-06-27 23:31 ` [PATCH 60/66] drm/i915: Actually add the new address spaces Ben Widawsky
2013-06-27 23:31 ` [PATCH 61/66] drm/i915: Use multiple VMs Ben Widawsky
2013-06-27 23:43   ` Ben Widawsky
2013-07-02 10:58     ` Ville Syrjälä
2013-07-02 11:07       ` Chris Wilson
2013-07-02 11:34         ` Ville Syrjälä
2013-07-02 11:38           ` Chris Wilson
2013-07-02 12:34             ` Daniel Vetter
2013-06-27 23:31 ` [PATCH 62/66] drm/i915: Kill now unused ppgtt_{un, }bind Ben Widawsky
2013-06-27 23:31 ` [PATCH 63/66] drm/i915: Add PPGTT dumper Ben Widawsky
2013-06-27 23:31 ` [PATCH 64/66] drm/i915: Dump all ppgtt Ben Widawsky
2013-06-27 23:31 ` [PATCH 65/66] drm/i915: Add debugfs for vma info per vm Ben Widawsky
2013-06-27 23:31 ` [PATCH 66/66] drm/i915: Getparam full ppgtt Ben Widawsky
2013-06-28  3:38 ` [PATCH 00/66] [v1] Full PPGTT minus soft pin Ben Widawsky
2013-07-01 21:39 ` Daniel Vetter
2013-07-01 22:36   ` Ben Widawsky
2013-07-02  7:43     ` Daniel Vetter
2013-10-29 23:08   ` Eric Anholt
2013-10-30  0:10     ` Jesse Barnes
2013-11-01 17:20       ` Jesse Barnes

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=20130628110113.2a07de59@jbarnes-desktop \
    --to=jbarnes@virtuousgeek.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).