diff options
author | Ben Widawsky <ben@bwidawsk.net> | 2012-05-24 18:03:10 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2012-05-25 08:15:46 -0400 |
commit | 23ba4fd0a42a46551041e379712e808ad496ba45 (patch) | |
tree | 53804484779f44977f60310ab8dec52c9289459e | |
parent | f3fd37683cc406ffaccf097de0433130c85c8651 (diff) |
drm/i915: wait render timeout ioctl
This 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)
v7: Use DRM_AUTH for the ioctl. (Eugeni)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r-- | drivers/gpu/drm/i915/i915_dma.c | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_drv.h | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem.c | 86 | ||||
-rw-r--r-- | include/drm/i915_drm.h | 10 |
4 files changed, 99 insertions, 0 deletions
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c index f94792626b94..262a74d1f852 100644 --- a/drivers/gpu/drm/i915/i915_dma.c +++ b/drivers/gpu/drm/i915/i915_dma.c | |||
@@ -1803,6 +1803,7 @@ struct drm_ioctl_desc i915_ioctls[] = { | |||
1803 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), | 1803 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
1804 | DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), | 1804 | DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
1805 | DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), | 1805 | DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
1806 | DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED), | ||
1806 | }; | 1807 | }; |
1807 | 1808 | ||
1808 | int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); | 1809 | int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); |
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 11c7a6a330c1..8ac10e8c0cdb 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h | |||
@@ -1229,6 +1229,8 @@ int i915_gem_get_tiling(struct drm_device *dev, void *data, | |||
1229 | struct drm_file *file_priv); | 1229 | struct drm_file *file_priv); |
1230 | int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data, | 1230 | int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data, |
1231 | struct drm_file *file_priv); | 1231 | struct drm_file *file_priv); |
1232 | int i915_gem_wait_ioctl(struct drm_device *dev, void *data, | ||
1233 | struct drm_file *file_priv); | ||
1232 | void i915_gem_load(struct drm_device *dev); | 1234 | void i915_gem_load(struct drm_device *dev); |
1233 | int i915_gem_init_object(struct drm_gem_object *obj); | 1235 | int i915_gem_init_object(struct drm_gem_object *obj); |
1234 | int __must_check i915_gem_flush_ring(struct intel_ring_buffer *ring, | 1236 | int __must_check i915_gem_flush_ring(struct intel_ring_buffer *ring, |
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index c8a5b04bc8d5..a0d740fac240 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c | |||
@@ -2001,6 +2001,92 @@ i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj) | |||
2001 | } | 2001 | } |
2002 | 2002 | ||
2003 | /** | 2003 | /** |
2004 | * i915_gem_wait_ioctl - implements DRM_IOCTL_I915_GEM_WAIT | ||
2005 | * @DRM_IOCTL_ARGS: standard ioctl arguments | ||
2006 | * | ||
2007 | * Returns 0 if successful, else an error is returned with the remaining time in | ||
2008 | * the timeout parameter. | ||
2009 | * -ETIME: object is still busy after timeout | ||
2010 | * -ERESTARTSYS: signal interrupted the wait | ||
2011 | * -ENONENT: object doesn't exist | ||
2012 | * Also possible, but rare: | ||
2013 | * -EAGAIN: GPU wedged | ||
2014 | * -ENOMEM: damn | ||
2015 | * -ENODEV: Internal IRQ fail | ||
2016 | * -E?: The add request failed | ||
2017 | * | ||
2018 | * The wait ioctl with a timeout of 0 reimplements the busy ioctl. With any | ||
2019 | * non-zero timeout parameter the wait ioctl will wait for the given number of | ||
2020 | * nanoseconds on an object becoming unbusy. Since the wait itself does so | ||
2021 | * without holding struct_mutex the object may become re-busied before this | ||
2022 | * function completes. A similar but shorter * race condition exists in the busy | ||
2023 | * ioctl | ||
2024 | */ | ||
2025 | int | ||
2026 | i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file) | ||
2027 | { | ||
2028 | struct drm_i915_gem_wait *args = data; | ||
2029 | struct drm_i915_gem_object *obj; | ||
2030 | struct intel_ring_buffer *ring = NULL; | ||
2031 | struct timespec timeout; | ||
2032 | u32 seqno = 0; | ||
2033 | int ret = 0; | ||
2034 | |||
2035 | timeout = ns_to_timespec(args->timeout_ns); | ||
2036 | |||
2037 | ret = i915_mutex_lock_interruptible(dev); | ||
2038 | if (ret) | ||
2039 | return ret; | ||
2040 | |||
2041 | obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->bo_handle)); | ||
2042 | if (&obj->base == NULL) { | ||
2043 | mutex_unlock(&dev->struct_mutex); | ||
2044 | return -ENOENT; | ||
2045 | } | ||
2046 | |||
2047 | /* Need to make sure the object is flushed first. This non-obvious | ||
2048 | * flush is required to enforce that (active && !olr) == no wait | ||
2049 | * necessary. | ||
2050 | */ | ||
2051 | ret = i915_gem_object_flush_gpu_write_domain(obj); | ||
2052 | if (ret) | ||
2053 | goto out; | ||
2054 | |||
2055 | if (obj->active) { | ||
2056 | seqno = obj->last_rendering_seqno; | ||
2057 | ring = obj->ring; | ||
2058 | } | ||
2059 | |||
2060 | if (seqno == 0) | ||
2061 | goto out; | ||
2062 | |||
2063 | ret = i915_gem_check_olr(ring, seqno); | ||
2064 | if (ret) | ||
2065 | goto out; | ||
2066 | |||
2067 | /* Do this after OLR check to make sure we make forward progress polling | ||
2068 | * on this IOCTL with a 0 timeout (like busy ioctl) | ||
2069 | */ | ||
2070 | if (!args->timeout_ns) { | ||
2071 | ret = -ETIME; | ||
2072 | goto out; | ||
2073 | } | ||
2074 | |||
2075 | drm_gem_object_unreference(&obj->base); | ||
2076 | mutex_unlock(&dev->struct_mutex); | ||
2077 | |||
2078 | ret = __wait_seqno(ring, seqno, true, &timeout); | ||
2079 | WARN_ON(!timespec_valid(&timeout)); | ||
2080 | args->timeout_ns = timespec_to_ns(&timeout); | ||
2081 | return ret; | ||
2082 | |||
2083 | out: | ||
2084 | drm_gem_object_unreference(&obj->base); | ||
2085 | mutex_unlock(&dev->struct_mutex); | ||
2086 | return ret; | ||
2087 | } | ||
2088 | |||
2089 | /** | ||
2004 | * i915_gem_object_sync - sync an object to a ring. | 2090 | * i915_gem_object_sync - sync an object to a ring. |
2005 | * | 2091 | * |
2006 | * @obj: object which may be in use on another ring. | 2092 | * @obj: object which may be in use on another ring. |
diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h index f3f82242bf1d..bab174334da5 100644 --- a/include/drm/i915_drm.h +++ b/include/drm/i915_drm.h | |||
@@ -200,6 +200,7 @@ typedef struct _drm_i915_sarea { | |||
200 | #define DRM_I915_GEM_EXECBUFFER2 0x29 | 200 | #define DRM_I915_GEM_EXECBUFFER2 0x29 |
201 | #define DRM_I915_GET_SPRITE_COLORKEY 0x2a | 201 | #define DRM_I915_GET_SPRITE_COLORKEY 0x2a |
202 | #define DRM_I915_SET_SPRITE_COLORKEY 0x2b | 202 | #define DRM_I915_SET_SPRITE_COLORKEY 0x2b |
203 | #define DRM_I915_GEM_WAIT 0x2c | ||
203 | 204 | ||
204 | #define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) | 205 | #define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) |
205 | #define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) | 206 | #define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) |
@@ -243,6 +244,7 @@ typedef struct _drm_i915_sarea { | |||
243 | #define DRM_IOCTL_I915_OVERLAY_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs) | 244 | #define DRM_IOCTL_I915_OVERLAY_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs) |
244 | #define DRM_IOCTL_I915_SET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey) | 245 | #define DRM_IOCTL_I915_SET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey) |
245 | #define DRM_IOCTL_I915_GET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey) | 246 | #define DRM_IOCTL_I915_GET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey) |
247 | #define DRM_IOCTL_I915_GEM_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_WAIT, struct drm_i915_gem_wait) | ||
246 | 248 | ||
247 | /* Allow drivers to submit batchbuffers directly to hardware, relying | 249 | /* Allow drivers to submit batchbuffers directly to hardware, relying |
248 | * on the security mechanisms provided by hardware. | 250 | * on the security mechanisms provided by hardware. |
@@ -886,4 +888,12 @@ struct drm_intel_sprite_colorkey { | |||
886 | __u32 flags; | 888 | __u32 flags; |
887 | }; | 889 | }; |
888 | 890 | ||
891 | struct drm_i915_gem_wait { | ||
892 | /** Handle of BO we shall wait on */ | ||
893 | __u32 bo_handle; | ||
894 | __u32 flags; | ||
895 | /** Number of nanoseconds to wait, Returns time remaining. */ | ||
896 | __u64 timeout_ns; | ||
897 | }; | ||
898 | |||
889 | #endif /* _I915_DRM_H_ */ | 899 | #endif /* _I915_DRM_H_ */ |