All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 18/23] drm/i915: Keep all partially allocated HWSP on a freelist
Date: Fri, 18 Jan 2019 14:12:58 +0200	[thread overview]
Message-ID: <87h8e6w4dx.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <20190117143519.16086-19-chris@chris-wilson.co.uk>

Chris Wilson <chris@chris-wilson.co.uk> writes:

> Keep track of partially allocated pages for use in allocating future
> timeline HWSP. This is still without migration, so it is possible for

timeline from HWSP?

> the system to end up with each timeline in its own page, but we ensure
> that no new allocation would needless allocate a fresh page!

s/needless/needlessly.
-Mika

>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: John Harrison <John.C.Harrison@Intel.com>
> ---
>  drivers/gpu/drm/i915/i915_drv.h      |  3 +-
>  drivers/gpu/drm/i915/i915_timeline.c | 81 +++++++++++++++++-----------
>  2 files changed, 50 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index d59228dabb6e..0bebef428f1e 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1981,8 +1981,7 @@ struct drm_i915_private {
>  
>  			/* Pack multiple timelines' seqnos into the same page */
>  			spinlock_t hwsp_lock;
> -			struct i915_vma *hwsp;
> -			u64 bitmap;
> +			struct list_head hwsp;
>  		} timelines;
>  
>  		struct list_head active_rings;
> diff --git a/drivers/gpu/drm/i915/i915_timeline.c b/drivers/gpu/drm/i915/i915_timeline.c
> index e939a9e1a4ab..64bb1ce24318 100644
> --- a/drivers/gpu/drm/i915/i915_timeline.c
> +++ b/drivers/gpu/drm/i915/i915_timeline.c
> @@ -9,74 +9,94 @@
>  #include "i915_timeline.h"
>  #include "i915_syncmap.h"
>  
> +struct i915_timeline_hwsp {
> +	struct list_head link;
> +	struct i915_vma *vma;
> +	u64 bitmap;
> +};
> +
>  static int hwsp_alloc(struct i915_timeline *timeline)
>  {
> -#define NBITS BITS_PER_TYPE(typeof(gt->bitmap))
>  	struct drm_i915_private *i915 = timeline->i915;
>  	struct i915_gt_timelines *gt = &i915->gt.timelines;
> -	struct i915_vma *vma;
> +	struct i915_timeline_hwsp *hwsp;
>  	int offset;
>  
>  	spin_lock(&gt->hwsp_lock);
>  
> -restart:
> -	offset = find_first_bit((unsigned long *)&gt->bitmap, NBITS);
> -	if (offset == NBITS && gt->hwsp) {
> -		i915_vma_put(gt->hwsp);
> -		gt->hwsp = NULL;
> -	}
> -
> -	vma = gt->hwsp;
> -	if (!vma) {
> +	hwsp = list_first_entry_or_null(&gt->hwsp, typeof(*hwsp), link);
> +	if (!hwsp) {
>  		struct drm_i915_gem_object *bo;
> +		struct i915_vma *vma;
>  
>  		spin_unlock(&gt->hwsp_lock);
>  
> -		BUILD_BUG_ON(NBITS * CACHELINE_BYTES > PAGE_SIZE);
> +		hwsp = kmalloc(sizeof(*hwsp), GFP_KERNEL);
> +		if (!hwsp)
> +			return -ENOMEM;
> +
> +		BUILD_BUG_ON(BITS_PER_TYPE(hwsp->bitmap) * CACHELINE_BYTES > PAGE_SIZE);
>  		bo = i915_gem_object_create_internal(i915, PAGE_SIZE);
> -		if (IS_ERR(bo))
> +		if (IS_ERR(bo)) {
> +			kfree(hwsp);
>  			return PTR_ERR(bo);
> +		}
>  
>  		i915_gem_object_set_cache_level(bo, I915_CACHE_LLC);
>  
>  		vma = i915_vma_instance(bo, &i915->ggtt.vm, NULL);
>  		if (IS_ERR(vma)) {
>  			i915_gem_object_put(bo);
> +			kfree(hwsp);
>  			return PTR_ERR(vma);
>  		}
>  
> -		spin_lock(&gt->hwsp_lock);
> -		if (gt->hwsp) {
> -			i915_gem_object_put(bo);
> -			goto restart;
> -		}
> +		vma->private = hwsp;
> +		hwsp->vma = vma;
> +		hwsp->bitmap = ~0ull;
>  
> -		gt->hwsp = vma;
> -		gt->bitmap = ~0ull;
> -		offset = 0;
> +		spin_lock(&gt->hwsp_lock);
> +		list_add(&hwsp->link, &gt->hwsp);
>  	}
>  
> -	gt->bitmap &= ~BIT_ULL(offset);
> +	GEM_BUG_ON(!hwsp->bitmap);
> +	offset = __ffs64(hwsp->bitmap);
> +	hwsp->bitmap &= ~BIT_ULL(offset);
> +	if (!hwsp->bitmap)
> +		list_del(&hwsp->link);
>  
>  	spin_unlock(&gt->hwsp_lock);
>  
> -	timeline->hwsp_ggtt = i915_vma_get(vma);
> +	timeline->hwsp_ggtt = i915_vma_get(hwsp->vma);
>  	timeline->hwsp_offset = offset * CACHELINE_BYTES;
>  
> +	GEM_BUG_ON(timeline->hwsp_ggtt->private != hwsp);
> +
>  	return 0;
> -#undef NBITS
>  }
>  
>  static void hwsp_free(struct i915_timeline *timeline)
>  {
>  	struct i915_gt_timelines *gt = &timeline->i915->gt.timelines;
> +	struct i915_timeline_hwsp *hwsp;
>  
> -	if (timeline->hwsp_ggtt != gt->hwsp)
> +	hwsp = timeline->hwsp_ggtt->private;
> +	if (!hwsp)
>  		return;
>  
>  	spin_lock(&gt->hwsp_lock);
> -	if (timeline->hwsp_ggtt == gt->hwsp)
> -		gt->bitmap |= BIT_ULL(timeline->hwsp_offset / CACHELINE_BYTES);
> +
> +	if (!hwsp->bitmap)
> +		list_add_tail(&hwsp->link, &gt->hwsp);
> +
> +	hwsp->bitmap |= BIT_ULL(timeline->hwsp_offset / CACHELINE_BYTES);
> +
> +	if (hwsp->bitmap == ~0ull) {
> +		i915_vma_put(hwsp->vma);
> +		list_del(&hwsp->link);
> +		kfree(hwsp);
> +	}
> +
>  	spin_unlock(&gt->hwsp_lock);
>  }
>  
> @@ -148,6 +168,7 @@ void i915_timelines_init(struct drm_i915_private *i915)
>  	INIT_LIST_HEAD(&gt->list);
>  
>  	spin_lock_init(&gt->hwsp_lock);
> +	INIT_LIST_HEAD(&gt->hwsp);
>  
>  	/* via i915_gem_wait_for_idle() */
>  	i915_gem_shrinker_taints_mutex(i915, &gt->mutex);
> @@ -264,13 +285,9 @@ void __i915_timeline_free(struct kref *kref)
>  void i915_timelines_fini(struct drm_i915_private *i915)
>  {
>  	struct i915_gt_timelines *gt = &i915->gt.timelines;
> -	struct i915_vma *vma;
>  
>  	GEM_BUG_ON(!list_empty(&gt->list));
> -
> -	vma = fetch_and_zero(&i915->gt.timelines.hwsp);
> -	if (vma)
> -		i915_vma_put(vma);
> +	GEM_BUG_ON(!list_empty(&gt->hwsp));
>  
>  	mutex_destroy(&gt->mutex);
>  }
> -- 
> 2.20.1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-01-18 12:14 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17 14:34 Swapping a single global interrupt handler for a herd Chris Wilson
2019-01-17 14:34 ` [PATCH 01/23] drm/i915: Make all GPU resets atomic Chris Wilson
2019-01-17 14:34 ` [PATCH 02/23] drm/i915/guc: Disable global reset Chris Wilson
2019-01-17 14:34 ` [PATCH 03/23] drm/i915: Remove GPU reset dependence on struct_mutex Chris Wilson
2019-01-17 14:34 ` [PATCH 04/23] drm/i915/selftests: Trim struct_mutex duration for set-wedged selftest Chris Wilson
2019-01-17 14:34 ` [PATCH 05/23] drm/i915: Issue engine resets onto idle engines Chris Wilson
2019-01-18 12:06   ` Mika Kuoppala
2019-01-17 14:34 ` [PATCH 06/23] drm/i915: Stop tracking MRU activity on VMA Chris Wilson
2019-01-17 14:34 ` [PATCH 07/23] drm/i915: Pull VM lists under the VM mutex Chris Wilson
2019-01-18 10:07   ` Tvrtko Ursulin
2019-01-17 14:34 ` [PATCH 08/23] drm/i915: Move vma lookup to its own lock Chris Wilson
2019-01-17 16:27   ` Tvrtko Ursulin
2019-01-17 16:31     ` Chris Wilson
2019-01-17 16:36       ` Chris Wilson
2019-01-17 16:51         ` Tvrtko Ursulin
2019-01-17 16:44     ` Chris Wilson
2019-01-17 14:34 ` [PATCH 09/23] drm/i915: Use b->irq_enable() as predicate for mock engine Chris Wilson
2019-01-17 16:44   ` Tvrtko Ursulin
2019-01-17 16:52     ` Chris Wilson
2019-01-17 18:00       ` Tvrtko Ursulin
2019-01-17 14:34 ` [PATCH 10/23] drm/i915/selftests: Allocate mock ring/timeline per context Chris Wilson
2019-01-17 14:34 ` [PATCH 11/23] drm/i915/selftests: Make evict tolerant of foreign objects Chris Wilson
2019-01-17 17:29   ` Tvrtko Ursulin
2019-01-18 11:23     ` Chris Wilson
2019-01-17 14:34 ` [PATCH 12/23] drm/i915: Always allocate an object/vma for the HWSP Chris Wilson
2019-01-17 14:34 ` [PATCH 13/23] drm/i915: Move list of timelines under its own lock Chris Wilson
2019-01-17 17:54   ` Tvrtko Ursulin
2019-01-18 11:31     ` Chris Wilson
2019-01-17 14:34 ` [PATCH 14/23] drm/i915: Introduce concept of per-timeline (context) HWSP Chris Wilson
2019-01-18 10:18   ` Tvrtko Ursulin
2019-01-17 14:34 ` [PATCH 15/23] drm/i915: Enlarge vma->pin_count Chris Wilson
2019-01-17 14:34 ` [PATCH 16/23] drm/i915: Allocate a status page for each timeline Chris Wilson
2019-01-18 11:19   ` Tvrtko Ursulin
2019-01-17 14:34 ` [PATCH 17/23] drm/i915: Share per-timeline HWSP using a slab suballocator Chris Wilson
2019-01-18 12:08   ` Tvrtko Ursulin
2019-01-17 14:34 ` [PATCH 18/23] drm/i915: Keep all partially allocated HWSP on a freelist Chris Wilson
2019-01-18 12:12   ` Mika Kuoppala [this message]
2019-01-18 12:25   ` Tvrtko Ursulin
2019-01-17 14:35 ` [PATCH 19/23] drm/i915: Track the context's seqno in its own timeline HWSP Chris Wilson
2019-01-18 14:10   ` Tvrtko Ursulin
2019-01-17 14:35 ` [PATCH 20/23] drm/i915: Identify active requests Chris Wilson
2019-01-17 14:35 ` [PATCH 21/23] drm/i915: Remove the intel_engine_notify tracepoint Chris Wilson
2019-01-17 14:35 ` [PATCH 22/23] drm/i915: Replace global breadcrumbs with per-context interrupt tracking Chris Wilson
2019-01-17 14:35 ` [PATCH 23/23] drm/i915: Drop fake breadcrumb irq Chris Wilson
2019-01-17 14:37 ` Swapping a single global interrupt handler for a herd Chris Wilson
2019-01-17 14:56 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/23] drm/i915: Make all GPU resets atomic Patchwork
2019-01-17 15:05 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-01-17 15:38 ` ✓ Fi.CI.BAT: success " Patchwork
2019-01-17 23:36 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-01-17 23:41   ` Chris Wilson

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=87h8e6w4dx.fsf@gaia.fi.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --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.