dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: "Chunming Zhou" <zhoucm1-5C7GfCeVMHo@public.gmane.org>,
	"Christian König" <christian.koenig-5C7GfCeVMHo@public.gmane.org>,
	"Chunming Zhou" <david1.zhou-5C7GfCeVMHo@public.gmane.org>,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Dave Airlie <airlied-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Daniel Rakos <Daniel.Rakos-5C7GfCeVMHo@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>
Subject: Re: [PATCH 5/5] [RFC]drm: add syncobj timeline support v3
Date: Mon, 3 Sep 2018 13:19:16 +0200	[thread overview]
Message-ID: <879aa2ac-26f4-b726-3e7e-807de27208c6@gmail.com> (raw)
In-Reply-To: <ffdac62f-8c9d-ff29-d699-f42873250ac6-5C7GfCeVMHo@public.gmane.org>

Am 03.09.2018 um 12:07 schrieb Chunming Zhou:
>
>
> 在 2018/9/3 16:50, Christian König 写道:
>> Am 03.09.2018 um 06:13 schrieb Chunming Zhou:
>>>
>>>
>>> 在 2018/8/30 19:32, Christian König 写道:
>>>> [SNIP]
>>>>>>>>
>>>>>>>>> +
>>>>>>>>> +struct drm_syncobj_wait_pt {
>>>>>>>>> +    struct drm_syncobj_stub_fence base;
>>>>>>>>> +    u64    value;
>>>>>>>>> +    struct rb_node   node;
>>>>>>>>> +};
>>>>>>>>> +struct drm_syncobj_signal_pt {
>>>>>>>>> +    struct drm_syncobj_stub_fence base;
>>>>>>>>> +    struct dma_fence *signal_fence;
>>>>>>>>> +    struct dma_fence *pre_pt_base;
>>>>>>>>> +    struct dma_fence_cb signal_cb;
>>>>>>>>> +    struct dma_fence_cb pre_pt_cb;
>>>>>>>>> +    struct drm_syncobj *syncobj;
>>>>>>>>> +    u64    value;
>>>>>>>>> +    struct list_head list;
>>>>>>>>> +};
>>>>>>>>
>>>>>>>> What are those two structures good for
>>>>>>> They are used to record wait ops points and signal ops points.
>>>>>>> For timeline, they are connected by timeline value, works like:
>>>>>>>     a. signal pt increase timeline value to signal_pt value when 
>>>>>>> signal_pt is signaled. signal_pt is depending on previous pt 
>>>>>>> fence and itself signal fence from signal ops.
>>>>>>>     b. wait pt tree checks if timeline value over itself value.
>>>>>>>
>>>>>>> For normal, works like:
>>>>>>>     a. signal pt increase 1 for syncobj_timeline->signal_point 
>>>>>>> every time when signal ops is performed.
>>>>>>>     b. when wait ops is comming, wait pt will fetch above last 
>>>>>>> signal pt value as its wait point. wait pt will be only signaled 
>>>>>>> by equal point value signal_pt.
>>>>>>>
>>>>>>>
>>>>>>>> and why is the stub fence their base?
>>>>>>> Good question, I tried to kzalloc for them as well when I debug 
>>>>>>> them, I encountered a problem:
>>>>>>> I lookup/find wait_pt or signal_pt successfully, but when I 
>>>>>>> tried to use them, they are freed sometimes, and results in NULL 
>>>>>>> point.
>>>>>>> and generally, when lookup them, we often need their stub fence 
>>>>>>> as well, and in the meantime,  their lifecycle are same.
>>>>>>> Above reason, I make stub fence as their base.
>>>>>>
>>>>>> That sounds like you only did this because you messed up the 
>>>>>> lifecycle.
>>>>>>
>>>>>> Additional to that I don't think you correctly considered the 
>>>>>> lifecycle of the waits and the sync object itself. E.g. blocking 
>>>>>> in drm_syncobj_timeline_fini() until all waits are done is not a 
>>>>>> good idea.
>>>>>>
>>>>>> What you should do instead is to create a fence_array object with 
>>>>>> all the fence we need to wait for when a wait point is requested.
>>>>> Yeah, this is our initial discussion result, but when I tried to 
>>>>> do that, I found that cannot meet the advance signal requirement:
>>>>>     a. We need to consider the wait and signal pt value are not 
>>>>> one-to-one match, it's difficult to find dependent point, at 
>>>>> least, there is some overhead.
>>>>
>>>> As far as I can see that is independent of using a fence array 
>>>> here. See you can either use a ring buffer or an rb-tree, but when 
>>>> you want to wait for a specific point we need to condense the not 
>>>> yet signaled fences into an array.
>>> again, need to find the range of where the specific point in, we 
>>> should close to timeline semantics, I also refered the sw_sync.c 
>>> timeline, usally wait_pt is signalled by timeline point. And I agree 
>>> we can implement it with several methods, but I don't think there 
>>> are basical differences.
>>
>> The problem is that with your current approach you need the sync_obj 
>> alive for the synchronization to work. That is most likely not a good 
>> idea.
> Indeed, I will fix that. How abount only creating fence array for 
> every wait pt when syncobj release? when syncobj release, wait pt must 
> have waited the signal opertation, then we can easily condense fences 
> for every wait pt. And meantime, we can take timeline based wait pt 
> advantage.

