<div dir="ltr">Hi<div><br></div><div>I've tested this version now - works great</div><div><br></div><div>Thanks</div><div><br></div><div>Mike<br><br><div class="gmail_quote"><div dir="ltr">On Wed, 9 Nov 2016 at 01:26 Mario Kleiner <<a href="mailto:mario.kleiner.de@gmail.com">mario.kleiner.de@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">External clients which import our bo's wait only<br class="gmail_msg">
for exclusive dmabuf-fences, not on shared ones,<br class="gmail_msg">
ditto for bo's which we import from external<br class="gmail_msg">
providers and write to.<br class="gmail_msg">
<br class="gmail_msg">
Therefore attach exclusive fences on prime shared buffers<br class="gmail_msg">
if our exported buffer gets imported by an external<br class="gmail_msg">
client, or if we import a buffer from an external<br class="gmail_msg">
exporter.<br class="gmail_msg">
<br class="gmail_msg">
See discussion in thread:<br class="gmail_msg">
<a href="https://lists.freedesktop.org/archives/dri-devel/2016-October/122370.html" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.freedesktop.org/archives/dri-devel/2016-October/122370.html</a><br class="gmail_msg">
<br class="gmail_msg">
Prime export tested on Intel iGPU + AMD Tonga dGPU as<br class="gmail_msg">
DRI3/Present Prime render offload, and with the Tonga<br class="gmail_msg">
standalone as primary gpu.<br class="gmail_msg">
<br class="gmail_msg">
v2: Add a wait for all shared fences before prime export,<br class="gmail_msg">
as suggested by Christian Koenig.<br class="gmail_msg">
<br class="gmail_msg">
v3: - Mark buffer prime_exported in amdgpu_gem_prime_pin,<br class="gmail_msg">
so we only use the exclusive fence when exporting a<br class="gmail_msg">
bo to external clients like a separate iGPU, but not<br class="gmail_msg">
when exporting/importing from/to ourselves as part of<br class="gmail_msg">
regular DRI3 fd passing.<br class="gmail_msg">
<br class="gmail_msg">
- Propagate failure of reservation_object_wait_rcu back<br class="gmail_msg">
to caller.<br class="gmail_msg">
<br class="gmail_msg">
v4: - Switch to a prime_shared_count counter instead of a<br class="gmail_msg">
flag, which gets in/decremented on prime_pin/unpin, so<br class="gmail_msg">
we can switch back to shared fences if all clients<br class="gmail_msg">
detach from our exported bo.<br class="gmail_msg">
<br class="gmail_msg">
- Also switch to exclusive fence for prime imported bo's.<br class="gmail_msg">
<br class="gmail_msg">
v5: - Drop lret, instead use int ret -> long ret, as proposed<br class="gmail_msg">
by Christian.<br class="gmail_msg">
<br class="gmail_msg">
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=95472" rel="noreferrer" class="gmail_msg" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=95472</a><br class="gmail_msg">
Tested-by: Mike Lothian <<a href="mailto:mike@fireburn.co.uk" class="gmail_msg" target="_blank">mike@fireburn.co.uk</a>> (v1)<br class="gmail_msg">
Signed-off-by: Mario Kleiner <<a href="mailto:mario.kleiner.de@gmail.com" class="gmail_msg" target="_blank">mario.kleiner.de@gmail.com</a>><br class="gmail_msg">
Reviewed-by: Christian König <<a href="mailto:christian.koenig@amd.com" class="gmail_msg" target="_blank">christian.koenig@amd.com</a>>.<br class="gmail_msg">
Cc: Christian König <<a href="mailto:christian.koenig@amd.com" class="gmail_msg" target="_blank">christian.koenig@amd.com</a>><br class="gmail_msg">
Cc: Michel Dänzer <<a href="mailto:michel.daenzer@amd.com" class="gmail_msg" target="_blank">michel.daenzer@amd.com</a>><br class="gmail_msg">
---<br class="gmail_msg">
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +<br class="gmail_msg">
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-<br class="gmail_msg">
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 20 +++++++++++++++++++-<br class="gmail_msg">
3 files changed, 21 insertions(+), 2 deletions(-)<br class="gmail_msg">
<br class="gmail_msg">
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br class="gmail_msg">
index 039b57e..496f72b 100644<br class="gmail_msg">
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br class="gmail_msg">
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br class="gmail_msg">
@@ -459,6 +459,7 @@ struct amdgpu_bo {<br class="gmail_msg">
u64 metadata_flags;<br class="gmail_msg">
void *metadata;<br class="gmail_msg">
u32 metadata_size;<br class="gmail_msg">
+ unsigned prime_shared_count;<br class="gmail_msg">
/* list of all virtual address to which this bo<br class="gmail_msg">
* is associated to<br class="gmail_msg">
*/<br class="gmail_msg">
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c<br class="gmail_msg">
index 651115d..c02db01f6 100644<br class="gmail_msg">
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c<br class="gmail_msg">
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c<br class="gmail_msg">
@@ -132,7 +132,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,<br class="gmail_msg">
entry->priority = min(info[i].bo_priority,<br class="gmail_msg">
AMDGPU_BO_LIST_MAX_PRIORITY);<br class="gmail_msg">
entry-><a href="http://tv.bo" rel="noreferrer" class="gmail_msg" target="_blank">tv.bo</a> = &entry->robj->tbo;<br class="gmail_msg">
- entry->tv.shared = true;<br class="gmail_msg">
+ entry->tv.shared = !entry->robj->prime_shared_count;<br class="gmail_msg">
<br class="gmail_msg">
if (entry->robj->prefered_domains == AMDGPU_GEM_DOMAIN_GDS)<br class="gmail_msg">
gds_obj = entry->robj;<br class="gmail_msg">
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c<br class="gmail_msg">
index 7700dc2..3826d5a 100644<br class="gmail_msg">
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c<br class="gmail_msg">
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c<br class="gmail_msg">
@@ -74,20 +74,36 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,<br class="gmail_msg">
if (ret)<br class="gmail_msg">
return ERR_PTR(ret);<br class="gmail_msg">
<br class="gmail_msg">
+ bo->prime_shared_count = 1;<br class="gmail_msg">
return &bo->gem_base;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
int amdgpu_gem_prime_pin(struct drm_gem_object *obj)<br class="gmail_msg">
{<br class="gmail_msg">
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);<br class="gmail_msg">
- int ret = 0;<br class="gmail_msg">
+ long ret = 0;<br class="gmail_msg">
<br class="gmail_msg">
ret = amdgpu_bo_reserve(bo, false);<br class="gmail_msg">
if (unlikely(ret != 0))<br class="gmail_msg">
return ret;<br class="gmail_msg">
<br class="gmail_msg">
+ /*<br class="gmail_msg">
+ * Wait for all shared fences to complete before we switch to future<br class="gmail_msg">
+ * use of exclusive fence on this prime shared bo.<br class="gmail_msg">
+ */<br class="gmail_msg">
+ ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,<br class="gmail_msg">
+ MAX_SCHEDULE_TIMEOUT);<br class="gmail_msg">
+ if (unlikely(ret < 0)) {<br class="gmail_msg">
+ DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);<br class="gmail_msg">
+ amdgpu_bo_unreserve(bo);<br class="gmail_msg">
+ return ret;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
/* pin buffer into GTT */<br class="gmail_msg">
ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);<br class="gmail_msg">
+ if (likely(ret == 0))<br class="gmail_msg">
+ bo->prime_shared_count++;<br class="gmail_msg">
+<br class="gmail_msg">
amdgpu_bo_unreserve(bo);<br class="gmail_msg">
return ret;<br class="gmail_msg">
}<br class="gmail_msg">
@@ -102,6 +118,8 @@ void amdgpu_gem_prime_unpin(struct drm_gem_object *obj)<br class="gmail_msg">
return;<br class="gmail_msg">
<br class="gmail_msg">
amdgpu_bo_unpin(bo);<br class="gmail_msg">
+ if (bo->prime_shared_count)<br class="gmail_msg">
+ bo->prime_shared_count--;<br class="gmail_msg">
amdgpu_bo_unreserve(bo);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
2.7.0<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
dri-devel mailing list<br class="gmail_msg">
<a href="mailto:dri-devel@lists.freedesktop.org" class="gmail_msg" target="_blank">dri-devel@lists.freedesktop.org</a><br class="gmail_msg">
<a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br class="gmail_msg">
</blockquote></div></div></div>