Re: [Intel-gfx] [RFC 4/4] drm/i915: Stop tracking execlists retired requests

2016-04-11 Thread Chris Wilson
On Mon, Apr 11, 2016 at 10:10:56AM +0100, Tvrtko Ursulin wrote:
> 
> On 08/04/16 15:57, Chris Wilson wrote:
> >On Fri, Apr 08, 2016 at 02:54:58PM +0100, Tvrtko Ursulin wrote:
> >>@@ -615,11 +613,6 @@ static void execlists_context_queue(struct 
> >>drm_i915_gem_request *request)
> >>struct drm_i915_gem_request *cursor;
> >>int num_elements = 0;
> >>
> >>-   if (request->ctx != request->i915->kernel_context)
> >>-   intel_lr_context_pin(request->ctx, engine);
> >>-
> >>-   i915_gem_request_reference(request);
> >>-
> >>spin_lock_bh(>execlist_lock);
> >>
> >>list_for_each_entry(cursor, >execlist_queue, execlist_link)
> >>@@ -636,11 +629,12 @@ static void execlists_context_queue(struct 
> >>drm_i915_gem_request *request)
> >>if (request->ctx == tail_req->ctx) {
> >>WARN(tail_req->elsp_submitted != 0,
> >>"More than 2 already-submitted reqs queued\n");
> >>-   list_move_tail(_req->execlist_link,
> >>-  >execlist_retired_req_list);
> >>+   list_del(_req->execlist_link);
> >>+   i915_gem_request_unreference(tail_req);
> >>}
> >>}
> >>
> >>+   i915_gem_request_reference(request);
> >>list_add_tail(>execlist_link, >execlist_queue);
> >
> >If you want to get truly radical, we do not need the ref on the request
> >until it is submitted to hardware. (As the request cannot be retired
> >until it has done so, it can leave the execlist_queue until we commit it
> >to hw, or perform the cancel).
> 
> Don't know. It is simple and nice that reference is tied to presence
> on execlist_queue.
> 
> More importantly, the patch as presented has a flaw that it
> dereferences req->ctx from execlists_check_remove_request where the
> context pin may have disappeared already due context complete
> interrupts getting behind when coallescing.
> 
> I will need to cache ctx_id in the request I think. It is fine do to
> that since ctx id must be unique and stable for a request.

For comparison, tracking by requests rather than contexts:

https://cgit.freedesktop.org/~ickle/linux-2.6/commit/?h=tasklet=e23791ef88636aa6e3f850b61ab2c4e027af0e52
-Chris
> 

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [RFC 4/4] drm/i915: Stop tracking execlists retired requests

2016-04-11 Thread Chris Wilson
On Mon, Apr 11, 2016 at 10:10:56AM +0100, Tvrtko Ursulin wrote:
> 
> On 08/04/16 15:57, Chris Wilson wrote:
> >On Fri, Apr 08, 2016 at 02:54:58PM +0100, Tvrtko Ursulin wrote:
> >>@@ -615,11 +613,6 @@ static void execlists_context_queue(struct 
> >>drm_i915_gem_request *request)
> >>struct drm_i915_gem_request *cursor;
> >>int num_elements = 0;
> >>
> >>-   if (request->ctx != request->i915->kernel_context)
> >>-   intel_lr_context_pin(request->ctx, engine);
> >>-
> >>-   i915_gem_request_reference(request);
> >>-
> >>spin_lock_bh(>execlist_lock);
> >>
> >>list_for_each_entry(cursor, >execlist_queue, execlist_link)
> >>@@ -636,11 +629,12 @@ static void execlists_context_queue(struct 
> >>drm_i915_gem_request *request)
> >>if (request->ctx == tail_req->ctx) {
> >>WARN(tail_req->elsp_submitted != 0,
> >>"More than 2 already-submitted reqs queued\n");
> >>-   list_move_tail(_req->execlist_link,
> >>-  >execlist_retired_req_list);
> >>+   list_del(_req->execlist_link);
> >>+   i915_gem_request_unreference(tail_req);
> >>}
> >>}
> >>
> >>+   i915_gem_request_reference(request);
> >>list_add_tail(>execlist_link, >execlist_queue);
> >
> >If you want to get truly radical, we do not need the ref on the request
> >until it is submitted to hardware. (As the request cannot be retired
> >until it has done so, it can leave the execlist_queue until we commit it
> >to hw, or perform the cancel).
> 
> Don't know. It is simple and nice that reference is tied to presence
> on execlist_queue.
> 
> More importantly, the patch as presented has a flaw that it
> dereferences req->ctx from execlists_check_remove_request where the
> context pin may have disappeared already due context complete
> interrupts getting behind when coallescing.
> 
> I will need to cache ctx_id in the request I think. It is fine do to
> that since ctx id must be unique and stable for a request.
> 
> Maybe even I should pull in your patch which makes ctx ids stable
> and persistent aligned with context existence and not pin. Think
> I've seen something like that somewhere.

Yes, both OA, PASID and vGPU depend upon having stable ctx-id for the
lifetime of the context. Dave expressed a concern that the GuC maybe
interpretting it as the LRCA, but as far as I can see, lrc->ring_lcra
and lrc->context_id are distinct and we never use the global context
identifier itself (the closest is the low 32bits of lrc_desc which do
not include our unique id).
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [RFC 4/4] drm/i915: Stop tracking execlists retired requests

2016-04-11 Thread Tvrtko Ursulin


On 08/04/16 15:57, Chris Wilson wrote:

On Fri, Apr 08, 2016 at 02:54:58PM +0100, Tvrtko Ursulin wrote:

@@ -615,11 +613,6 @@ static void execlists_context_queue(struct 
drm_i915_gem_request *request)
struct drm_i915_gem_request *cursor;
int num_elements = 0;

-   if (request->ctx != request->i915->kernel_context)
-   intel_lr_context_pin(request->ctx, engine);
-
-   i915_gem_request_reference(request);
-
spin_lock_bh(>execlist_lock);

list_for_each_entry(cursor, >execlist_queue, execlist_link)
@@ -636,11 +629,12 @@ static void execlists_context_queue(struct 
drm_i915_gem_request *request)
if (request->ctx == tail_req->ctx) {
WARN(tail_req->elsp_submitted != 0,
"More than 2 already-submitted reqs queued\n");
-   list_move_tail(_req->execlist_link,
-  >execlist_retired_req_list);
+   list_del(_req->execlist_link);
+   i915_gem_request_unreference(tail_req);
}
}

+   i915_gem_request_reference(request);
list_add_tail(>execlist_link, >execlist_queue);


If you want to get truly radical, we do not need the ref on the request
until it is submitted to hardware. (As the request cannot be retired
until it has done so, it can leave the execlist_queue until we commit it
to hw, or perform the cancel).


Don't know. It is simple and nice that reference is tied to presence on 
execlist_queue.


More importantly, the patch as presented has a flaw that it dereferences 
req->ctx from execlists_check_remove_request where the context pin may 
have disappeared already due context complete interrupts getting behind 
when coallescing.


I will need to cache ctx_id in the request I think. It is fine do to 
that since ctx id must be unique and stable for a request.


Maybe even I should pull in your patch which makes ctx ids stable and 
persistent aligned with context existence and not pin. Think I've seen 
something like that somewhere.


Regards,

Tvrtko
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [RFC 4/4] drm/i915: Stop tracking execlists retired requests

2016-04-08 Thread Chris Wilson
On Fri, Apr 08, 2016 at 02:54:58PM +0100, Tvrtko Ursulin wrote:
> @@ -615,11 +613,6 @@ static void execlists_context_queue(struct 
> drm_i915_gem_request *request)
>   struct drm_i915_gem_request *cursor;
>   int num_elements = 0;
>  
> - if (request->ctx != request->i915->kernel_context)
> - intel_lr_context_pin(request->ctx, engine);
> -
> - i915_gem_request_reference(request);
> -
>   spin_lock_bh(>execlist_lock);
>  
>   list_for_each_entry(cursor, >execlist_queue, execlist_link)
> @@ -636,11 +629,12 @@ static void execlists_context_queue(struct 
> drm_i915_gem_request *request)
>   if (request->ctx == tail_req->ctx) {
>   WARN(tail_req->elsp_submitted != 0,
>   "More than 2 already-submitted reqs queued\n");
> - list_move_tail(_req->execlist_link,
> ->execlist_retired_req_list);
> + list_del(_req->execlist_link);
> + i915_gem_request_unreference(tail_req);
>   }
>   }
>  
> + i915_gem_request_reference(request);
>   list_add_tail(>execlist_link, >execlist_queue);

If you want to get truly radical, we do not need the ref on the request
until it is submitted to hardware. (As the request cannot be retired
until it has done so, it can leave the execlist_queue until we commit it
to hw, or perform the cancel).