That could work, but I don't see how you want to replace the already 
issued fence with a fence_array when the sync object is destroyed.

Additional to that I would rather prefer a consistent handling, e.g. 
without extra rarely used code paths.

>
>>
>> Additional to that you enable signaling without a need from the 
>> waiting side. That is rather bad for implementations which need that 
>> optimization.
> Do you mean increasing timeline based on signal fence is not better? 
> only update timeline value when requested by a wait pt?

Yes, exactly.

> This way, we will not update timeline value immidiately and cannot 
> free signal pt immidiately, and we also need to consider it to CPU 
> query and wait.

That is actually the better coding style. We usually try to avoid doing 
things in interrupt handlers as much as possible.

How about this idea:
1. Each signaling point is a fence implementation with an rb node.
2. Each node keeps a reference to the last previously inserted node.
3. Each node is referenced by the sync object itself.
4. Before each signal/wait operation we do a garbage collection and 
remove the first node from the tree as long as it is signaled.

5. When enable_signaling is requested for a node we cascade that to the 
left using rb_prev.
     This ensures that signaling is enabled for the current fence as 
well as all previous fences.

6. A wait just looks into the tree for the signal point lower or equal 
of the requested sequence number.

7. When the sync object is released we use 
rbtree_postorder_for_each_entry_safe() and drop the extra reference to 
each node, but never call rb_erase!
     This way the rb_tree stays in memory, but without a root (e.g. the 
sync object). It only destructs itself when the looked up references to 
the nodes are dropped.

Well that is quite a bunch of logic, but I think that should work fine.

Regards,
Christian.

>
> Thanks,
> David Zhou
>
>>
>> I suggest to either condense all the fences you need to wait for in 
>> an array during the wait operation, or reference count the sync_obj 
>> and only enable the signaling on the fences when requested by a wait.
>>
>>>
>>>>
>>>>>     b. because we allowed "wait-before-signal", if 
>>>>> "wait-before-signal" happens, there isn't signal fence which can 
>>>>> be used to create fence array.
>>>>
>>>> Well, again we DON'T support wait-before-signal here. I will 
>>>> certainly NAK any implementation which tries to do this until we 
>>>> haven't figured out all the resource management constraints and I 
>>>> still don't see how we can do this.
>>> yes, we don't support real wait-before-signal in patch now, just a 
>>> fake wait-before-signal, which still wait on CS submission until 
>>> signal operation coming through wait_event, which is the conclusion 
>>> we disscussed before.
>>
>> Well in this case we should call it wait-for-signal and not 
>> wait-before-signal :)
>>
>>>
>>>>
>>>>> So timeline value is good to resolve that.
>>>>>
>>>>>>
>>>>>> Otherwise somebody can easily construct a situation where 
>>>>>> timeline sync obj A waits on B and B waits on A.
>>>>> Same situation also can happens with fence-array, we only can see 
>>>>> this is a programming bug with incorrect use.
>>>>
>>>> No, fence-array is initialized only once with a static list of 
>>>> fences. This way it is impossible to add the fence-array to itself 
>>>> for example.
>>>>
>>>> E.g. you can't build circle dependencies with that.
>>> we already wait for signal operation event, so never build circle 
>>> dependencies with that. The theory is same.
>>
>> Yeah, ok that is certainly true.
>>
>> Regards,
>> Christian.
>>
>>>
>>>
>>>>
>>>>> Better use rbtree_postorder_for_each_entry_safe() for this.
>>>>>>> From the comments, seems we cannot use it here, we need erase 
>>>>>>> node here.
>>>>>>> Comments:
>>>>>>>  * Note, however, that it cannot handle other modifications that 
>>>>>>> re-order the
>>>>>>>  * rbtree it is iterating over. This includes calling rb_erase() 
>>>>>>> on @pos, as
>>>>>>>  * rb_erase() may rebalance the tree, causing us to miss some 
>>>>>>> nodes.
>>>>>>>  */
>>>>>>
>>>>>> Yeah, but your current implementation has the same problem :)
>>>>>>
>>>>>> You need to use something like "while (node = rb_first(...))" 
>>>>>> instead if you want to destruct the whole tree.
>>> OK, got it, I will change it in v4.
>>>
>>> Thanks,
>>> David Zhou
>>
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-09-03 11:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29 10:44 [PATCH 1/5] drm: fix syncobj null_fence_enable_signaling Chunming Zhou
2018-08-29 10:44 ` [PATCH 3/5] drm: expand drm_syncobj_find_fence to support timeline point v2 Chunming Zhou
     [not found] ` <20180829104434.13265-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-08-29 10:44   ` [PATCH 2/5] drm: rename null fence to stub fence in syncobj Chunming Zhou
2018-08-29 10:44   ` [PATCH 4/5] drm: expand replace_fence to support timeline point v2 Chunming Zhou
2018-08-29 10:44   ` [PATCH 5/5] [RFC]drm: add syncobj timeline support v3 Chunming Zhou
     [not found]     ` <20180829104434.13265-5-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-08-29 11:42       ` Christian König
2018-08-30  3:50         ` zhoucm1
     [not found]           ` <45ed2e67-0b20-fa45-9575-e3f29470d4fd-5C7GfCeVMHo@public.gmane.org>
2018-08-30  7:25             ` Christian König
     [not found]               ` <f6bf45a6-6f7e-587a-f41c-5ddb8df5284e-5C7GfCeVMHo@public.gmane.org>
2018-08-30 10:40                 ` zhoucm1
     [not found]                   ` <e3d4a0c9-80f9-73e6-d9ad-ecaf1e055bcf-5C7GfCeVMHo@public.gmane.org>
2018-08-30 11:32                     ` Christian König
     [not found]                       ` <60e0dd83-93c1-8cbf-03b6-f00739fb7078-5C7GfCeVMHo@public.gmane.org>
2018-09-03  4:13                         ` Chunming Zhou
2018-09-03  8:50                           ` Christian König
     [not found]                             ` <43b69e04-d71b-e77a-6a41-1d8cb9ec1b95-5C7GfCeVMHo@public.gmane.org>
2018-09-03 10:07                               ` Chunming Zhou
     [not found]                                 ` <ffdac62f-8c9d-ff29-d699-f42873250ac6-5C7GfCeVMHo@public.gmane.org>
2018-09-03 11:19                                   ` Christian König [this message]
     [not found]                                     ` <879aa2ac-26f4-b726-3e7e-807de27208c6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-09-04  4:04                                       ` zhoucm1
2018-09-04  7:00                                         ` Christian König
     [not found]                                           ` <4701566f-3b32-055c-3a5b-9c46708d85f1-5C7GfCeVMHo@public.gmane.org>
2018-09-04  7:53                                             ` zhoucm1
     [not found]                                               ` <9b3ba227-c8c5-4789-daff-6436fa5a2f28-5C7GfCeVMHo@public.gmane.org>
2018-09-04  8:05                                                 ` Christian König
     [not found]                                                   ` <94dd248e-15e2-7d27-e0ca-74e00b3e52c4-5C7GfCeVMHo@public.gmane.org>
2018-09-04  8:27                                                     ` zhoucm1
     [not found]                                                       ` <84d83bb0-5576-558d-1f73-8f41276dcf87-5C7GfCeVMHo@public.gmane.org>
2018-09-04  8:42                                                         ` Christian König
     [not found]                                                           ` <2f04c699-3259-ea87-e415-10c7e834460b-5C7GfCeVMHo@public.gmane.org>
2018-09-04  9:00                                                             ` zhoucm1
     [not found]                                                               ` <f2808965-22a5-bfe8-9eb1-e206e20265d8-5C7GfCeVMHo@public.gmane.org>
2018-09-04  9:20                                                                 ` Christian König
2018-09-05  3:36                                                                   ` zhoucm1
     [not found]                                                                     ` <8363b46b-52c4-1539-0928-df5b8894370e-5C7GfCeVMHo@public.gmane.org>
2018-09-05  6:55                                                                       ` Christian König
  -- strict thread matches above, loose matches on Subject: below --
2018-08-30  6:48 [PATCH 1/5] drm: fix syncobj null_fence_enable_signaling Chunming Zhou
2018-08-30  6:48 ` [PATCH 5/5] [RFC]drm: add syncobj timeline support v3 Chunming Zhou

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=879aa2ac-26f4-b726-3e7e-807de27208c6@gmail.com \
    --to=ckoenig.leichtzumerken-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=Daniel.Rakos-5C7GfCeVMHo@public.gmane.org \
    --cc=airlied-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=christian.koenig-5C7GfCeVMHo@public.gmane.org \
    --cc=daniel-/w4YWyX8dFk@public.gmane.org \
    --cc=david1.zhou-5C7GfCeVMHo@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=zhoucm1-5C7GfCeVMHo@public.gmane.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).