xref: /linux/drivers/gpu/drm/i915/i915_scheduler.h (revision 7651a4452ddf8ace48defd473ead6effe35059c7)
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2018 Intel Corporation
5  */
6 
7 #ifndef _I915_SCHEDULER_H_
8 #define _I915_SCHEDULER_H_
9 
10 #include <linux/bitops.h>
11 
12 #include <uapi/drm/i915_drm.h>
13 
14 enum {
15 	I915_PRIORITY_MIN = I915_CONTEXT_MIN_USER_PRIORITY - 1,
16 	I915_PRIORITY_NORMAL = I915_CONTEXT_DEFAULT_PRIORITY,
17 	I915_PRIORITY_MAX = I915_CONTEXT_MAX_USER_PRIORITY + 1,
18 
19 	I915_PRIORITY_INVALID = INT_MIN
20 };
21 
22 #define I915_USER_PRIORITY_SHIFT 0
23 #define I915_USER_PRIORITY(x) ((x) << I915_USER_PRIORITY_SHIFT)
24 
25 #define I915_PRIORITY_COUNT BIT(I915_USER_PRIORITY_SHIFT)
26 #define I915_PRIORITY_MASK (I915_PRIORITY_COUNT - 1)
27 
28 struct i915_sched_attr {
29 	/**
30 	 * @priority: execution and service priority
31 	 *
32 	 * All clients are equal, but some are more equal than others!
33 	 *
34 	 * Requests from a context with a greater (more positive) value of
35 	 * @priority will be executed before those with a lower @priority
36 	 * value, forming a simple QoS.
37 	 *
38 	 * The &drm_i915_private.kernel_context is assigned the lowest priority.
39 	 */
40 	int priority;
41 };
42 
43 /*
44  * "People assume that time is a strict progression of cause to effect, but
45  * actually, from a nonlinear, non-subjective viewpoint, it's more like a big
46  * ball of wibbly-wobbly, timey-wimey ... stuff." -The Doctor, 2015
47  *
48  * Requests exist in a complex web of interdependencies. Each request
49  * has to wait for some other request to complete before it is ready to be run
50  * (e.g. we have to wait until the pixels have been rendering into a texture
51  * before we can copy from it). We track the readiness of a request in terms
52  * of fences, but we also need to keep the dependency tree for the lifetime
53  * of the request (beyond the life of an individual fence). We use the tree
54  * at various points to reorder the requests whilst keeping the requests
55  * in order with respect to their various dependencies.
56  *
57  * There is no active component to the "scheduler". As we know the dependency
58  * DAG of each request, we are able to insert it into a sorted queue when it
59  * is ready, and are able to reorder its portion of the graph to accommodate
60  * dynamic priority changes.
61  */
62 struct i915_sched_node {
63 	struct list_head signalers_list; /* those before us, we depend upon */
64 	struct list_head waiters_list; /* those after us, they depend upon us */
65 	struct list_head link;
66 	struct i915_sched_attr attr;
67 };
68 
69 struct i915_dependency {
70 	struct i915_sched_node *signaler;
71 	struct list_head signal_link;
72 	struct list_head wait_link;
73 	struct list_head dfs_link;
74 	unsigned long flags;
75 #define I915_DEPENDENCY_ALLOC BIT(0)
76 };
77 
78 #endif /* _I915_SCHEDULER_H_ */
79