Lgtm,
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [RFC 4/4] drm/i915: Stop tracking execlists retired requests

2016-04-08 Thread Tvrtko Ursulin
From: Tvrtko Ursulin 

With the previous patch having extended the pinned lifetime of
contexts by referencing the previous context from the current
request until the latter is retired (completed by the GPU),
we can now remove usage of execlist retired queue entirely.

This is because the above now guarantees that all execlist
object access requirements are satisfied by this new tracking,
and we can stop taking additional references and stop keeping
request on the execlists retired queue.

The latter was a source of significant scalability issues in
the driver causing performance hits on some tests. Most
dramatical of which was igt/gem_close_race which had run time
in tens of minutes which is now reduced to tens of seconds.

Signed-off-by: Tvrtko Ursulin 
Cc: Chris Wilson 
---
 drivers/gpu/drm/i915/i915_gem.c | 10 +--
 drivers/gpu/drm/i915/intel_lrc.c| 46 ++---
 drivers/gpu/drm/i915/intel_lrc.h|  2 +-
 drivers/gpu/drm/i915/intel_ringbuffer.h |  1 -
 4 files changed, 16 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 118911ce7231..2f4bfe93b20c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2901,13 +2901,7 @@ static void i915_gem_reset_engine_cleanup(struct 
drm_i915_private *dev_priv,
/* Ensure irq handler finishes or is cancelled. */
tasklet_kill(>irq_tasklet);
 
-   spin_lock_bh(>execlist_lock);
-   /* list_splice_tail_init checks for empty lists */
-   list_splice_tail_init(>execlist_queue,
- >execlist_retired_req_list);
-   spin_unlock_bh(>execlist_lock);
-
-   intel_execlists_retire_requests(engine);
+   intel_execlists_cancel_requests(engine);
}
 
/*
@@ -3029,8 +3023,6 @@ i915_gem_retire_requests(struct drm_device *dev)
spin_lock_bh(>execlist_lock);
idle &= list_empty(>execlist_queue);
spin_unlock_bh(>execlist_lock);
-
-   intel_execlists_retire_requests(engine);
}
}
 
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 5e967943ce49..f241cf6e4227 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -456,8 +456,8 @@ static void execlists_context_unqueue(struct 
intel_engine_cs *engine)
/* Same ctx: ignore first request, as second request
 * will update tail past first request's workload */
cursor->elsp_submitted = req0->elsp_submitted;
-   list_move_tail(>execlist_link,
-  >execlist_retired_req_list);
+   list_del(>execlist_link);
+   i915_gem_request_unreference(req0);
req0 = cursor;
} else {
req1 = cursor;
@@ -499,19 +499,17 @@ execlists_check_remove_request(struct intel_engine_cs 
*engine, u32 request_id)
struct drm_i915_gem_request,
execlist_link);
 
-   if (!head_req)
-   return 0;
-
-   if (unlikely(intel_execlists_ctx_id(head_req->ctx, engine) != 
request_id))
-   return 0;
+   if (WARN_ON(!head_req ||
+   (intel_execlists_ctx_id(head_req->ctx, engine) != request_id)))
+   return 0;
 
WARN(head_req->elsp_submitted == 0, "Never submitted head request\n");
 
if (--head_req->elsp_submitted > 0)
return 0;
 
-   list_move_tail(_req->execlist_link,
-  >execlist_retired_req_list);
+   list_del(_req->execlist_link);
+   i915_gem_request_unreference(head_req);
 
return 1;
 }
@@ -615,11 +613,6 @@ static void execlists_context_queue(struct 
drm_i915_gem_request *request)
struct drm_i915_gem_request *cursor;
int num_elements = 0;
 
-   if (request->ctx != request->i915->kernel_context)
-   intel_lr_context_pin(request->ctx, engine);
-
-   i915_gem_request_reference(request);
-
spin_lock_bh(>execlist_lock);
 
list_for_each_entry(cursor, >execlist_queue, execlist_link)
@@ -636,11 +629,12 @@ static void execlists_context_queue(struct 
drm_i915_gem_request *request)
if (request->ctx == tail_req->ctx) {
WARN(tail_req->elsp_submitted != 0,
"More than 2 already-submitted reqs queued\n");
-   list_move_tail(_req->execlist_link,
-  >execlist_retired_req_list);
+   list_del(_req->execlist_link);
+