2 * SPDX-License-Identifier: MIT
4 * Copyright © 2014-2016 Intel Corporation
7 #include <linux/jiffies.h>
9 #include <drm/drm_file.h>
12 #include "i915_gem_ioctls.h"
13 #include "i915_gem_object.h"
16 * 20ms is a fairly arbitrary limit (greater than the average frame time)
17 * chosen to prevent the CPU getting more than a frame ahead of the GPU
18 * (when using lax throttling for the frontbuffer). We also use it to
19 * offer free GPU waitboosts for severely congested workloads.
21 #define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20)
24 * Throttle our rendering by waiting until the ring has completed our requests
25 * emitted over 20 msec ago.
27 * Note that if we were to use the current jiffies each time around the loop,
28 * we wouldn't escape the function with any frames outstanding if the time to
29 * render a frame was over 20ms.
31 * This should get us reasonable parallelism between CPU and GPU but also
32 * relatively low latency when blocking on a particular request to finish.
35 i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
36 struct drm_file *file)
38 struct drm_i915_file_private *file_priv = file->driver_priv;
39 unsigned long recent_enough = jiffies - DRM_I915_THROTTLE_JIFFIES;
40 struct i915_request *request, *target = NULL;
43 /* ABI: return -EIO if already wedged */
44 ret = intel_gt_terminally_wedged(&to_i915(dev)->gt);
48 spin_lock(&file_priv->mm.lock);
49 list_for_each_entry(request, &file_priv->mm.request_list, client_link) {
50 if (time_after_eq(request->emitted_jiffies, recent_enough))
54 list_del(&target->client_link);
55 target->file_priv = NULL;
61 i915_request_get(target);
62 spin_unlock(&file_priv->mm.lock);
67 ret = i915_request_wait(target,
68 I915_WAIT_INTERRUPTIBLE,
69 MAX_SCHEDULE_TIMEOUT);
70 i915_request_put(target);
72 return ret < 0 ? ret : 0;