1 /*
2 * Copyright © 2017 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <errno.h>
25 #include <string.h>
26 #include <sys/ioctl.h>
27
28 #include "igt_core.h"
29 #include "ioctl_wrappers.h"
30
31 #include "i915/gem_scheduler.h"
32
33 #define LOCAL_I915_PARAM_HAS_SCHEDULER 41
34
35 /**
36 * SECTION:gem_scheduler
37 * @short_description: Helpers for querying scheduler capabilities
38 * @title: GEM Scheduler
39 *
40 * This helper library contains functions used for getting information on
41 * currently used scheduling model.
42 */
43
44 /**
45 * gem_scheduler_capability:
46 * @fd: open i915 drm file descriptor
47 *
48 * Returns: Scheduler capability bitmap.
49 */
gem_scheduler_capability(int fd)50 unsigned gem_scheduler_capability(int fd)
51 {
52 static int caps = -1;
53
54 if (caps < 0) {
55 struct drm_i915_getparam gp;
56
57 memset(&gp, 0, sizeof(gp));
58 gp.param = LOCAL_I915_PARAM_HAS_SCHEDULER;
59 gp.value = ∩︀
60
61 caps = 0;
62 ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
63 errno = 0;
64 }
65
66 return caps;
67 }
68
69 /**
70 * gem_scheduler_enabled:
71 * @fd: open i915 drm file descriptor
72 *
73 * Feature test macro to query whether the driver has scheduling capability.
74 */
gem_scheduler_enabled(int fd)75 bool gem_scheduler_enabled(int fd)
76 {
77 return gem_scheduler_capability(fd) &
78 I915_SCHEDULER_CAP_ENABLED;
79 }
80
81 /**
82 * gem_scheduler_has_ctx_priority:
83 * @fd: open i915 drm file descriptor
84 *
85 * Feature test macro to query whether the driver supports assigning custom
86 * priorities to contexts from userspace.
87 */
gem_scheduler_has_ctx_priority(int fd)88 bool gem_scheduler_has_ctx_priority(int fd)
89 {
90 return gem_scheduler_capability(fd) &
91 I915_SCHEDULER_CAP_PRIORITY;
92 }
93
94 /**
95 * gem_scheduler_has_preemption:
96 * @fd: open i915 drm file descriptor
97 *
98 * Feature test macro to query whether the driver supports preempting active
99 * (currently executing on HW) workloads.
100 */
gem_scheduler_has_preemption(int fd)101 bool gem_scheduler_has_preemption(int fd)
102 {
103 return gem_scheduler_capability(fd) &
104 I915_SCHEDULER_CAP_PREEMPTION;
105 }
106
107 /**
108 * gem_scheduler_has_semaphores:
109 * @fd: open i915 drm file descriptor
110 *
111 * Feature test macro to query whether the driver supports using HW semaphores
112 * to schedule dependencies in parallel (using the HW to delay execution until
113 * ready to reduce latency).
114 */
gem_scheduler_has_semaphores(int fd)115 bool gem_scheduler_has_semaphores(int fd)
116 {
117 return gem_scheduler_capability(fd) &
118 I915_SCHEDULER_CAP_SEMAPHORES;
119 }
120
121 /**
122 * gem_scheduler_print_capability:
123 * @fd: open i915 drm file descriptor
124 *
125 * Helper for pretty-printing scheduler capability.
126 */
gem_scheduler_print_capability(int fd)127 void gem_scheduler_print_capability(int fd)
128 {
129 unsigned caps = gem_scheduler_capability(fd);
130
131 if (!caps)
132 return;
133
134 igt_info("Has kernel scheduler\n");
135 if (caps & I915_SCHEDULER_CAP_PRIORITY)
136 igt_info(" - With priority sorting\n");
137 if (caps & I915_SCHEDULER_CAP_PREEMPTION)
138 igt_info(" - With preemption enabled\n");
139 if (caps & I915_SCHEDULER_CAP_SEMAPHORES)
140 igt_info(" - With HW semaphores enabled\n");
141 }
142