drm/i915: timeout parameter for seqno wait
Subsystems (2)
PATCH v4 1/4 drm/i915: timeout parameter for seqno wait
Insert a wait parameter in the code so we can possibly timeout on a seqno wait if need be. The code should be functionally the same as before because all the callers will continue to retry if an arbitrary timeout elapses.
We'd like to have nanosecond granularity, but the only way to do this is with hrtimer, and that doesn't fit well with the needs of this code.
v2: Fix rebase error (Chris)
Return proper time even in wedged + signal case (Chris + Ben) Use timespec constructs (Ben)
Didn't take Daniel's advice regarding the Frankenstein-ness of the
function. I did try his advice, but in the end I liked the way the original code looked, better.
v3: Make wakeups far less frequent for infinite waits (Chris)
v4: Remove dummy_wait variable (Daniel)
Use raw monotonic time instead of jiffies (made the code a bit cleaner) (Ben) Added a couple of warnings (Ben)
--- drivers/gpu/drm/i915/i915_gem.c | 73 ++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +61 -12
@@ -1868,34 +1868,85 @@ i915_gem_check_olr(struct intel_ring_buffer *ring, u32 seqno)return ret; } +/** +* __wait_seqno - wait until execution of seqno has finished +* @ring: the ring expected to report seqno +* @seqno: duh! +* @interruptible: do an interruptible wait (normally yes) +* @timeout: in - how long to wait (NULL forever); out - how much time remaining +* +* Returns 0 if the seqno was found within the alloted time. Else returns the +* errno with remaining time filled in timeout argument. +*/ static int __wait_seqno (struct intel_ring_buffer *ring,u32 seqno, -bool interruptible) +bool interruptible,struct timespec *timeout) {drm_i915_private_t *dev_priv = ring->dev->dev_private; -int ret =0 ; +struct timespec before, now, wait_time={1 ,0 }; +unsigned long timeout_jiffies; +long end; +bool wait_forever = true;if (i915_seqno_passed (ring->get_seqno (ring), seqno))return 0 ;trace_i915_gem_request_wait_begin (ring, seqno); + +if (timeout !=NULL ) { + wait_time = *timeout; + wait_forever = false; + } + + timeout_jiffies =timespec_to_jiffies (&wait_time); +if (WARN_ON (!ring->irq_get (ring)))return -ENODEV ; +/* Record current jiffies in case interrupted by signal, or wedged * */ +getrawmonotonic (&before); +#define EXIT_COND \ (i915_seqno_passed(ring->get_seqno(ring), seqno) || \ atomic_read(&dev_priv->mm.wedged)) +do { +if (interruptible) + end =wait_event_interruptible_timeout (ring->irq_queue, +EXIT_COND , + timeout_jiffies); +else + end =wait_event_timeout (ring->irq_queue,EXIT_COND , + timeout_jiffies); -if (interruptible) - ret =wait_event_interruptible (ring->irq_queue, -EXIT_COND ); -else -wait_event (ring->irq_queue,EXIT_COND ); +if (atomic_read (&dev_priv->mm.wedged)) + end = -EAGAIN ; + }while (end ==0 && wait_forever); + +getrawmonotonic (&now); ring->irq_put (ring);trace_i915_gem_request_wait_end (ring, seqno);#undef EXIT_COND -return ret; +switch (end) { +case -EAGAIN :/* Wedged */ +case -ERESTARTSYS :/* Signal */ +if (!WARN_ON (timespec_compare (&now, &before) <=0 ) && timeout) { +struct timespec temp = *timeout; +struct timespec sleep_time =timespec_sub (now, before); + *timeout =timespec_sub (*timeout, sleep_time); +WARN_ON (timespec_compare (&temp, timeout) <0 ); + } +return (int )end; +case 0 :/* Timeout */ +if (timeout) +jiffies_to_timespec (end, timeout); +return -ETIME ; +default :/* Completed */ +WARN_ON (end <0 );/* We're not aware of other errors */ +if (timeout) +jiffies_to_timespec (end, timeout); +return 0 ; + } }/**
@@ -1919,9 +1970,7 @@ i915_wait_request(struct intel_ring_buffer *ring,if (ret)return ret; - ret =__wait_seqno (ring, seqno, dev_priv->mm.interruptible); -if (atomic_read (&dev_priv->mm.wedged)) - ret = -EAGAIN ; + ret =__wait_seqno (ring, seqno, dev_priv->mm.interruptible,NULL );return ret; }
@@ -2996,7 +3045,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)if (seqno ==0 )return 0 ; - ret =__wait_seqno (ring, seqno, true); + ret =__wait_seqno (ring, seqno, true,NULL );if (ret ==0 )queue_delayed_work (dev_priv->wq, &dev_priv->mm.retire_work,0 );
Signature · 1 line
1.7.10.1
PATCH v3 2/4 drm/i915: improve i915_wait_request_begin trace
The trace events adds whether or not the wait was blocking. Blocking in this case means to hold struct_mutex (ie. no new work can be submitted during the wait). The information is inherently racy.
The blocking information is racy since mutex_is_locked doesn't check that the current thread holds the lock. The only other option would be to pass the boolean information of whether or not the class was blocking down through the stack which is less desirable.
v2: Don't do a trace event per loop. (Chris)
Only get blocking/non-blocking info (Chris)
v3: updated comment in code as well as commit msg (Daniel) Add "(NB)" to trace information to remind us in 6 months (Ben)
--- drivers/gpu/drm/i915/i915_trace.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_trace.h +26 -2
@@ -311,9 +311,33 @@ DEFINE_EVENT(i915_gem_request, i915_gem_request_retire,TP_ARGS (ring, seqno) ); -DEFINE_EVENT (i915_gem_request, i915_gem_request_wait_begin, +TRACE_EVENT (i915_gem_request_wait_begin, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), -TP_ARGS (ring, seqno) +TP_ARGS (ring, seqno), + +TP_STRUCT__entry ( + __field(u32, dev) + __field(u32, ring) + __field(u32, seqno) +__field (bool, blocking) + ), + +/* NB: the blocking information is racy since mutex_is_locked +* doesn't check that the current thread holds the lock. The only +* other option would be to pass the boolean information of whether +* or not the class was blocking down through the stack which is +* less desirable. +*/ +TP_fast_assign ( + __entry->dev = ring->dev->primary->index; + __entry->ring = ring->id; + __entry->seqno = seqno; + __entry->blocking = mutex_is_locked(&ring->dev->struct_mutex); + ), + +TP_printk ("dev=%u, ring=%u, seqno=%u, blocking=%s" , + __entry->dev, __entry->ring, __entry->seqno, + __entry->blocking ?"yes (NB)" :"no" ) ); DEFINE_EVENT(i915_gem_request, i915_gem_request_wait_end,
Signature · 1 line
1.7.10.1
PATCH v6 3/4 drm/i915: wait render timeout ioctl
In reply to Ben WidawskyThis helps implement GL_ARB_sync but stops short of allowing full blown sync objects. Finally we can use the new timed seqno waiting function to allow userspace to wait on a buffer object with a timeout. This implements that interface.
The IOCTL will take as input a buffer object handle, and a timeout in nanoseconds (flags is currently optional but will likely be used for permutations of flush operations). Users may specify 0 nanoseconds to instantly check.
The wait ioctl with a timeout of 0 reimplements the busy ioctl. With any non-zero timeout parameter the wait ioctl will wait for the given number of nanoseconds on an object becoming unbusy. Since the wait itself does so holding struct_mutex the object may become re-busied before this completes. A similar but shorter race condition exists in the busy ioctl.
v2: ETIME/ERESTARTSYS instead of changing to EBUSY, and EGAIN (Chris) Flush the object from the gpu write domain (Chris + Daniel) Fix leaked refcount in good case (Chris)
Naturally align ioctl struct (Chris)
v3: Drop lock after getting seqno to avoid ugly dance (Chris)
v4: check for 0 timeout after olr check to allow polling (Chris)
v5: Updated the comment. (Chris)
v6: Return -ETIME instead of -EBUSY when timeout_ns is 0 (Daniel) Fix the commit message comment to be less ugly (Ben) Add a warning to check the return timespec (Ben)
--- drivers/gpu/drm/i915/i915_dma.c | 1 + drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/i915_gem.c | 86 +++++++++++++++++++++++++++++++++++++++ include/drm/i915_drm.h | 10 +++++ 4 files changed, 99 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +1 -0
@@ -1800,6 +1800,7 @@ struct drm_ioctl_desc i915_ioctls[] = {DRM_IOCTL_DEF_DRV (I915_OVERLAY_ATTRS , intel_overlay_attrs,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF_DRV (I915_SET_SPRITE_COLORKEY , intel_sprite_set_colorkey,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF_DRV (I915_GET_SPRITE_COLORKEY , intel_sprite_get_colorkey,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_UNLOCKED), };int i915_max_ioctl =DRM_ARRAY_SIZE (i915_ioctls);
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -1226,6 +1226,8 @@ int i915_gem_get_tiling(struct drm_device *dev, void *data, struct drm_file *file_priv);int i915_gem_get_aperture_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int i915_gem_wait_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv);void i915_gem_load (struct drm_device *dev);int i915_gem_init_object (struct drm_gem_object *obj); int __must_check i915_gem_flush_ring(struct intel_ring_buffer *ring,
drivers/gpu/drm/i915/i915_gem.c +86 -0
92 lines not on this page · raw message
include/drm/i915_drm.h +10 -0
@@ -200,6 +200,7 @@ typedef struct _drm_i915_sarea {#define DRM_I915_GEM_EXECBUFFER2 0x29#define DRM_I915_GET_SPRITE_COLORKEY 0x2a#define DRM_I915_SET_SPRITE_COLORKEY 0x2b +#define DRM_I915_GEM_WAIT 0x2c#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -243,6 +244,7 @@ typedef struct _drm_i915_sarea {#define DRM_IOCTL_I915_OVERLAY_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)#define DRM_IOCTL_I915_SET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey)#define DRM_IOCTL_I915_GET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey) +#define DRM_IOCTL_I915_GEM_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_WAIT, struct drm_i915_gem_wait)/* Allow drivers to submit batchbuffers directly to hardware, relying * on the security mechanisms provided by hardware.
@@ -886,4 +888,12 @@ struct drm_intel_sprite_colorkey { __u32 flags; }; +struct drm_i915_gem_wait { +/** Handle of BO we shall wait on */ +__u32 bo_handle; +__u32 flags; +/** Number of nanoseconds to wait, Returns time remaining. */ +__u64 timeout_ns; +}; +#endif /* _I915_DRM_H_ */
Signature · 1 line
1.7.10.1
Re: [PATCH 3/4 v6] drm/i915: wait render timeout ioctl
drivers/gpu/drm/i915/i915_dma.c struct drm_ioctl_desc i915_ioctls[] = { · line 1804
Quoted 6 lines · Ben Widawsky
drivers/gpu/drm/i915/i915_dma.c +1
-0@@ -1800,6 +1800,7 @@ struct drm_ioctl_desc i915_ioctls[] = {DRM_IOCTL_DEF_DRV (I915_OVERLAY_ATTRS , intel_overlay_attrs,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF_DRV (I915_SET_SPRITE_COLORKEY , intel_sprite_set_colorkey,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF_DRV (I915_GET_SPRITE_COLORKEY , intel_sprite_get_colorkey,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_UNLOCKED), };
I was just wondering (not directly related to this patch, but more thinking on the overall gem flow) - don't we want to use DRM_AUTH here?
Re: [PATCH 3/4 v6] drm/i915: wait render timeout ioctl
Quoted 10 lines · On Fri, 11 May 2012 20:09:19 -0300 Eugeni Dodonov…
drivers/gpu/drm/i915/i915_dma.c struct drm_ioctl_desc i915_ioctls[] = { · line 1804
Quoted 6 lines · Ben Widawsky
drivers/gpu/drm/i915/i915_dma.c +1
-0@@ -1800,6 +1800,7 @@ struct drm_ioctl_desc i915_ioctls[] = {DRM_IOCTL_DEF_DRV (I915_OVERLAY_ATTRS , intel_overlay_attrs,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF_DRV (I915_SET_SPRITE_COLORKEY , intel_sprite_set_colorkey,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF_DRV (I915_GET_SPRITE_COLORKEY , intel_sprite_get_colorkey,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_UNLOCKED), };I was just wondering (not directly related to this patch, but more thinking on the overall gem flow) - don't we want to use
DRM_AUTHhere?
I'd like to hear from others on this. I never really understand when to use DRM_AUTH, and when not to. Given that BUSY ioctl uses DRM_AUTH, you are probably right (and execbuffer too for that matter).
However from a security perspective, I don't really see why we need DRM_AUTH for this, or BUSY, and OTOH, set domain doesn't have DRM_AUTH, and the operation is quite similar, so I dunno.
At this point I think whatever is most consistent is the right answer.
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
PATCH 4/4 drm/i915: s/i915_wait_reqest/i915_wait_seqno/g
In reply to Ben WidawskyWait request is poorly named IMO. After working with these functions for some time, I feel it's much clearer to name the functions more appropriately.
Of course we must update the callers to use the new name as well.
This leaves room within our namespace for a *real* wait request function at some point.
Note to maintainer: this patch is optional.
--- drivers/gpu/drm/i915/i915_drv.h | 4 ++-- drivers/gpu/drm/i915/i915_gem.c | 9 ++++----- drivers/gpu/drm/i915/intel_overlay.c | 4 ++-- drivers/gpu/drm/i915/intel_ringbuffer.c | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -2
@@ -1312,8 +1312,8 @@ int __must_check i915_gem_idle(struct drm_device *dev);int __must_check i915_add_request (struct intel_ring_buffer *ring,struct drm_file *file,struct drm_i915_gem_request *request); -int __must_check i915_wait_request (struct intel_ring_buffer *ring, -uint32_t seqno); +int __must_check i915_wait_seqno (struct intel_ring_buffer *ring, +uint32_t seqno);int i915_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf); int __must_check i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
drivers/gpu/drm/i915/i915_gem.c +4 -5
@@ -1954,8 +1954,7 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,* request and object lists appropriately for that event. */ int -i915_wait_request (struct intel_ring_buffer *ring, -uint32_t seqno) +i915_wait_seqno (struct intel_ring_buffer *ring,uint32_t seqno) {drm_i915_private_t *dev_priv = ring->dev->dev_private;int ret =0 ;
@@ -1993,7 +1992,7 @@ i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj)* it. */ if (obj->active) { - ret =i915_wait_request (obj->ring, obj->last_rendering_seqno); + ret =i915_wait_seqno (obj->ring, obj->last_rendering_seqno);if (ret)return ret;i915_gem_retire_requests_ring (obj->ring);
@@ -2266,7 +2265,7 @@ static int i915_ring_idle(struct intel_ring_buffer *ring)return ret; } -return i915_wait_request (ring,i915_gem_next_request_seqno (ring)); +return i915_wait_seqno (ring,i915_gem_next_request_seqno (ring)); }int i915_gpu_idle (struct drm_device *dev)
@@ -2465,7 +2464,7 @@ i915_gem_object_flush_fence(struct drm_i915_gem_object *obj) }if (obj->last_fenced_seqno) { - ret =i915_wait_request (obj->ring, obj->last_fenced_seqno); + ret =i915_wait_seqno (obj->ring, obj->last_fenced_seqno);if (ret)return ret;
drivers/gpu/drm/i915/intel_overlay.c +2 -2
@@ -226,7 +226,7 @@ static int intel_overlay_do_wait_request(struct intel_overlay *overlay, } overlay->last_flip_req = request->seqno; overlay->flip_tail = tail; - ret =i915_wait_request (ring, overlay->last_flip_req); + ret =i915_wait_seqno (ring, overlay->last_flip_req);if (ret)return ret;i915_gem_retire_requests (dev);
@@ -452,7 +452,7 @@ static int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay)if (overlay->last_flip_req ==0 )return 0 ; - ret =i915_wait_request (ring, overlay->last_flip_req); + ret =i915_wait_seqno (ring, overlay->last_flip_req);if (ret)return ret;i915_gem_retire_requests (dev);
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
@@ -1085,7 +1085,7 @@ static int intel_ring_wait_seqno(struct intel_ring_buffer *ring, u32 seqno) was_interruptible = dev_priv->mm.interruptible; dev_priv->mm.interruptible = false; - ret =i915_wait_request (ring, seqno); + ret =i915_wait_seqno (ring, seqno); dev_priv->mm.interruptible = was_interruptible;if (!ret)
Signature · 1 line
1.7.10.1
Re: [PATCH 4/4] drm/i915: s/i915_wait_reqest/i915_wait_seqno/g
Quoted 4 lines · Ben Widawsky
Wait request is poorly named IMO. After working with these functions for some time, I feel it's much clearer to name the functions more appropriately.
Quoted 8 lines
Of course we must update the callers to use the new name as well.
This leaves room within our namespace for a *real* wait request function at some point.
Note to maintainer: this patch is optional.
Signed-off-by Ben Widawsky<[email protected]>
My only bikeshedding is to 's/wait_reqest/wait_request' in patch title :).
Eugeni
Re: [PATCH 4/4] drm/i915: s/i915_wait_reqest/i915_wait_seqno/g
Quoted 10 lines · On Fri, 11 May 2012 19:56:42 -0300 Eugeni Dodonov…
Quoted 9 lines · Ben Widawsky
Wait request is poorly named IMO. After working with these functions for some time, I feel it's much clearer to name the functions more appropriately.
Of course we must update the callers to use the new name as well.
This leaves room within our namespace for a *real* wait request function at some point.
Quoted 7 lines
Quoted 3 lines
Note to maintainer: this patch is optional.
Signed-off-by Ben Widawsky<[email protected]>My only bikeshedding is to 's/wait_reqest/wait_request' in patch title :).
Eugeni
Thanks. Fixed locally. Daniel, let me know if you want me to resubmit it when you're ready to merge.
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
PATCH 1/1 intel: add a timed wait function
In reply to Ben Widawskydrm_intel_gem_bo_wait(bo, &timeout in ns)
--- include/drm/i915_drm.h | 10 ++++++++++ intel/intel_bufmgr.h | 1 + intel/intel_bufmgr_gem.c | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+)
include/drm/i915_drm.h +10 -0
@@ -191,6 +191,7 @@ typedef struct _drm_i915_sarea {#define DRM_I915_GEM_EXECBUFFER2 0x29#define DRM_I915_GET_SPRITE_COLORKEY 0x2a#define DRM_I915_SET_SPRITE_COLORKEY 0x2b +#define DRM_I915_GEM_WAIT 0x2c#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -234,6 +235,7 @@ typedef struct _drm_i915_sarea {#define DRM_IOCTL_I915_OVERLAY_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)#define DRM_IOCTL_I915_SET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey)#define DRM_IOCTL_I915_GET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey) +#define DRM_IOCTL_I915_GEM_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_WAIT, struct drm_i915_gem_wait)/* Allow drivers to submit batchbuffers directly to hardware, relying * on the security mechanisms provided by hardware.
@@ -876,4 +878,12 @@ struct drm_intel_sprite_colorkey { __u32 flags; }; +struct drm_i915_gem_wait { +/** Handle of BO we shall wait on */ +__u32 bo_handle; +__u32 flags; +/** Number of nanoseconds to wait, Returns time remaining. */ +__u64 timeout_ns; +}; +#endif /* _I915_DRM_H_ */
intel/intel_bufmgr.h +1 -0
@@ -184,6 +184,7 @@ int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);int drm_intel_get_aperture_sizes (int fd,size_t *mappable,size_t *total);int drm_intel_bufmgr_gem_get_devid (drm_intel_bufmgr *bufmgr); +int drm_intel_gem_bo_wait (drm_intel_bo *bo,uint64_t *timeout_ns);/* drm_intel_bufmgr_fake.c */ drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
intel/intel_bufmgr_gem.c +26 -0
@@ -1478,6 +1478,32 @@ drm_intel_gem_bo_wait_rendering(drm_intel_bo *bo)drm_intel_gem_bo_start_gtt_access (bo,1 ); } +int drm_intel_gem_bo_wait (drm_intel_bo *bo,uint64_t *timeout_ns) +{ +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +struct drm_i915_gem_wait wait; +int ret; + +if (!timeout_ns) +return -EINVAL ; + + wait.bo_handle = bo_gem->gem_handle; + wait.timeout_ns = *timeout_ns; + wait.flags =0 ; + ret =drmIoctl (bufmgr_gem->fd,DRM_IOCTL_I915_GEM_WAIT , &wait); +if (ret) +return ret; + +if (wait.timeout_ns ==0 ) { +DBG ("Wait timed out on buffer %d\n" , bo_gem->gem_handle); + *timeout_ns =0 ; + }else + *timeout_ns = wait.timeout_ns; + +return ret; +} +/** * Sets the object to the GTT read and possibly write domain, used by the X * 2D driver in the absence of kernel support to do drm_intel_gem_bo_map_gtt().
Signature · 1 line
1.7.10.1
PATCH 1/1 tests/wait render timeout test
In reply to Ben WidawskyAssures that signals interrupting the wait works properly. Because of the scheduling around signals, interrupted waits will *seem* faster as the GPU continues to work while all the CPU scheduling stuff happens.
--- tests/Makefile.am | 3 + tests/gem_wait_render_timeout.c | 155 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 tests/gem_wait_render_timeout.c
tests/Makefile.am +3 -0
@@ -63,6 +63,7 @@ TESTS_progs = \ drm_vma_limiter_cached \ sysfs_rc6_residency \ flip_test \ + gem_wait_render_timeout \ $(NULL) # IMPORTANT: The ZZ_ tests need to be run last!
@@ -116,3 +117,5 @@ AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS) gem_fence_thrash_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) gem_fence_thrash_LDADD = $(LDADD) -lpthread + +gem_wait_render_timeout_LDADD = $(LDADD) -lrt
tests/gem_wait_render_timeout.c new file +155 -0
155 lines not on this page · raw message
Signature · 6 lines
1.7.10.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 15 lines · Ben Widawsky
Insert a wait parameter in the code so we can possibly timeout on a seqno wait if need be. The code should be functionally the same as before because all the callers will continue to retry if an arbitrary timeout elapses.
We'd like to have nanosecond granularity, but the only way to do this is with hrtimer, and that doesn't fit well with the needs of this code.
v2: Fix rebase error (Chris)
Return proper time even in wedged + signal case (Chris + Ben) Use timespec constructs (Ben)
Didn't take Daniel's advice regarding the Frankenstein-ness of the
function. I did try his advice, but in the end I liked the way the original code looked, better.
Quoted 7 lines
v3: Make wakeups far less frequent for infinite waits (Chris)
v4: Remove
dummy_waitvariable (Daniel)
Use raw monotonic time instead of jiffies (made the code a bit cleaner) (Ben) Added a couple of warnings (Ben)Signed-off-by Ben Widawsky<[email protected]>
I couldn't find much to bikeshed here except for question on patch 3 and one small typo on Patch 4. So for the series: