drm/i915: Add sync framework support to execbuff IOCTL
Subsystems (3)
RFC 1/1 drm/i915: Add sync framework support to execbuff IOCTL
From: John Harrison <[email protected]>
Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retreive a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.
This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.
At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.
Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.
--- drivers/gpu/drm/i915/Makefile | 2 + drivers/gpu/drm/i915/i915_drv.h | 18 ++ drivers/gpu/drm/i915/i915_gem.c | 38 +++ drivers/gpu/drm/i915/i915_gem_execbuffer.c | 89 ++++++- drivers/gpu/drm/i915/intel_sync.c | 357 +++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_sync.h | 76 ++++++ include/uapi/drm/i915_drm.h | 18 +- 7 files changed, 592 insertions(+), 6 deletions(-) create mode 100644 drivers/gpu/drm/i915/intel_sync.c create mode 100644 drivers/gpu/drm/i915/intel_sync.h
drivers/gpu/drm/i915/Makefile +2 -0
@@ -90,6 +90,8 @@ i915-y += i915_vgpu.o # legacy horrors i915-y += i915_dma.o +i915-$(CONFIG_SYNC) += intel_sync.o + obj-$(CONFIG_DRM_I915) += i915.o CFLAGS_i915_trace_points.o := -I$(src)
drivers/gpu/drm/i915/i915_drv.h +18 -0
@@ -836,6 +836,10 @@ struct i915_ctx_hang_stats {bool banned; }; +#ifdef CONFIG_SYNC +struct i915_sync_timeline ; +#endif +/* This must match up with the value previously used for execbuf2.rsvd1. */ #define DEFAULT_CONTEXT_HANDLE 0
@@ -880,6 +884,9 @@ struct intel_context {struct drm_i915_gem_object *state;struct intel_ringbuffer *ringbuf;int pin_count; +#ifdef CONFIG_SYNC +struct i915_sync_timeline *sync_timeline; +#endif } engine[I915_NUM_RINGS ];struct list_head link;
@@ -2201,6 +2208,11 @@ struct drm_i915_gem_request {/** process identifier submitting this request */ struct pid *pid; +#ifdef CONFIG_SYNC +/** native sync timeline value **/ +uint32_t sync_value; +#endif +/** * The ELSP only accepts two elements at a time, so we queue * context/tail pairs on a given queue (ring->execlist_queue) until the
@@ -2291,6 +2303,12 @@ static inline void i915_gem_request_assign(struct drm_i915_gem_request **pdst, *pdst = src; } +#ifdef CONFIG_SYNC +struct drm_i915_gem_request *i915_gem_request_find_by_sync_value (struct intel_engine_cs *ring, +struct intel_context *ctx, +uint32_t sync_value); +#endif +/* * A command that requires special handling by the command parser. */
drivers/gpu/drm/i915/i915_gem.c +38 -0
@@ -37,6 +37,7 @@#include <linux/swap.h> #include <linux/pci.h> #include <linux/dma-buf.h> +#include "intel_sync.h" #define RQ_BUG_ON (expr)
@@ -2534,6 +2535,17 @@ void __i915_add_request(struct drm_i915_gem_request *request,*/ i915_gem_request_submit (request); +#ifdef CONFIG_SYNC +/* +* If an external sync point has been requested for this request then +* it can be waited on without the driver's knowledge, i.e. without +* calling __i915_wait_request(). Thus interrupts must be enabled +* from the start rather than only on demand. +*/ +if (request->sync_value) +i915_gem_request_enable_interrupt (request); +#endif +if (i915.enable_execlists) ret = ring->emit_request (request);else {
@@ -2735,6 +2747,11 @@ void i915_gem_request_notify(struct intel_engine_cs *ring)fence_signal_locked (&req->fence);trace_i915_gem_request_complete (req); + +#ifdef CONFIG_SYNC +if (req->sync_value) +i915_sync_timeline_advance (req->ctx, req->ring, req->sync_value); +#endif }list_del_init (&req->signal_list);
@@ -2830,6 +2847,27 @@ void i915_gem_request_cancel(struct drm_i915_gem_request *req)i915_gem_request_unreference (req); } +#ifdef CONFIG_SYNC +struct drm_i915_gem_request *i915_gem_request_find_by_sync_value (struct intel_engine_cs *ring, +struct intel_context *ctx, +uint32_t sync_value) +{ +struct drm_i915_gem_request *req =NULL ; + +BUG_ON (!mutex_is_locked (&ring->dev->struct_mutex)); + +list_for_each_entry (req, &ring->request_list, list) { +if (req->ctx != ctx) +continue ; + +if (req->sync_value == sync_value) +break ; + } + +return req; +} +#endif +struct drm_i915_gem_request *i915_gem_find_active_request (struct intel_engine_cs *ring) {
drivers/gpu/drm/i915/i915_gem_execbuffer.c +84 -5
137 lines not on this page · raw message
drivers/gpu/drm/i915/intel_sync.c new file +357 -0
357 lines not on this page · raw message
drivers/gpu/drm/i915/intel_sync.h new file +76 -0
76 lines not on this page · raw message
include/uapi/drm/i915_drm.h +17 -1
@@ -765,7 +765,17 @@ struct drm_i915_gem_execbuffer2 {#define I915_EXEC_BSD_RING1 (1<<13)#define I915_EXEC_BSD_RING2 (2<<13) -#define __I915_EXEC_UNKNOWN_FLAGS -(1<<15) +/** Caller supplies a sync fence fd in the rsvd2 field. +* Wait for it to be signalled before starting the work +*/ +#define I915_EXEC_WAIT_FENCE (1<<15) + +/** Caller wants a sync fence fd for this execbuffer. +* It will be returned in rsvd2 +*/ +#define I915_EXEC_REQUEST_FENCE (1<<16) + +#define __I915_EXEC_UNKNOWN_FLAGS -(1<<17)#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)#define i915_execbuffer2_set_context_id (eb2, context) \
@@ -773,6 +783,12 @@ struct drm_i915_gem_execbuffer2 {#define i915_execbuffer2_get_context_id (eb2) \ ((eb2).rsvd1 & I915_EXEC_CONTEXT_ID_MASK) +struct drm_i915_gem_syncpt_driver_data { +__u32 value; +__u32 cycle; +__u64 ring_mask; +}; +struct drm_i915_gem_pin {/** Handle of the buffer to be pinned. */ __u32 handle;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 25 lines · On Thu, Jul 02, 2015 at 12:09:59PM +0100, [email protected] wrote:
From: John Harrison <[email protected]>
Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retreive a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.
This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.
At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.
Quoted 8 lines
Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.
But there is nothing preventing assignment of the sync value on submission. Other than the debug .fence_value_str it's a private implementation detail, and the interface is solely through the fd and signalling. You could implement this as a secondary write to the HWS, assigning the sync_value to the sync_pt on submission and remove the request tracking, as when signalled you only need to compare the sync_value against the timeline value in the HWS.
However, that equally applies to the existing request->seqno. That can also be assigned on submission so that it always an ordered timeline, and so can be used internally or externally.
It's a pity that the sync_pt didn't forward thefence->enable_signaling().
As for using rsvd2, make sure you do
int fence_fd = lower_32_bits(args->rsvd2);
and maybe I915_EXEC_CREATE_FENCE is a clearer name. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 3 lines · Chris Wilson
However, that equally applies to the existing
request->seqno. That can also be assigned on submission so that it always an ordered timeline, and so can be used internally or externally.
Hmm, we need to preallocate seqno space for the request during i915_gem_request_alloc(). In the noop scheduler, we are then safe to assign the next available. A reordering scheduler can insert whatever commands it needs in between batches and wouldn't need to do anything in the preallocate.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 34 lines · Chris Wilson
Quoted 25 lines · On Thu, Jul 02, 2015 at 12:09:59PM +0100, [email protected] wrote:
From: John Harrison <[email protected]>
Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retreive a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.
This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.
At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.
Quoted 8 lines
Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.
Quoted 4 lines
But there is nothing preventing assignment of the sync value on submission. Other than the debug .fence_value_str it's a private implementation detail, and the interface is solely through the fd and signalling.
No, it needs to be public from the moment of creation. The sync framework API allows sync points to be combined together to create fences that either merge multiple points on the same timeline or amalgamate points across differing timelines. The merging part means that the sync point must be capable of doing arithmetic comparisons with other sync points from the instant it is returned to user land. And those comparisons must not change in the future due to scheduler re-ordering because by then it is too late to redo the test.
Quoted 8 lines
You could implement this as a secondary write to the HWS,
assigning thesync_valueto thesync_pton submission and remove the request tracking, as when signalled you only need to compare thesync_valueagainst the timeline value in the HWS.However, that equally applies to the existing
request->seqno. That can also be assigned on submission so that it always an ordered timeline, and so can be used internally or externally.
One of the scheduler patches is to defer seqno assignment until batch submission rather than do it at request creation (for execbuffer requests). You still have a problem with pre-emption though. A request that is pre-empted will get a new seqno assigned when it is resubmitted so that the HWS page always sees ordered values popping out. For internal requests, this is fine but for external sync points that breaks the assumptions made by the framework.
Quoted 10 lines
It's a pity that the
sync_ptdidn't forward thefence->enable_signaling().As for using rsvd2, make sure you do
int fence_fd = lower_32_bits(args->rsvd2);and maybe
I915_EXEC_CREATE_FENCEis a clearer name. -Chris
Thanks,
John.
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 39 lines · John Harrison
Quoted 34 lines · Chris Wilson
Quoted 25 lines · On Thu, Jul 02, 2015 at 12:09:59PM +0100, [email protected] wrote:
From: John Harrison <[email protected]>
Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retreive a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.
This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.
At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.
Quoted 8 lines
Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.
Quoted 4 lines
But there is nothing preventing assignment of the sync value on submission. Other than the debug .fence_value_str it's a private implementation detail, and the interface is solely through the fd and signalling.
Quoted 8 lines
No, it needs to be public from the moment of creation. The sync framework API allows sync points to be combined together to create fences that either merge multiple points on the same timeline or amalgamate points across differing timelines. The merging part means that the sync point must be capable of doing arithmetic comparisons with other sync points from the instant it is returned to user land. And those comparisons must not change in the future due to scheduler re-ordering because by then it is too late to redo the test.
You know that's not documented at all. The only information userspace gets is afaict
struct sync_pt_info {
__u32 len;
char obj_name[32];
char driver_name[32];
__s32 status;
__u64 timestamp_ns;
__u8 driver_data[0];
};There is a merge operation done by combining two fence into a new one. Merging is done by ordering the fences based on the context pointers and then by sync_pt->fence.seqno, not the private sync value.
How does userspace try to order the fences other than as opaque fd? You actually mean driver_data is undefined ABI...
Quoted 9 lines
Quoted 8 lines
You could implement this as a secondary write to the HWS,
assigning thesync_valueto thesync_pton submission and remove the request tracking, as when signalled you only need to compare thesync_valueagainst the timeline value in the HWS.However, that equally applies to the existing
request->seqno. That can also be assigned on submission so that it always an ordered timeline, and so can be used internally or externally.
Quoted 8 lines
One of the scheduler patches is to defer seqno assignment until batch submission rather than do it at request creation (for execbuffer requests). You still have a problem with pre-emption though. A request that is pre-empted will get a new seqno assigned when it is resubmitted so that the HWS page always sees ordered values popping out. For internal requests, this is fine but for external sync points that breaks the assumptions made by the framework.
I fail to see how. Nothing in uapi/sync.h says anything about the order of fences or gives any such guarantees. If the external callers only have access through the fd, there is no restriction that the timeline sync_pt->value must be set prior to submission.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 61 lines · Chris Wilson
Quoted 39 lines · John Harrison
Quoted 34 lines · Chris Wilson
Quoted 25 lines · On Thu, Jul 02, 2015 at 12:09:59PM +0100, [email protected] wrote:
From: John Harrison <[email protected]>
Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retreive a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.
This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.
At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.
Quoted 8 lines
Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.
Quoted 4 lines
But there is nothing preventing assignment of the sync value on submission. Other than the debug .fence_value_str it's a private implementation detail, and the interface is solely through the fd and signalling.
Quoted 8 lines
No, it needs to be public from the moment of creation. The sync framework API allows sync points to be combined together to create fences that either merge multiple points on the same timeline or amalgamate points across differing timelines. The merging part means that the sync point must be capable of doing arithmetic comparisons with other sync points from the instant it is returned to user land. And those comparisons must not change in the future due to scheduler re-ordering because by then it is too late to redo the test.
You know that's not documented at all. The only information userspace gets is afaict
struct sync_pt_info { __u32 len; char obj_name[32]; char driver_name[32]; __s32 status; __u64 timestamp_ns; __u8 driver_data[0]; };
Quoted 6 lines
There is a merge operation done by combining two fence into a new one. Merging is done by ordering the fences based on the context pointers and then by
sync_pt->fence.seqno, not the private sync value.How does userspace try to order the fences other than as opaque fd? You actually mean
driver_datais undefined ABI...
Hmm, something looks confused. Way back when (i.e. the shipping Android tree), the 'private' seqno value was very definitely being exposed in various ways but it looks like it has actually been superseded by the seqno value inside the (new) fence object that is inside the sync_pt. Despite that, there is still a 'compare' callback in the timeline_ops for doing comparisons between sync_pts based on their private implementation specific seqno. Although this is marked as 'required' it is not actually called anywhere anymore! So it looks like we can drop the 'private' seqno value completely and just use the fence version.
In my defense, this code is all coming from the Android tree and the port to the nightly was done by someone else. I hadn't realised that nightly had changed quite so significantly.
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
You could implement this as a secondary write to the HWS,
assigning thesync_valueto thesync_pton submission and remove the request tracking, as when signalled you only need to compare thesync_valueagainst the timeline value in the HWS.However, that equally applies to the existing
request->seqno. That can also be assigned on submission so that it always an ordered timeline, and so can be used internally or externally.Quoted 8 lines
One of the scheduler patches is to defer seqno assignment until batch submission rather than do it at request creation (for execbuffer requests). You still have a problem with pre-emption though. A request that is pre-empted will get a new seqno assigned when it is resubmitted so that the HWS page always sees ordered values popping out. For internal requests, this is fine but for external sync points that breaks the assumptions made by the framework.
Quoted 4 lines
I fail to see how. Nothing in
uapi/sync.hsays anything about the order of fences or gives any such guarantees. If the external callers only have access through the fd, there is no restriction that the timelinesync_pt->valuemust be set prior to submission.
As noted above, it looks like the new version of the sync framework now allocates its own context/value seqno pair internally at creation time. So all my comments really refer to that seqno inside the struct fence. It seems like a bad idea that we are trying to shoe horn another seqno value on top.
Back to the drawing board...
Quoted 2 lines
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 79 lines · John Harrison
Quoted 61 lines · Chris Wilson
Quoted 39 lines · John Harrison
Quoted 34 lines · Chris Wilson
Quoted 25 lines · On Thu, Jul 02, 2015 at 12:09:59PM +0100, [email protected] wrote:
From: John Harrison <[email protected]>
Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retreive a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.
This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.
At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.
Quoted 8 lines
Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.
Quoted 4 lines
But there is nothing preventing assignment of the sync value on submission. Other than the debug .fence_value_str it's a private implementation detail, and the interface is solely through the fd and signalling.
Quoted 8 lines
No, it needs to be public from the moment of creation. The sync framework API allows sync points to be combined together to create fences that either merge multiple points on the same timeline or amalgamate points across differing timelines. The merging part means that the sync point must be capable of doing arithmetic comparisons with other sync points from the instant it is returned to user land. And those comparisons must not change in the future due to scheduler re-ordering because by then it is too late to redo the test.
You know that's not documented at all. The only information userspace gets is afaict
struct sync_pt_info { __u32 len; char obj_name[32]; char driver_name[32]; __s32 status; __u64 timestamp_ns; __u8 driver_data[0]; };Quoted 6 lines
There is a merge operation done by combining two fence into a new one. Merging is done by ordering the fences based on the context pointers and then by
sync_pt->fence.seqno, not the private sync value.How does userspace try to order the fences other than as opaque fd? You actually mean
driver_datais undefined ABI...Hmm, something looks confused. Way back when (i.e. the shipping Android tree), the 'private' seqno value was very definitely being exposed in various ways but it looks like it has actually been superseded by the seqno value inside the (new) fence object that is inside the
sync_pt. Despite that, there is still a 'compare' callback in thetimeline_opsfor doing comparisons betweensync_ptsbased on their private implementation specific seqno. Although this is marked as 'required' it is not actually called anywhere anymore! So it looks like we can drop the 'private' seqno value completely and just use the fence version.
Quoted 3 lines
In my defense, this code is all coming from the Android tree and the port to the nightly was done by someone else. I hadn't realised that nightly had changed quite so significantly.
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the sync_pt and not worry about its relationship to the execution seqno.
Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency... -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 10 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the
sync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to be less noisy and some prep patches omitted):
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
drivers/gpu/drm/i915/Kconfig +14 -0
@@ -71,3 +71,17 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT option changes the default for that module option. If in doubt, say "N". + +config DRM_I915_SYNC + bool "Enable explicit sync support" + depends on DRM_I915 + default y if STAGING + depends on STAGING + select ANDROID + select SYNC + help + Choose this option to enable Android native sync support and the + corresponding i915 driver code to expose it. Slightly increases + driver size and pulls in sync support from staging. + + If in doubt, say "Y".
drivers/gpu/drm/i915/Makefile +3 -0
@@ -91,6 +91,9 @@ i915-y += i915_vgpu.o # legacy horrors i915-y += i915_dma.o +# sync points +i915-$(CONFIG_DRM_I915_SYNC) += i915_sync.o + obj-$(CONFIG_DRM_I915) += i915.o CFLAGS_i915_trace_points.o := -I$(src)
drivers/gpu/drm/i915/i915_drv.h +20 -0
@@ -2753,6 +2753,26 @@ void i915_init_vm(struct drm_i915_private *dev_priv,void i915_gem_free_object (struct drm_gem_object *obj);void i915_gem_vma_destroy (struct i915_vma *vma); +/* i915_sync.c */ +struct sync_fence ; + +#ifdef CONFIG_DRM_I915_SYNC +int i915_fence_ring_fill_driver_data (struct fence *fence,void *data,int size); +void i915_fence_ring_value_str (struct fence *fence,char *str,int size); +void i915_fence_ring_timeline_value_str (struct fence *fence,char *str, +int size); + +int i915_create_sync_fence_ring (struct drm_i915_gem_request *req, +struct sync_fence **sync_fence,int *fence_fd); +#else +static inline +int i915_create_sync_fence_ring (struct drm_i915_gem_request *req, +struct sync_fence **sync_fence,int *fence_fd) +{ +return -ENODEV ; +} +#endif +#define PIN_MAPPABLE 0x1#define PIN_NONBLOCK 0x2#define PIN_GLOBAL 0x4
drivers/gpu/drm/i915/i915_gem.c +7 -1
@@ -2633,7 +2633,7 @@ static const char *i915_gem_request_get_timeline_name(struct fence *req_fence)return req->ring->name; } -#if 0 +#if CONFIG_DRM_I915_SYNC static bool i915_gem_request_is_signaled (struct fence *req_fence) { struct drm_i915_gem_request *req = container_of(req_fence,
@@ -2770,12 +2770,14 @@ static const struct fence_ops i915_gem_request_fops = { .get_driver_name = i915_gem_request_get_driver_name, .get_timeline_name = i915_gem_request_get_timeline_name, .enable_signaling = i915_gem_request_enable_signaling, .wait = fence_default_wait, .release = i915_gem_request_free, +#if CONFIG_DRM_I915_SYNC + .signaled = i915_gem_request_is_signaled, + .fill_driver_data = i915_fence_ring_fill_driver_data, + .fence_value_str = i915_fence_ring_value_str, + .timeline_value_str = i915_fence_ring_timeline_value_str +#endif }; int _i915_gem_request_alloc(struct intel_engine_cs *ring,
drivers/gpu/drm/i915/i915_gem_execbuffer.c +30 -0
@@ -32,6 +32,7 @@#include "i915_trace.h" #include "intel_drv.h" #include <linux/dma_remapping.h> +#include "../../../staging/android/sync.h" #define __EXEC_OBJECT_HAS_PIN (1<<31)#define __EXEC_OBJECT_HAS_FENCE (1<<30)
@@ -1417,6 +1418,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,u32 dispatch_flags;int ret;bool need_relocs; +struct sync_fence *sync_fence =NULL ; +int fence_fd =-1 ;if (!i915_gem_check_execbuffer (args))return -EINVAL ;
@@ -1610,6 +1613,13 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,if (ret) goto err_batch_unpin; +if (args->flags &I915_EXEC_FENCE_OUT ) { + ret =i915_create_sync_fence_ring (params->request, &sync_fence, + &fence_fd); +if (ret) + goto err_batch_unpin; + } + ret =i915_gem_request_add_to_client (params->request, file);if (ret) goto err_batch_unpin;
@@ -1628,6 +1638,26 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, params->ctx = ctx; ret = dev_priv->gt.execbuf_submit (params, args, &eb->vmas); +if (ret) + goto err_submit; + +if (sync_fence) { +sync_fence_install (sync_fence, fence_fd); + args->rsvd2 = fence_fd; + sync_fence =NULL ; + } + +err_submit: +if (sync_fence) { +/* +* We are under the struct mutex here and sync fence we +* created will attempt to grab it in its destructor. +* Therefore remove the lock before unreferencing. +*/ + sync_fence->lock =NULL ; +fput (sync_fence->file); +put_unused_fd (fence_fd); + } err_batch_unpin:/*
drivers/gpu/drm/i915/i915_sync.c new file +106 -0
106 lines not on this page · raw message
include/uapi/drm/i915_drm.h +5 -3
@@ -246,7 +246,7 @@ typedef struct _drm_i915_sarea {#define DRM_IOCTL_I915_HWS_ADDR DRM_IOW(DRM_COMMAND_BASE + DRM_I915_HWS_ADDR, struct drm_i915_gem_init)#define DRM_IOCTL_I915_GEM_INIT DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_INIT, struct drm_i915_gem_init)#define DRM_IOCTL_I915_GEM_EXECBUFFER DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER, struct drm_i915_gem_execbuffer) -#define DRM_IOCTL_I915_GEM_EXECBUFFER2 DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER2, struct drm_i915_gem_execbuffer2) +#define DRM_IOCTL_I915_GEM_EXECBUFFER2 DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER2, struct drm_i915_gem_execbuffer2)#define DRM_IOCTL_I915_GEM_PIN DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_PIN, struct drm_i915_gem_pin)#define DRM_IOCTL_I915_GEM_UNPIN DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_UNPIN, struct drm_i915_gem_unpin)#define DRM_IOCTL_I915_GEM_BUSY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_BUSY, struct drm_i915_gem_busy)
@@ -722,7 +722,7 @@ struct drm_i915_gem_execbuffer2 {#define I915_EXEC_CONSTANTS_REL_SURFACE (2<<6)/* gen4/5 only */ __u64 flags;__u64 rsvd1;/* now used for context info */ -__u64 rsvd2; +__u64 rsvd2;/* now used for fence fd */ };/** Resets the SO write offset registers for transform feedback on gen7. */
@@ -760,7 +760,9 @@ struct drm_i915_gem_execbuffer2 {#define I915_EXEC_BSD_RING1 (1<<13)#define I915_EXEC_BSD_RING2 (2<<13) -#define __I915_EXEC_UNKNOWN_FLAGS -(1<<15) +#define I915_EXEC_FENCE_OUT (1<<15) + +#define __I915_EXEC_UNKNOWN_FLAGS -(1<<16)#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)#define i915_execbuffer2_set_context_id (eb2, context) \
Signature · 7 lines
2.4.0 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 26 lines · Tvrtko Ursulin
Quoted 10 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the
sync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to be less noisy and some prep patches omitted):
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 8 lines
drivers/gpu/drm/i915/Kconfig +0
-0@@ -71,3 +71,17 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT option changes the default for that module option.
drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 82
Quoted 10 lines
drivers/gpu/drm/i915/Kconfig +9
-0If in doubt, say "N". + +config DRM_I915_SYNC + bool "Enable explicit sync support" + depends on DRM_I915 + default y if STAGING + depends on STAGING + select ANDROID + select SYNC + help
No Kconfig for userspace ABI please. Yes this means we need to destage android syncpts first. The problem I see there is that apparently google is still changing the uabi a lot, and that's a no-go for upstream. And it needs to be cleaned up to work more seamlessly with struct fence (i.e. anything that's missing there should be moved to struct fence, drivers should only use fd_to_fence and fenct_to_fd functions similar to dma-buf).
And we don't have anyone except android using syncpts, so a bit a trouble with finding userspace vehicles for this. We probably need agreement from google to be happy with a frozen abi for syncpts first ... -Daniel
Quoted 293 lines
drivers/gpu/drm/i915/Kconfig +5
-0+ Choose this option to enable Android native sync support and the + corresponding i915 driver code to expose it. Slightly increases + driver size and pulls in sync support from staging. + + If in doubt, say "Y".drivers/gpu/drm/i915/Makefile +3
-0@@ -91,6 +91,9 @@ i915-y += i915_vgpu.o # legacy horrors i915-y += i915_dma.o +# sync points +i915-$(CONFIG_DRM_I915_SYNC) += i915_sync.o + obj-$(CONFIG_DRM_I915) += i915.o CFLAGS_i915_trace_points.o := -I$(src)drivers/gpu/drm/i915/i915_drv.h +20
-0@@ -2753,6 +2753,26 @@ void i915_init_vm(struct drm_i915_private *dev_priv,void i915_gem_free_object (struct drm_gem_object *obj);void i915_gem_vma_destroy (struct i915_vma *vma); +/* i915_sync.c */ +struct sync_fence ; + +#ifdef CONFIG_DRM_I915_SYNC +int i915_fence_ring_fill_driver_data (struct fence *fence,void *data,int size); +void i915_fence_ring_value_str (struct fence *fence,char *str,int size); +void i915_fence_ring_timeline_value_str (struct fence *fence,char *str, +int size); + +int i915_create_sync_fence_ring (struct drm_i915_gem_request *req, +struct sync_fence **sync_fence,int *fence_fd); +#else +static inline +int i915_create_sync_fence_ring (struct drm_i915_gem_request *req, +struct sync_fence **sync_fence,int *fence_fd) +{ +return -ENODEV ; +} +#endif +#define PIN_MAPPABLE 0x1#define PIN_NONBLOCK 0x2#define PIN_GLOBAL 0x4drivers/gpu/drm/i915/i915_gem.c +7
-1@@ -2633,7 +2633,7 @@ static const char *i915_gem_request_get_timeline_name(struct fence *req_fence)return req->ring->name; } -#if 0 +#if CONFIG_DRM_I915_SYNC static bool i915_gem_request_is_signaled (struct fence *req_fence) { struct drm_i915_gem_request *req = container_of(req_fence,@@ -2770,12 +2770,14 @@ static const struct fence_ops i915_gem_request_fops = { .get_driver_name = i915_gem_request_get_driver_name, .get_timeline_name = i915_gem_request_get_timeline_name, .enable_signaling = i915_gem_request_enable_signaling, .wait = fence_default_wait, .release = i915_gem_request_free, +#if CONFIG_DRM_I915_SYNC + .signaled = i915_gem_request_is_signaled, + .fill_driver_data = i915_fence_ring_fill_driver_data, + .fence_value_str = i915_fence_ring_value_str, + .timeline_value_str = i915_fence_ring_timeline_value_str +#endif }; int _i915_gem_request_alloc(struct intel_engine_cs *ring,drivers/gpu/drm/i915/i915_gem_execbuffer.c +30
-0@@ -32,6 +32,7 @@#include "i915_trace.h" #include "intel_drv.h" #include <linux/dma_remapping.h> +#include "../../../staging/android/sync.h" #define __EXEC_OBJECT_HAS_PIN (1<<31)#define __EXEC_OBJECT_HAS_FENCE (1<<30)@@ -1417,6 +1418,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,u32 dispatch_flags;int ret;bool need_relocs; +struct sync_fence *sync_fence =NULL ; +int fence_fd =-1 ;if (!i915_gem_check_execbuffer (args))return -EINVAL ;@@ -1610,6 +1613,13 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,if (ret) goto err_batch_unpin; +if (args->flags &I915_EXEC_FENCE_OUT ) { + ret =i915_create_sync_fence_ring (params->request, &sync_fence, + &fence_fd); +if (ret) + goto err_batch_unpin; + } + ret =i915_gem_request_add_to_client (params->request, file);if (ret) goto err_batch_unpin;@@ -1628,6 +1638,26 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, params->ctx = ctx; ret = dev_priv->gt.execbuf_submit (params, args, &eb->vmas); +if (ret) + goto err_submit; + +if (sync_fence) { +sync_fence_install (sync_fence, fence_fd); + args->rsvd2 = fence_fd; + sync_fence =NULL ; + } + +err_submit: +if (sync_fence) { +/* +* We are under the struct mutex here and sync fence we +* created will attempt to grab it in its destructor. +* Therefore remove the lock before unreferencing. +*/ + sync_fence->lock =NULL ; +fput (sync_fence->file); +put_unused_fd (fence_fd); + } err_batch_unpin:/* drivers/gpu/drm/i915/i915_sync.c new file +106
-0@@ -0,0 +1,106 @@ +/* +* Copyright © 2013-2015 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +* Authors: +* Jesse Barnes <[email protected]> +* Tvrtko Ursulin <[email protected]> +* +*/ + +#include <linux/fs.h> +#include <linux/fence.h> +#include "../../../staging/android/sync.h" +#include "i915_drv.h" + +/* +* i915 Android native sync fences. +* +* We implement sync points in terms of i915 seqnos. They're exposed through +* the DRM_IOCTL_I915_GEM_EXECBUFFER2 ioctl, and can be mixed and matched +* with other Android timelines and aggregated into sync_fences, etc. +* +* TODO: +* * Display engine fences. +* * Extend driver data with context id / ring id. +*/ + +int i915_fence_ring_fill_driver_data (struct fence *fence,void *data,int size) +{ +struct drm_i915_gem_request *req =container_of (fence,typeof (*req), + fence); + +if (size <sizeof (req->seqno)) +return -ENOMEM ; + +memcpy (data, &req->seqno,sizeof (req->seqno)); + +return sizeof (req->seqno); +} + +void i915_fence_ring_value_str (struct fence *fence,char *str,int size) +{ +struct drm_i915_gem_request *req =container_of (fence,typeof (*req), + fence); + +snprintf (str, size,"%u" , req->seqno); +} + +void i915_fence_ring_timeline_value_str (struct fence *fence,char *str, +int size) +{ +struct drm_i915_gem_request *req =container_of (fence,typeof (*req), + fence); +struct intel_engine_cs *ring = req->ring; + +snprintf (str, size,"%u" , ring->get_seqno (ring, false)); +} + +int i915_create_sync_fence_ring (struct drm_i915_gem_request *req, +struct sync_fence **sync_fence,int *fence_fd) +{ +struct drm_device *dev = req->i915->dev; +struct intel_engine_cs *ring = req->ring; +struct sync_fence *sfence; +char ring_name[6 ] ="ring0" ; +int fd; + + fd =get_unused_fd_flags (O_CLOEXEC ); +if (fd <0 ) { +DRM_DEBUG ("No available file descriptors!\n" ); +return fd; + } + + ring_name[4 ] += ring->id; + sfence =sync_fence_create_dma (ring_name, &req->fence, + &dev->struct_mutex); +if (!sfence) { +put_unused_fd (fd); +return -ENOMEM ; + } + + *sync_fence = sfence; + *fence_fd = fd; + +fence_get (&req->fence); + +return 0 ; +}include/uapi/drm/i915_drm.h +5
-3@@ -246,7 +246,7 @@ typedef struct _drm_i915_sarea {#define DRM_IOCTL_I915_HWS_ADDR DRM_IOW(DRM_COMMAND_BASE + DRM_I915_HWS_ADDR, struct drm_i915_gem_init)#define DRM_IOCTL_I915_GEM_INIT DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_INIT, struct drm_i915_gem_init)#define DRM_IOCTL_I915_GEM_EXECBUFFER DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER, struct drm_i915_gem_execbuffer) -#define DRM_IOCTL_I915_GEM_EXECBUFFER2 DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER2, struct drm_i915_gem_execbuffer2) +#define DRM_IOCTL_I915_GEM_EXECBUFFER2 DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER2, struct drm_i915_gem_execbuffer2)#define DRM_IOCTL_I915_GEM_PIN DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_PIN, struct drm_i915_gem_pin)#define DRM_IOCTL_I915_GEM_UNPIN DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_UNPIN, struct drm_i915_gem_unpin)#define DRM_IOCTL_I915_GEM_BUSY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_BUSY, struct drm_i915_gem_busy)@@ -722,7 +722,7 @@ struct drm_i915_gem_execbuffer2 {#define I915_EXEC_CONSTANTS_REL_SURFACE (2<<6)/* gen4/5 only */ __u64 flags;__u64 rsvd1;/* now used for context info */ -__u64 rsvd2; +__u64 rsvd2;/* now used for fence fd */ };/** Resets the SO write offset registers for transform feedback on gen7. */ @@ -760,7 +760,9 @@ struct drm_i915_gem_execbuffer2 {#define I915_EXEC_BSD_RING1 (1<<13)#define I915_EXEC_BSD_RING2 (2<<13) -#define __I915_EXEC_UNKNOWN_FLAGS -(1<<15) +#define I915_EXEC_FENCE_OUT (1<<15) + +#define __I915_EXEC_UNKNOWN_FLAGS -(1<<16)#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)#define i915_execbuffer2_set_context_id (eb2, context) \Signature · 7 lines
2.4.0 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 25 lines · Daniel Vetter
Quoted 24 lines · Tvrtko Ursulin
Quoted 10 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the
sync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to be less noisy and some prep patches omitted):
Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/Kconfig +0
-0@@ -71,3 +71,17 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT option changes the default for that module option.
Quoted 12 lines
drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 82
Quoted 10 lines
drivers/gpu/drm/i915/Kconfig +9
-0If in doubt, say "N". + +config DRM_I915_SYNC + bool "Enable explicit sync support" + depends on DRM_I915 + default y if STAGING + depends on STAGING + select ANDROID + select SYNC + helpNo
Kconfigfor userspace ABI please. Yes this means we need to destage android syncpts first.
There is already a CONFIG_SYNC flag that wraps up all the existing sync code in the staging branch. There's not a lot we can do about that is there? We have to at least wrap the sync specific code in the i915 driver with '#if CONFIG_SYNC' otherwise it won't compile.
Quoted 5 lines
The problem I see there is that apparently google
is still changing the uabi a lot, and that's a no-go for upstream. And it needs to be cleaned up to work more seamlessly with struct fence (i.e. anything that's missing there should be moved to struct fence, drivers should only usefd_to_fenceandfenct_to_fdfunctions similar to dma-buf).
Are Google changing it or is it upstream that are changing it? The only changes to android/staging/sync.c have been a few minor bug fixes and Maarten Lankhorst's conversion to use struct fence which was back in July last year.
Quoted 4 lines
And we don't have anyone except android using syncpts, so a bit a trouble with finding userspace vehicles for this. We probably need agreement from google to be happy with a frozen abi for syncpts first ... -Daniel
I believe Jesse is wanting to use it for his work.
John.
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 31 lines · John Harrison
Quoted 25 lines · Daniel Vetter
Quoted 24 lines · Tvrtko Ursulin
Quoted 10 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the
sync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to be less noisy and some prep patches omitted):
Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 12 lines
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
The solution to this problem is to have a mem cgroup limit set. No need to complicate our kernel code.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/Kconfig +3
-0@@ -71,3 +71,17 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT option changes the default for that module option. If in doubt, say "N". + +config DRM_I915_SYNC + bool "Enable explicit sync support"Quoted 8 lines
drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 82
Quoted 6 lines
drivers/gpu/drm/i915/Kconfig +6
-0+ depends on DRM_I915 + default y if STAGING + depends on STAGING + select ANDROID + select SYNC + helpNo
Kconfigfor userspace ABI please. Yes this means we need to destage android syncpts first.
Quoted 4 lines
There is already a
CONFIG_SYNCflag that wraps up all the existing sync code in the staging branch. There's not a lot we can do about that is there? We have to at least wrap the sync specific code in the i915 driver with '#ifCONFIG_SYNC' otherwise it won't compile.
User-settable CONFIG_SYNC is one of these bits we need to fix up when de-staging - it should be an internal variable which is selected by i915, like all the other optional kernel services we use.
Quoted 10 lines
Quoted 5 lines
The problem I see there is that apparently google
is still changing the uabi a lot, and that's a no-go for upstream. And it needs to be cleaned up to work more seamlessly with struct fence (i.e. anything that's missing there should be moved to struct fence, drivers should only usefd_to_fenceandfenct_to_fdfunctions similar to dma-buf).Are Google changing it or is it upstream that are changing it? The only changes to
android/staging/sync.chave been a few minor bug fixes and Maarten Lankhorst's conversion to use struct fence which was back in July last year.
destaging android syncpt will probably require a few changes, but more so it will freeze the abi. If we do that effort and google ignores it it's fairly pointless (as long as android is the only serious user of syncpts).
Quoted 6 lines
Quoted 4 lines
And we don't have anyone except android using syncpts, so a bit a trouble with finding userspace vehicles for this. We probably need agreement from google to be happy with a frozen abi for syncpts first ... -Daniel
I believe Jesse is wanting to use it for his work.
Yes I know, but afaik it's also a long way off. Which means not useful as an open-source demonstration vehicle unfortunately.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 44 lines · Daniel Vetter
Quoted 31 lines · John Harrison
Quoted 25 lines · Daniel Vetter
Quoted 24 lines · Tvrtko Ursulin
Quoted 10 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the
sync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to be less noisy and some prep patches omitted):
Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 12 lines
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
Quoted 6 lines
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
The solution to this problem is to have a mem cgroup limit set. No need to complicate our kernel code.
There is still the extra complication that request unreferencing cannot require any kind of mutex lock if we are allowing it to happen from outside of the driver. That means the unreference callback must move the request to a 'please clean me later' list, schedule a worker thread to run, and thus do the clean up asynchronously.
Quoted 39 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/Kconfig +3
-0@@ -71,3 +71,17 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT option changes the default for that module option. If in doubt, say "N". + +config DRM_I915_SYNC + bool "Enable explicit sync support"Quoted 8 lines
drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 82
Quoted 6 lines
drivers/gpu/drm/i915/Kconfig +6
-0+ depends on DRM_I915 + default y if STAGING + depends on STAGING + select ANDROID + select SYNC + helpNo
Kconfigfor userspace ABI please. Yes this means we need to destage android syncpts first.Quoted 4 lines
There is already a
CONFIG_SYNCflag that wraps up all the existing sync code in the staging branch. There's not a lot we can do about that is there? We have to at least wrap the sync specific code in the i915 driver with '#ifCONFIG_SYNC' otherwise it won't compile.User-settable
CONFIG_SYNCis one of these bits we need to fix up when de-staging - it should be an internal variable which is selected by i915, like all the other optional kernel services we use.Quoted 9 lines
Quoted 5 lines
The problem I see there is that apparently google
is still changing the uabi a lot, and that's a no-go for upstream. And it needs to be cleaned up to work more seamlessly with struct fence (i.e. anything that's missing there should be moved to struct fence, drivers should only usefd_to_fenceandfenct_to_fdfunctions similar to dma-buf).Are Google changing it or is it upstream that are changing it? The only changes to
android/staging/sync.chave been a few minor bug fixes and Maarten Lankhorst's conversion to use struct fence which was back in July last year.destaging android syncpt will probably require a few changes, but more so it will freeze the abi. If we do that effort and google ignores it it's fairly pointless (as long as android is the only serious user of syncpts).
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
And we don't have anyone except android using syncpts, so a bit a trouble with finding userspace vehicles for this. We probably need agreement from google to be happy with a frozen abi for syncpts first ... -Daniel
I believe Jesse is wanting to use it for his work.
Yes I know, but afaik it's also a long way off. Which means not useful as an open-source demonstration vehicle unfortunately.
-Daniel
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 49 lines · John Harrison
Quoted 48 lines · Daniel Vetter
Quoted 31 lines · John Harrison
Quoted 25 lines · Daniel Vetter
Quoted 24 lines · Tvrtko Ursulin
Quoted 10 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating the
sync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not sure if that is a problem or not.
Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to be less noisy and some prep patches omitted):
Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 12 lines
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
Quoted 8 lines
Quoted 2 lines
The solution to this problem is to have a mem cgroup limit set. No need to complicate our kernel code.
There is still the extra complication that request unreferencing cannot require any kind of mutex lock if we are allowing it to happen from outside of the driver. That means the unreference callback must move the request to a 'please clean me later' list, schedule a worker thread to run, and thus do the clean up asynchronously.
Yeah, struct_mutex locking design is terribly, and we'll pay the prize for that dearly until it's eventually fixed up. We can optimize it at least with a mutex_try_lock.
Or we just fix up request tracking to not require struct_mutex, that might be better. All the references we hold onto the request should point one way with no weak references going the other direction, so this should be possible.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 73 lines · John Harrison
Quoted 64 lines · Daniel Vetter
Quoted 55 lines · John Harrison
Quoted 37 lines · Daniel Vetter
Quoted 36 lines · Tvrtko Ursulin
Quoted 16 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external
fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like
we could just add such a stamp when creating thesync_ptand not worry
about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the
signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 7 lines
Afaict the sync uapi is based on waiting for all of a set of fences to
retire. It doesn't seem to rely on fence ordering (that is knowing that
fence A will signal before fence B so it need only wait on fence B).Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but
timeline business has always been confusing me. There is nothing in the
uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 6 lines
Quoted 4 lines
This implements the ioctl based uapi and indeed seqnos are not actually
used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object
to user land via a file descriptor (or indeed any other mechanism) then that
fence object must be locked until user land closes the file. If the fence
object is the one embedded within our request structure then that means user
land is effectively locking our request structure. Given that more and moreQuoted 8 lines
stuff is being attached to the request, that could be a fair bit of memory
tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't
really care so much.Quoted 7 lines
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
The solution to this problem is to have a mem cgroup limit set. No need to
complicate our kernel code.
Quoted 5 lines
There is still the extra complication that request unreferencing cannot require any kind of mutex lock if we are allowing it to happen from outside of the driver. That means the unreference callback must move the request to a 'please clean me later' list, schedule a worker thread to run, and thus do the clean up asynchronously.
For this particular issue my solution was to extend the sync_fence constructor to take a mutex and store it inside the object. Then at destruction time, which happens at sync_fd->f_ops->release() time, it is just a matter of calling kref_put_mutex instead of kref_put.
Seemed to work under some quick testing but that is as much as I did back then.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 81 lines · Tvrtko Ursulin
Quoted 73 lines · John Harrison
Quoted 64 lines · Daniel Vetter
Quoted 55 lines · John Harrison
Quoted 37 lines · Daniel Vetter
Quoted 36 lines · Tvrtko Ursulin
Quoted 16 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external
fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like
we could just add such a stamp when creating thesync_ptand not worry
about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the
signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 7 lines
Afaict the sync uapi is based on waiting for all of a set of fences to
retire. It doesn't seem to rely on fence ordering (that is knowing that
fence A will signal before fence B so it need only wait on fence B).Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but
timeline business has always been confusing me. There is nothing in the
uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 6 lines
Quoted 4 lines
This implements the ioctl based uapi and indeed seqnos are not actually
used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object
to user land via a file descriptor (or indeed any other mechanism) then that
fence object must be locked until user land closes the file. If the fence
object is the one embedded within our request structure then that means user
land is effectively locking our request structure. Given that more and moreQuoted 8 lines
stuff is being attached to the request, that could be a fair bit of memory
tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't
really care so much.Quoted 7 lines
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
The solution to this problem is to have a mem cgroup limit set. No need to
complicate our kernel code.Quoted 5 lines
There is still the extra complication that request unreferencing cannot require any kind of mutex lock if we are allowing it to happen from outside of the driver. That means the unreference callback must move the request to a 'please clean me later' list, schedule a worker thread to run, and thus do the clean up asynchronously.
Quoted 7 lines
For this particular issue my solution was to extend the
sync_fenceconstructor to take a mutex and store it inside the object. Then at destruction time, which happens atsync_fd->f_ops->release()time, it is just a matter of callingkref_put_mutexinstead ofkref_put.Seemed to work under some quick testing but that is as much as I did back then.
The problem is that it doesn't scale since everyone wants some other kind of mutex to serialize the final kref_put. If something is supposed to be cross-subsystem/driver (which is the case for fences) then we really can't do that kind of leaky locking design. Imo we should have a kref_put_mutex considered harmful sign somewhere ...
If you have weak references somewhere and need to prevent the object from disappearing untimely while chasing that weak reference then imo the better design pattern is to use kref_get_unless_zero. If you need the serialization the mutex provides for some other reason (someone is only hodling the mutex instead of grabbing a proper refernce when they really should grab one) then your refcounting scheme probably needs another kind of fixup patch.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 86 lines · Daniel Vetter
Quoted 85 lines · Tvrtko Ursulin
Quoted 73 lines · John Harrison
Quoted 64 lines · Daniel Vetter
Quoted 55 lines · John Harrison
Quoted 37 lines · Daniel Vetter
Quoted 36 lines · Tvrtko Ursulin
Quoted 16 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external
fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like
we could just add such a stamp when creating thesync_ptand not worry
about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the
signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 7 lines
Afaict the sync uapi is based on waiting for all of a set of fences to
retire. It doesn't seem to rely on fence ordering (that is knowing that
fence A will signal before fence B so it need only wait on fence B).Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but
timeline business has always been confusing me. There is nothing in the
uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 6 lines
Quoted 4 lines
This implements the ioctl based uapi and indeed seqnos are not actually
used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object
to user land via a file descriptor (or indeed any other mechanism) then that
fence object must be locked until user land closes the file. If the fence
object is the one embedded within our request structure then that means user
land is effectively locking our request structure. Given that more and moreQuoted 8 lines
stuff is being attached to the request, that could be a fair bit of memory
tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't
really care so much.Quoted 7 lines
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
The solution to this problem is to have a mem cgroup limit set. No need to
complicate our kernel code.Quoted 5 lines
There is still the extra complication that request unreferencing cannot require any kind of mutex lock if we are allowing it to happen from outside of the driver. That means the unreference callback must move the request to a 'please clean me later' list, schedule a worker thread to run, and thus do the clean up asynchronously.
For this particular issue my solution was to extend the
sync_fenceconstructor to take a mutex and store it inside the object. Then at destruction time, which happens atsync_fd->f_ops->release()time, it is just a matter of callingkref_put_mutexinstead ofkref_put.
Quoted 8 lines
Quoted 2 lines
Seemed to work under some quick testing but that is as much as I did back then.
The problem is that it doesn't scale since everyone wants some other kind of mutex to serialize the final
kref_put. If something is supposed to be cross-subsystem/driver (which is the case for fences) then we really can't do that kind of leaky locking design. Imo we should have akref_put_mutexconsidered harmful sign somewhere ...
I get the argument about everything wanting to add their own not scaling, but don't tie with the leaky comment? Also mutex is a pretty standard thing, especially since kref_put_mutex. :D If you look at it from that angle it kind of just exposes to the super class what the base class can do.
Quoted 7 lines
If you have weak references somewhere and need to prevent the object from disappearing untimely while chasing that weak reference then imo the better design pattern is to use
kref_get_unless_zero. If you need the serialization the mutex provides for some other reason (someone is only hodling the mutex instead of grabbing a proper refernce when they really should grab one) then your refcounting scheme probably needs another kind of fixup patch.
I don't see how weak references can work since if the request goes information is lost, unless stored somewhere else.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 97 lines · Tvrtko Ursulin
Quoted 86 lines · Daniel Vetter
Quoted 85 lines · Tvrtko Ursulin
Quoted 73 lines · John Harrison
Quoted 64 lines · Daniel Vetter
Quoted 55 lines · John Harrison
Quoted 37 lines · Daniel Vetter
Quoted 36 lines · Tvrtko Ursulin
Quoted 16 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external
fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like
we could just add such a stamp when creating thesync_ptand not worry
about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the
signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 7 lines
Afaict the sync uapi is based on waiting for all of a set of fences to
retire. It doesn't seem to rely on fence ordering (that is knowing that
fence A will signal before fence B so it need only wait on fence B).Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but
timeline business has always been confusing me. There is nothing in the
uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 6 lines
Quoted 4 lines
This implements the ioctl based uapi and indeed seqnos are not actually
used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object
to user land via a file descriptor (or indeed any other mechanism) then that
fence object must be locked until user land closes the file. If the fence
object is the one embedded within our request structure then that means user
land is effectively locking our request structure. Given that more and moreQuoted 8 lines
stuff is being attached to the request, that could be a fair bit of memory
tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't
really care so much.Quoted 7 lines
Userspace can exhaust kernel allocations, that's nothing new. And if we keep it userspace simply needs to leak a few more fence fds than if there's a bit more data attached to it.
The solution to this problem is to have a mem cgroup limit set. No need to
complicate our kernel code.Quoted 5 lines
There is still the extra complication that request unreferencing cannot require any kind of mutex lock if we are allowing it to happen from outside of the driver. That means the unreference callback must move the request to a 'please clean me later' list, schedule a worker thread to run, and thus do the clean up asynchronously.
For this particular issue my solution was to extend the
sync_fenceconstructor to take a mutex and store it inside the object. Then at destruction time, which happens atsync_fd->f_ops->release()time, it is just a matter of callingkref_put_mutexinstead ofkref_put.Quoted 8 lines
Quoted 2 lines
Seemed to work under some quick testing but that is as much as I did back then.
The problem is that it doesn't scale since everyone wants some other kind of mutex to serialize the final
kref_put. If something is supposed to be cross-subsystem/driver (which is the case for fences) then we really can't do that kind of leaky locking design. Imo we should have akref_put_mutexconsidered harmful sign somewhere ...
Quoted 4 lines
I get the argument about everything wanting to add their own not scaling, but don't tie with the leaky comment? Also mutex is a pretty standard thing, especially since
kref_put_mutex. :D If you look at it from that angle it kind of just exposes to the super class what the base class can do.
leaky not as in leaking memory, but leaky abstraction - we impose locking internals for i915 onto users of the fence interface (somewhat at least).
Quoted 11 lines
Quoted 8 lines
If you have weak references somewhere and need to prevent the object from disappearing untimely while chasing that weak reference then imo the better design pattern is to use
kref_get_unless_zero. If you need the serialization the mutex provides for some other reason (someone is only hodling the mutex instead of grabbing a proper refernce when they really should grab one) then your refcounting scheme probably needs another kind of fixup patch.I don't see how weak references can work since if the request goes information is lost, unless stored somewhere else.
So weak refernce is a pointer which doesn't hold a reference to the object controlled with kref, but protected by some lock. Latest when the object is destroyed we need to clear that pointer in the free callback of kref_put (and so also grab the lock that protects that pointer). The problem is that anyone else chasing that weak reference might race with the final kref_put and increase the refcount from 0 to 1, which isn't good.
There's two ways to do that:
- kref_put_mutex on the release side.
- in the acquire side do a kref_get_unless_zero _while_ holding that lock.
Two upsides of the later approach:
- You can have an unrestricted amount of weak references, each protected with their own lock. kref_put_mutex only works up to one.
- It doesn't serialize the final kref_put with the lock - doing that allows folks to rely on the mutex instead of a proper refcount to make the obj stick around, which is imo a design antipattern that I suffered through trying to cleaning it up agian a lot.
But that's really a tangent to the discussion here, I have no idea whether this applies here since I didn't read your patch in detail. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 36 lines · Daniel Vetter
Quoted 12 lines · Tvrtko Ursulin
Quoted 9 lines · Daniel Vetter
On Mon, Jul 06, 2015 at 03:46:49PM +0100, Tvrtko Ursulin wrote:
If you have weak references somewhere and need to prevent the object from disappearing untimely while chasing that weak reference then imo the better design pattern is to use
kref_get_unless_zero. If you need the serialization the mutex provides for some other reason (someone is only hodling the mutex instead of grabbing a proper refernce when they really should grab one) then your refcounting scheme probably needs another kind of fixup patch.Quoted 2 lines
I don't see how weak references can work since if the request goes information is lost, unless stored somewhere else.
So weak refernce is a pointer which doesn't hold a reference to the object controlled with kref, but protected by some lock. Latest when the object is destroyed we need to clear that pointer in the free callback of
kref_put(and so also grab the lock that protects that pointer). The problem is that anyone else chasing that weak reference might race with the finalkref_putand increase the refcount from 0 to 1, which isn't good.There's two ways to do that:
-kref_put_mutexon the release side.
- in the acquire side do akref_get_unless_zero_while_ holding that lock.Two upsides of the later approach:
- You can have an unrestricted amount of weak references, each protected with their own lock.kref_put_mutexonly works up to one.
- It doesn't serialize the finalkref_putwith the lock - doing that allows folks to rely on the mutex instead of a proper refcount to make the obj stick around, which is imo a design antipattern that I suffered through trying to cleaning it up agian a lot.
Quoted 2 lines
But that's really a tangent to the discussion here, I have no idea whether this applies here since I didn't read your patch in detail.
I think it is not about my patch but whether the Android native sync implementation handles losing the weak reference on a fence.
I don't think it does and I am not sure how easy or hard would it be to change it right now. (The whole area traditionally confuses me since there are too many things called sync something and fence something.)
I would need to handle it to be able at least report the status of a fence to userspace and gracefully fail other operations. And that is assuming that wouldn't break existing userspace.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 44 lines · Tvrtko Ursulin
Quoted 36 lines · Daniel Vetter
Quoted 12 lines · Tvrtko Ursulin
Quoted 9 lines · Daniel Vetter
On Mon, Jul 06, 2015 at 03:46:49PM +0100, Tvrtko Ursulin wrote:
If you have weak references somewhere and need to prevent the object from disappearing untimely while chasing that weak reference then imo the better design pattern is to use
kref_get_unless_zero. If you need the serialization the mutex provides for some other reason (someone is only hodling the mutex instead of grabbing a proper refernce when they really should grab one) then your refcounting scheme probably needs another kind of fixup patch.Quoted 2 lines
I don't see how weak references can work since if the request goes information is lost, unless stored somewhere else.
So weak refernce is a pointer which doesn't hold a reference to the object controlled with kref, but protected by some lock. Latest when the object is destroyed we need to clear that pointer in the free callback of
kref_put(and so also grab the lock that protects that pointer). The problem is that anyone else chasing that weak reference might race with the finalkref_putand increase the refcount from 0 to 1, which isn't good.There's two ways to do that:
-kref_put_mutexon the release side.
- in the acquire side do akref_get_unless_zero_while_ holding that lock.Two upsides of the later approach:
- You can have an unrestricted amount of weak references, each protected with their own lock.kref_put_mutexonly works up to one.
- It doesn't serialize the finalkref_putwith the lock - doing that allows folks to rely on the mutex instead of a proper refcount to make the obj stick around, which is imo a design antipattern that I suffered through trying to cleaning it up agian a lot.Quoted 2 lines
But that's really a tangent to the discussion here, I have no idea whether this applies here since I didn't read your patch in detail.
I think it is not about my patch but whether the Android native sync implementation handles losing the weak reference on a fence.
Quoted 7 lines
I don't think it does and I am not sure how easy or hard would it be to change it right now. (The whole area traditionally confuses me since there are too many things called sync something and fence something.)
I would need to handle it to be able at least report the status of a fence to userspace and gracefully fail other operations. And that is assuming that wouldn't break existing userspace.
For reporting status it should grab a strong reference. I thought this was about i915-internal lists and stuff we use to keep track of our own requests, for which we'd need struct_mutex. struct_mutex won't protect any of the syncpt internal state. I guess I'm rather confused now what this is about ...
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 35 lines · John Harrison
Quoted 29 lines · Daniel Vetter
Quoted 28 lines · Tvrtko Ursulin
Quoted 12 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating thesync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 13 lines
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
I am starting to agree gradually with this view. Given all the complications, referencing requests for exporting via fds feels quite heavy-weight, with potentially unbound dependencies and more trickiness in the future, even if we agreed on referencing and locking details.
Seqnos per context sounds like a significantly more light-weight and decoupled implementation.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 51 lines · Tvrtko Ursulin
Quoted 35 lines · John Harrison
Quoted 29 lines · Daniel Vetter
Quoted 28 lines · Tvrtko Ursulin
Quoted 12 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating thesync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 13 lines
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
Quoted 8 lines
I am starting to agree gradually with this view. Given all the complications, referencing requests for exporting via fds feels quite heavy-weight, with potentially unbound dependencies and more trickiness in the future, even if we agreed on referencing and locking details.
Seqnos per context sounds like a significantly more light-weight and decoupled implementation.
I think this is the right long term direction as well; conceptually the per-context seqnos make the most sense in light of scheduling, and they let us keep things simple for sync pts as well. Only question is, who is signed up to make it all work?
Jesse
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 56 lines · Jesse Barnes
Quoted 55 lines · Tvrtko Ursulin
Quoted 35 lines · John Harrison
Quoted 29 lines · Daniel Vetter
Quoted 28 lines · Tvrtko Ursulin
Quoted 12 lines · Chris Wilson
It would be nice if we could reuse one seqno both for internal/external fences. If you need to expose a fence ordering within a timeline that is
based on the creation stamp rather than execution stamp, it seems like we could just add such a stamp when creating thesync_ptand not worry about its relationship to the execution seqno.Doing so does expose that requests are reordered to userspace since the signalling timeline is not the same as userspace's ordered timeline. Not
sure if that is a problem or not.Quoted 5 lines
Afaict the sync uapi is based on waiting for all of a set of fences to retire. It doesn't seem to rely on fence ordering (that is knowing that fence A will signal before fence B so it need only wait on fence B).
Here's hoping that we can have both simplicity and efficiency...
Jumping in with not even perfect understanding of everything here - but timeline business has always been confusing me. There is nothing in the uapi which needs it afaics and iirc there was some discussion at the time
Jesse floated his patches that it can be removed. Based on that when I squashed his patches and ported them on top of John's request to fence conversion it ended up something like the below (manually edited a bit to
be less noisy and some prep patches omitted):Quoted 5 lines
Quoted 3 lines
This implements the ioctl based uapi and indeed seqnos are not actually used in waits. So is this insufficient for some reason? (Other that it does not implement the input fence side of things.)
Yeah android syncpt on top of struct fence embedded int i915 request is what I'd have expected.
Quoted 13 lines
The thing I'm not happy with in that plan is that it leaves the kernel driver at the mercy of user land applications. If we return a fence object to user land via a file descriptor (or indeed any other mechanism) then that fence object must be locked until user land closes the file. If the fence object is the one embedded within our request structure then that means user land is effectively locking our request structure. Given that more and more stuff is being attached to the request, that could be a fair bit of memory tied up that we can do nothing about. E.g. if a rogue/buggy application requests a fence be returned for every batch buffer submitted but never closes them. Whereas, if we go the route of a separate fence object specifically for user land then they can leak them like a sieve and we won't really care so much.
I am starting to agree gradually with this view. Given all the complications, referencing requests for exporting via fds feels quite heavy-weight, with potentially unbound dependencies and more trickiness in the future, even if we agreed on referencing and locking details.
Quoted 9 lines
Quoted 2 lines
Seqnos per context sounds like a significantly more light-weight and decoupled implementation.
I think this is the right long term direction as well; conceptually the per-context seqnos make the most sense in light of scheduling, and they let us keep things simple for sync pts as well. Only question is, who is signed up to make it all work?
Jesse
That's the version I had originally. A separate fence object using a per context per ring timeline that is safe to export to user land. However, Daniel Vetter was very strongly convinced that using a single shared fence object both internally and externally was the better solution.
My current implementation has a per context per ring timeline which is used to give the fence a definitely in order and sensible seqno. It is just not the same seqno that goes through the hardware. At least, not yet! Although that change could be quite significant.
John.
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx