dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Mikko Perttunen <cyndis@kapsi.fi>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jon Hunter <jonathanh@nvidia.com>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	sumit.semwal@linaro.org, gustavo@padovan.org
Cc: "linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	talho@nvidia.com, bhuntsman@nvidia.com,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Erik Faye-Lund <kusmabite@gmail.com>
Subject: Re: [RFC] Host1x/TegraDRM UAPI (sync points)
Date: Mon, 29 Jun 2020 05:36:59 +0300	[thread overview]
Message-ID: <623c1eaa-31fb-8dff-f6c0-d8cd0be60070@gmail.com> (raw)
In-Reply-To: <62859775-514c-2941-75ed-6905e9282a6f@kapsi.fi>

28.06.2020 12:44, Mikko Perttunen пишет:
> On 6/28/20 2:27 AM, Dmitry Osipenko wrote:
>> 23.06.2020 15:09, Mikko Perttunen пишет:
>>>
>>> ### IOCTL HOST1X_ALLOCATE_SYNCPOINT (on /dev/host1x)
>>>
>>> Allocates a free syncpoint, returning a file descriptor representing it.
>>> Only the owner of the file descriptor is allowed to mutate the value of
>>> the syncpoint.
>>>
>>> ```
>>> struct host1x_ctrl_allocate_syncpoint {
>>>         /**
>>>          * @fd:
>>>          *
>>>          * [out] New file descriptor representing the allocated
>>> syncpoint.
>>>          */
>>>         __s32 fd;
>>>
>>>         __u32 reserved[3];
>>> };
>>
>> We should need at least these basic things from the sync points API >
>> - Execution context shouldn't be able to tamper sync points of the other
>> contexts.
> 
> This is covered by this UAPI - when submitting, as part of the
> syncpt_incr struct you pass the syncpoint FD. This way the driver can
> check the syncpoints used are correct, or program HW protection.
> 
>>
>> - Sync point could be shared with other contexts for explicit fencing.
> 
> Not sure what you specifically mean; you can get the ID out of the
> syncpoint fd and share the ID for read-only access. (Or the FD for
> read-write access)

I enumerated the overall points that UAPI should provide to us, just for
clarity. Not like you haven't covered any of them, sorry for the
confusion! :)

Please see more comments below!

>>
>> - Sync points should work reliably.
>>
>> Some problems of the current Host1x driver, like where it falls over if
>> sync point value is out-of-sync + all the hang-job recovery labor could
>> be easily reduced if sync point health is protected by extra UAPI
>> constraints. >
>> So I think we may want the following:
>>
>> 1. We still should need to assign sync point ID to a DRM-channel's
>> context. This sync point ID will be used for a commands stream forming,
>> like it is done by the current staging UAPI.
>>
>> So we should need to retain the DRM_TEGRA_GET_SYNCPT IOCTL, but
>> improve it.

My point here is that the UAPI shouldn't be able to increment the job's
sync point using SYNCPOINT_INCREMENT IOCTL, which is another UAPI
constraint.

I'm suggesting that we should have two methods of sync point allocations:

1) Sync point that could be used only by a submitted job.

2) Sync point that could be incremented by CPU.

The first method will allocate a raw sync point ID that is assigned to
the channel's context. This ID will be used for the job's completion
tracking. Perhaps this method also could optionally return a sync point
FD if you'd want to wait on this sync point by another job.

We don't need a dedicated sync point FD for all kinds of jobs, don't we?
For example, I don't see why a sync point FD may be needed in a case of
Opentegra jobs.

>> 2. Allocated sync point must have a clean hardware state.
> 
> What do you mean by clean hardware state?

I mean that sync point should have a predictable state [1], it shouldn't
accidentally fire during of hardware programming for example.

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/host1x/soc/syncpoints.c#L132

For a submitted job, the job's sync point state could be reset at a
submission time, for example like I did it in the grate-kernel's
experimental driver [2].

[2]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/host1x/soc/channel.c#L145

>>
>> 3. Sync points should be properly refcounted. Job's sync points
>> shouldn't be re-used while job is alive.
>>
>> 4. The job's sync point can't be re-used after job's submission (UAPI
>> constraint!). Userspace must free sync point and allocate a new one for
>> the next job submission. And now we:
>>
>>    - Know that job's sync point is always in a healthy state!
>>
>>    - We're not limited by a number of physically available hardware sync
>> points! Allocation should block until free sync point is available.
>>
>>    - The logical number of job's sync point increments matches the SP
>> hardware state! Which is handy for a job's debugging.
>>
>> Optionally, the job's sync point could be auto-removed from the DRM's
>> context after job's submission, avoiding a need for an extra SYNCPT_PUT
>> IOCTL invocation to be done by userspace after the job's submission.
>> Could be a job's flag.
> 
> I think this would cause problems where after a job completes but before
> the fence has been waited, the syncpoint is already recycled (especially
> if the syncpoint is reset into some clean state).

Exactly, good point! The dma-fence shouldn't be hardwired to the sync
point in order to avoid this situation :)

Please take a look at the fence implementation that I made for the
grate-driver [3]. The host1x-fence is a dma-fence [4] that is attached
to a sync point by host1x_fence_create(). Once job is completed, the
host1x-fence is detached from the sync point [5][6] and sync point could
be recycled safely!

[3]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/host1x/fence.c

[4]
https://github.com/grate-driver/linux/blob/master/include/linux/host1x.h#L450

[5]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/host1x/soc/syncpoints_hw.c#L50

[6]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/uapi/scheduler.c#L133

Please try to take a closer look at the grate-driver's implementation if
you haven't yet. I think we should be able to reuse or improve some of
the ideas. That implementation isn't 100% complete, it doesn't cover
things like CPU-incremented or exported sync points for example, but
basics are there.

> I would prefer having a syncpoint for each userspace channel context
> (several of which could share a hardware channel if MLOCKing is not used).
> 
> In my experience it's then not difficult to pinpoint which job has
> failed, and if each userspace channel context uses a separate syncpoint,
> a hanging job wouldn't mess with other application's jobs, either.

I agree that there shouldn't be any problems with finding what job is
hanged. The timed out job is always the hanged job, no? :)

Also, please take a look at the DRM scheduler. Once I started to wire up
the DRM scheduler support in the grate-driver, I realized that there is
no real need to try to recover sync point's counter and etc, like the
current upstream host1x driver does for a hanged job. When job is
hanged, the whole channel should be turned down and reset, the job's
sync point state reset, client's HW engine reset, all the pre-queued
jobs re-submitted. And the generic DRM job scheduler helps us with that!
It also has other neat features which I haven't tried yet, like job
priorities for example.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-06-29  6:51 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 12:09 [RFC] Host1x/TegraDRM UAPI Mikko Perttunen
2020-06-24 20:55 ` Dmitry Osipenko
2020-06-25  9:17   ` Mikko Perttunen
2020-06-24 22:33 ` Dmitry Osipenko
2020-06-25  9:27   ` Mikko Perttunen
2020-06-25 22:50     ` [RFC] Host1x/TegraDRM UAPI (drm_tegra_submit_relocation) Dmitry Osipenko
2020-06-26  9:01       ` Mikko Perttunen
2020-06-24 23:11 ` [RFC] Host1x/TegraDRM UAPI Dmitry Osipenko
2020-06-25  9:16   ` Mikko Perttunen
2020-06-25 23:24     ` Dmitry Osipenko
2020-06-26  9:05       ` Mikko Perttunen
2020-06-24 23:18 ` Dmitry Osipenko
2020-06-25  0:59   ` Dmitry Osipenko
2020-06-24 23:23 ` Dmitry Osipenko
2020-06-25  9:19   ` Mikko Perttunen
2020-06-25  0:47 ` Dmitry Osipenko
2020-06-25  9:23   ` Mikko Perttunen
2020-06-25 22:47 ` [RFC] Host1x/TegraDRM UAPI (drm_tegra_channel_map) Dmitry Osipenko
2020-06-26  7:34   ` Thierry Reding
2020-06-26 16:35     ` Dmitry Osipenko
2020-06-28 11:16       ` Mikko Perttunen
2020-06-28 22:59         ` Dmitry Osipenko
2020-06-30 10:55           ` Mikko Perttunen
2020-06-30 19:48             ` Dmitry Osipenko
2020-06-26 11:06 ` [RFC] Host1x/TegraDRM UAPI Karol Herbst
2020-06-26 11:13   ` Mikko Perttunen
2020-06-26 11:16     ` Karol Herbst
2020-06-26 11:40   ` Thierry Reding
2020-06-26 13:38     ` Daniel Vetter
2020-06-26 13:59       ` Dmitry Osipenko
2020-06-30  9:09         ` Daniel Vetter
2020-06-27 21:47 ` [RFC] Host1x/TegraDRM UAPI (drm_tegra_submit_syncpt_incr) Dmitry Osipenko
2020-06-28 11:10   ` Mikko Perttunen
2020-06-27 22:32 ` [RFC] Host1x/TegraDRM UAPI (drm_tegra_submit_command) Dmitry Osipenko
2020-06-28 10:28   ` Mikko Perttunen
2020-06-29  0:00     ` Dmitry Osipenko
2020-06-30 10:40       ` Mikko Perttunen
2020-06-27 23:27 ` [RFC] Host1x/TegraDRM UAPI (sync points) Dmitry Osipenko
2020-06-28  9:44   ` Mikko Perttunen
2020-06-29  2:36     ` Dmitry Osipenko [this message]
2020-06-29 10:27       ` Mikko Perttunen
2020-06-29 19:28         ` Dmitry Osipenko
2020-06-29 19:33         ` Dmitry Osipenko
2020-06-29 19:42         ` Dmitry Osipenko
2020-06-30 10:26           ` Mikko Perttunen
2020-07-01  0:22             ` Dmitry Osipenko
2020-07-02 12:10               ` Mikko Perttunen
2020-07-07 11:06                 ` Dmitry Osipenko
2020-07-08 10:06                   ` Mikko Perttunen
2020-07-09  9:28                     ` Dmitry Osipenko

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=623c1eaa-31fb-8dff-f6c0-d8cd0be60070@gmail.com \
    --to=digetx@gmail.com \
    --cc=airlied@linux.ie \
    --cc=bhuntsman@nvidia.com \
    --cc=cyndis@kapsi.fi \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo@padovan.org \
    --cc=jonathanh@nvidia.com \
    --cc=kusmabite@gmail.com \
    --cc=linux-tegra@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=talho@nvidia.com \
    --cc=thierry.reding@gmail.com \
    /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