<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Please CC Michel as well, he originally
commented that we should try to solve this in the DDX instead.<br>
<br>
And BTW: Why don't we just do the migration during the mmap call?<br>
<br>
Christian.<br>
<br>
Am 13.12.2017 um 22:28 schrieb Li, Samuel:<br>
</div>
<blockquote type="cite"
cite="mid:BLUPR12MB06283F027DB3101FEDFF46A0F5350@BLUPR12MB0628.namprd12.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]-->
<style><!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@SimSun";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#2F5496;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#2F5496">Will
do after some basic testing.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#2F5496"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#2F5496">Sam<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#2F5496"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in
0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">
Deucher, Alexander
<br>
<b>Sent:</b> Wednesday, December 13, 2017 2:49 PM<br>
<b>To:</b> Li, Samuel <a class="moz-txt-link-rfc2396E" href="mailto:Samuel.Li@amd.com"><Samuel.Li@amd.com></a>;
Koenig, Christian <a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a>;
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
<b>Subject:</b> Re: FW: [PATCH v2 2/2] drm/amdgpu:
Move to gtt before cpu accesses dma buf.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span
style="font-family:"Calibri",sans-serif;color:black">Please
send the drm prime patch to dri-devel if you didn't
already.<o:p></o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black">Alex<o:p></o:p></span></p>
</div>
<div class="MsoNormal" style="text-align:center"
align="center">
<hr align="center" size="2" width="98%">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
amd-gfx <<a
href="mailto:amd-gfx-bounces@lists.freedesktop.org"
moz-do-not-send="true">amd-gfx-bounces@lists.freedesktop.org</a>>
on behalf of Samuel Li <<a
href="mailto:samuel.li@amd.com" moz-do-not-send="true">samuel.li@amd.com</a>><br>
<b>Sent:</b> Wednesday, December 13, 2017 2:17:49 PM<br>
<b>To:</b> Koenig, Christian; <a
href="mailto:amd-gfx@lists.freedesktop.org"
moz-do-not-send="true">amd-gfx@lists.freedesktop.org</a><br>
<b>Subject:</b> Re: FW: [PATCH v2 2/2] drm/amdgpu: Move
to gtt before cpu accesses dma buf.</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">For
the record.<br>
<br>
<br>
On 2017-12-13 01:26 PM, Christian König wrote:<br>
> Actually we try to avoid that drivers define
their own dma_buf_ops in DRM.<br>
> <br>
> That's why you have all those callbacks in
drm_driver which just mirror the dma_buf interface but
unpack the GEM object from the dma-buf object.<br>
> <br>
> There are quite a number of exceptions, but those
drivers then implement everything on their own because
the DRM marshaling doesn't make sense for them.<br>
> <br>
> Christian.<br>
> <br>
> Am 13.12.2017 um 19:01 schrieb Samuel Li:<br>
>> That is an approach. The cost is to add a new
call back, which is not necessary though, since driver
can always actually define their own dma_buf_ops.<br>
>> The intention here is to allow a driver reuse
drm_gem_prime_dmabuf_ops{}. If you would like to go
this far, maybe a more straight forward way is to
export those ops, e.g. drm_gem_map_attach, so that a
driver can use them in its own definitions.<br>
>><br>
>> Sam<br>
>><br>
>><br>
>><br>
>> On 2017-12-13 05:23 AM, Christian König
wrote:<br>
>>> Something like the attached patch. Not
even compile tested.<br>
>>><br>
>>> Christian.<br>
>>><br>
>>> Am 12.12.2017 um 20:13 schrieb Samuel Li:<br>
>>>> Not sure if I understand your
comments correctly. Currently amdgpu prime reuses
drm_gem_prime_dmabuf_ops{}, and it is defined as
static which is reasonable. I do not see an easier way
to introduce amdgpu_gem_begin_cpu_access().<br>
>>>><br>
>>>> Sam<br>
>>>><br>
>>>> On 2017-12-12 01:30 PM, Christian
König wrote:<br>
>>>>>> + while
(amdgpu_dmabuf_ops.begin_cpu_access !=
amdgpu_gem_begin_cpu_access)<br>
>>>>> I would rather just add the four
liner code to drm to forward the begin_cpu_access
callback into a drm_driver callback instead of all
this.<br>
>>>>><br>
>>>>> But apart from that it looks good
to me.<br>
>>>>><br>
>>>>> Christian.<br>
>>>>><br>
>>>>> Am 12.12.2017 um 19:14 schrieb
Li, Samuel:<br>
>>>>>> A gentle ping on this one,
Christian, can you take a look at this?<br>
>>>>>><br>
>>>>>> Sam<br>
>>>>>><br>
>>>>>> -----Original Message-----<br>
>>>>>> From: Li, Samuel<br>
>>>>>> Sent: Friday, December 08,
2017 5:22 PM<br>
>>>>>> To: <a
href="mailto:amd-gfx@lists.freedesktop.org"
moz-do-not-send="true">amd-gfx@lists.freedesktop.org</a><br>
>>>>>> Cc: Li, Samuel <<a
href="mailto:Samuel.Li@amd.com"
moz-do-not-send="true">Samuel.Li@amd.com</a>><br>
>>>>>> Subject: [PATCH v2 2/2]
drm/amdgpu: Move to gtt before cpu accesses dma buf.<br>
>>>>>><br>
>>>>>> To improve cpu read
performance. This is implemented for APUs currently.<br>
>>>>>><br>
>>>>>> v2: Adapt to change <a
href="https://lists.freedesktop.org/archives/amd-gfx/2017-October/015174.html"
moz-do-not-send="true">
https://lists.freedesktop.org/archives/amd-gfx/2017-October/015174.html</a><br>
>>>>>><br>
>>>>>> Change-Id:
I7a583e23a9ee706e0edd2a46f4e4186a609368e3<br>
>>>>>> ---<br>
>>>>>>
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++<br>
>>>>>>
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +-<br>
>>>>>>
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 58
+++++++++++++++++++++++++++++++<br>
>>>>>> 3 files changed, 61
insertions(+), 1 deletion(-)<br>
>>>>>><br>
>>>>>> diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
>>>>>> index f8657c3..193db70 100644<br>
>>>>>> ---
a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
>>>>>> +++
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
>>>>>> @@ -417,6 +417,8 @@
amdgpu_gem_prime_import_sg_table(struct drm_device
*dev, struct dma_buf *amdgpu_gem_prime_export(struct
drm_device *dev,<br>
>>>>>>
struct drm_gem_object *gobj,<br>
>>>>>> int
flags);<br>
>>>>>> +struct drm_gem_object
*amdgpu_gem_prime_import(struct drm_device *dev,<br>
>>>>>> +
struct dma_buf *dma_buf);<br>
>>>>>> int
amdgpu_gem_prime_pin(struct drm_gem_object *obj);
void amdgpu_gem_prime_unpin(struct drm_gem_object
*obj); struct reservation_object
*amdgpu_gem_prime_res_obj(struct drm_gem_object *);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
>>>>>> index 31383e0..df30b08 100644<br>
>>>>>> ---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
>>>>>> +++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
>>>>>> @@ -868,7 +868,7 @@ static
struct drm_driver kms_driver = {<br>
>>>>>> .prime_handle_to_fd =
drm_gem_prime_handle_to_fd,<br>
>>>>>> .prime_fd_to_handle =
drm_gem_prime_fd_to_handle,<br>
>>>>>> .gem_prime_export =
amdgpu_gem_prime_export,<br>
>>>>>> - .gem_prime_import =
drm_gem_prime_import,<br>
>>>>>> + .gem_prime_import =
amdgpu_gem_prime_import,<br>
>>>>>> .gem_prime_pin =
amdgpu_gem_prime_pin,<br>
>>>>>> .gem_prime_unpin =
amdgpu_gem_prime_unpin,<br>
>>>>>> .gem_prime_res_obj =
amdgpu_gem_prime_res_obj, diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c<br>
>>>>>> index ae9c106..de6f599 100644<br>
>>>>>> ---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c<br>
>>>>>> +++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c<br>
>>>>>> @@ -26,6 +26,7 @@<br>
>>>>>> #include
<drm/drmP.h><br>
>>>>>> #include "amdgpu.h"<br>
>>>>>> +#include "amdgpu_display.h"<br>
>>>>>> #include
<drm/amdgpu_drm.h><br>
>>>>>> #include
<linux/dma-buf.h><br>
>>>>>> @@ -164,6 +165,33 @@
struct reservation_object
*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)<br>
>>>>>> return
bo->tbo.resv;<br>
>>>>>> }<br>
>>>>>> +static int
amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,
enum<br>
>>>>>> +dma_data_direction
direction) {<br>
>>>>>> + struct amdgpu_bo *bo =
gem_to_amdgpu_bo(dma_buf->priv);<br>
>>>>>> + struct amdgpu_device
*adev = amdgpu_ttm_adev(bo->tbo.bdev);<br>
>>>>>> + struct ttm_operation_ctx
ctx = { true, false };<br>
>>>>>> + u32 domain =
amdgpu_framebuffer_domains(adev);<br>
>>>>>> + long ret = 0;<br>
>>>>>> + bool reads = (direction
== DMA_BIDIRECTIONAL || direction ==<br>
>>>>>> +DMA_FROM_DEVICE);<br>
>>>>>> +<br>
>>>>>> + if (!reads || !(domain |
AMDGPU_GEM_DOMAIN_GTT) || bo->pin_count)<br>
>>>>>> + return 0;<br>
>>>>>> +<br>
>>>>>> + /* move to gtt */<br>
>>>>>> + ret =
amdgpu_bo_reserve(bo, false);<br>
>>>>>> + if (unlikely(ret != 0))<br>
>>>>>> + return ret;<br>
>>>>>> +<br>
>>>>>> +
amdgpu_ttm_placement_from_domain(bo,
AMDGPU_GEM_DOMAIN_GTT);<br>
>>>>>> + ret =
ttm_bo_validate(&bo->tbo,
&bo->placement, &ctx);<br>
>>>>>> +<br>
>>>>>> + amdgpu_bo_unreserve(bo);<br>
>>>>>> + return ret;<br>
>>>>>> +}<br>
>>>>>> +<br>
>>>>>> +static struct dma_buf_ops
amdgpu_dmabuf_ops; static atomic_t aops_lock;<br>
>>>>>> +<br>
>>>>>> struct dma_buf
*amdgpu_gem_prime_export(struct drm_device *dev,<br>
>>>>>>
struct drm_gem_object *gobj,<br>
>>>>>> int
flags)<br>
>>>>>> @@ -178,5 +206,35 @@ struct
dma_buf *amdgpu_gem_prime_export(struct drm_device
*dev,<br>
>>>>>> buf =
drm_gem_prime_export(dev, gobj, flags);<br>
>>>>>> if (!IS_ERR(buf))<br>
>>>>>>
buf->file->f_mapping =
dev->anon_inode->i_mapping;<br>
>>>>>> +<br>
>>>>>> + while
(amdgpu_dmabuf_ops.begin_cpu_access !=
amdgpu_gem_begin_cpu_access)<br>
>>>>>> + {<br>
>>>>>> + if
(!atomic_cmpxchg(&aops_lock, 0, 1)) {<br>
>>>>>> +
amdgpu_dmabuf_ops = *(buf->ops);<br>
>>>>>> +
amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;<br>
>>>>>> + }<br>
>>>>>> + }<br>
>>>>>> + buf->ops =
&amdgpu_dmabuf_ops;<br>
>>>>>> +<br>
>>>>>> return buf;<br>
>>>>>> }<br>
>>>>>> +<br>
>>>>>> +struct drm_gem_object
*amdgpu_gem_prime_import(struct drm_device *dev,<br>
>>>>>> +
struct dma_buf *dma_buf)<br>
>>>>>> +{<br>
>>>>>> + struct drm_gem_object
*obj;<br>
>>>>>> +<br>
>>>>>> + if (dma_buf->ops ==
&amdgpu_dmabuf_ops) {<br>
>>>>>> + obj =
dma_buf->priv;<br>
>>>>>> + if (obj->dev ==
dev) {<br>
>>>>>> + /*<br>
>>>>>> + * Importing
dmabuf exported from out own gem increases<br>
>>>>>> + * refcount on
gem itself instead of f_count of dmabuf.<br>
>>>>>> + */<br>
>>>>>> +
drm_gem_object_get(obj);<br>
>>>>>> + return obj;<br>
>>>>>> + }<br>
>>>>>> + }<br>
>>>>>> +<br>
>>>>>> + return
drm_gem_prime_import(dev, dma_buf); }<br>
>>>>>> -- <br>
>>>>>> 2.7.4<br>
>>>>>><br>
> <o:p></o:p></span></p>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
amd-gfx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
</pre>
</blockquote>
<br>
</body>
</html>