]> Pileus Git - ~andy/linux/blobdiff - drivers/gpu/drm/i915/i915_gem.c
drm/i915: Inifite timeout for wait ioctl
[~andy/linux] / drivers / gpu / drm / i915 / i915_gem.c
index a20ac438b8ef3945b791e82bebc32b6013dc59eb..deaa0d4bb456e582c01a205cc9a76f5542f7a3cb 100644 (file)
@@ -2029,6 +2029,31 @@ i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj)
        return 0;
 }
 
+/**
+ * Ensures that an object will eventually get non-busy by flushing any required
+ * write domains, emitting any outstanding lazy request and retiring and
+ * completed requests.
+ */
+static int
+i915_gem_object_flush_active(struct drm_i915_gem_object *obj)
+{
+       int ret;
+
+       if (obj->active) {
+               ret = i915_gem_object_flush_gpu_write_domain(obj);
+               if (ret)
+                       return ret;
+
+               ret = i915_gem_check_olr(obj->ring,
+                                        obj->last_rendering_seqno);
+               if (ret)
+                       return ret;
+               i915_gem_retire_requests_ring(obj->ring);
+       }
+
+       return 0;
+}
+
 /**
  * i915_gem_wait_ioctl - implements DRM_IOCTL_I915_GEM_WAIT
  * @DRM_IOCTL_ARGS: standard ioctl arguments
@@ -2057,11 +2082,14 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
        struct drm_i915_gem_wait *args = data;
        struct drm_i915_gem_object *obj;
        struct intel_ring_buffer *ring = NULL;
-       struct timespec timeout;
+       struct timespec timeout_stack, *timeout = NULL;
        u32 seqno = 0;
        int ret = 0;
 
-       timeout = ns_to_timespec(args->timeout_ns);
+       if (args->timeout_ns >= 0) {
+               timeout_stack = ns_to_timespec(args->timeout_ns);
+               timeout = &timeout_stack;
+       }
 
        ret = i915_mutex_lock_interruptible(dev);
        if (ret)
@@ -2073,11 +2101,8 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
                return -ENOENT;
        }
 
-       /* Need to make sure the object is flushed first. This non-obvious
-        * flush is required to enforce that (active && !olr) == no wait
-        * necessary.
-        */
-       ret = i915_gem_object_flush_gpu_write_domain(obj);
+       /* Need to make sure the object gets inactive eventually. */
+       ret = i915_gem_object_flush_active(obj);
        if (ret)
                goto out;
 
@@ -2089,10 +2114,6 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
        if (seqno == 0)
                 goto out;
 
-       ret = i915_gem_check_olr(ring, seqno);
-       if (ret)
-               goto out;
-
        /* Do this after OLR check to make sure we make forward progress polling
         * on this IOCTL with a 0 timeout (like busy ioctl)
         */
@@ -2104,9 +2125,11 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
        drm_gem_object_unreference(&obj->base);
        mutex_unlock(&dev->struct_mutex);
 
-       ret = __wait_seqno(ring, seqno, true, &timeout);
-       WARN_ON(!timespec_valid(&timeout));
-       args->timeout_ns = timespec_to_ns(&timeout);
+       ret = __wait_seqno(ring, seqno, true, timeout);
+       if (timeout) {
+               WARN_ON(!timespec_valid(timeout));
+               args->timeout_ns = timespec_to_ns(timeout);
+       }
        return ret;
 
 out:
@@ -3330,30 +3353,9 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
         * become non-busy without any further actions, therefore emit any
         * necessary flushes here.
         */
-       args->busy = obj->active;
-       if (args->busy) {
-               /* Unconditionally flush objects, even when the gpu still uses this
-                * object. Userspace calling this function indicates that it wants to
-                * use this buffer rather sooner than later, so issuing the required
-                * flush earlier is beneficial.
-                */
-               if (obj->base.write_domain & I915_GEM_GPU_DOMAINS) {
-                       ret = i915_gem_flush_ring(obj->ring,
-                                                 0, obj->base.write_domain);
-               } else {
-                       ret = i915_gem_check_olr(obj->ring,
-                                                obj->last_rendering_seqno);
-               }
+       ret = i915_gem_object_flush_active(obj);
 
-               /* Update the active list for the hardware's current position.
-                * Otherwise this only updates on a delayed timer or when irqs
-                * are actually unmasked, and our working set ends up being
-                * larger than required.
-                */
-               i915_gem_retire_requests_ring(obj->ring);
-
-               args->busy = obj->active;
-       }
+       args->busy = obj->active;
 
        drm_gem_object_unreference(&obj->base);
 unlock: