2 * SPDX-License-Identifier: MIT
4 * Copyright © 2018 Intel Corporation
7 #ifndef _I915_SCHEDULER_H_
8 #define _I915_SCHEDULER_H_
10 #include <linux/bitops.h>
11 #include <linux/kernel.h>
13 #include <uapi/drm/i915_drm.h>
15 struct drm_i915_private;
17 struct intel_engine_cs;
20 I915_PRIORITY_MIN = I915_CONTEXT_MIN_USER_PRIORITY - 1,
21 I915_PRIORITY_NORMAL = I915_CONTEXT_DEFAULT_PRIORITY,
22 I915_PRIORITY_MAX = I915_CONTEXT_MAX_USER_PRIORITY + 1,
24 I915_PRIORITY_INVALID = INT_MIN
27 #define I915_USER_PRIORITY_SHIFT 2
28 #define I915_USER_PRIORITY(x) ((x) << I915_USER_PRIORITY_SHIFT)
30 #define I915_PRIORITY_COUNT BIT(I915_USER_PRIORITY_SHIFT)
31 #define I915_PRIORITY_MASK (I915_PRIORITY_COUNT - 1)
33 #define I915_PRIORITY_WAIT ((u8)BIT(0))
34 #define I915_PRIORITY_NEWCLIENT ((u8)BIT(1))
36 struct i915_sched_attr {
38 * @priority: execution and service priority
40 * All clients are equal, but some are more equal than others!
42 * Requests from a context with a greater (more positive) value of
43 * @priority will be executed before those with a lower @priority
44 * value, forming a simple QoS.
46 * The &drm_i915_private.kernel_context is assigned the lowest priority.
52 * "People assume that time is a strict progression of cause to effect, but
53 * actually, from a nonlinear, non-subjective viewpoint, it's more like a big
54 * ball of wibbly-wobbly, timey-wimey ... stuff." -The Doctor, 2015
56 * Requests exist in a complex web of interdependencies. Each request
57 * has to wait for some other request to complete before it is ready to be run
58 * (e.g. we have to wait until the pixels have been rendering into a texture
59 * before we can copy from it). We track the readiness of a request in terms
60 * of fences, but we also need to keep the dependency tree for the lifetime
61 * of the request (beyond the life of an individual fence). We use the tree
62 * at various points to reorder the requests whilst keeping the requests
63 * in order with respect to their various dependencies.
65 * There is no active component to the "scheduler". As we know the dependency
66 * DAG of each request, we are able to insert it into a sorted queue when it
67 * is ready, and are able to reorder its portion of the graph to accommodate
68 * dynamic priority changes.
70 struct i915_sched_node {
71 struct list_head signalers_list; /* those before us, we depend upon */
72 struct list_head waiters_list; /* those after us, they depend upon us */
73 struct list_head link;
74 struct i915_sched_attr attr;
77 struct i915_dependency {
78 struct i915_sched_node *signaler;
79 struct list_head signal_link;
80 struct list_head wait_link;
81 struct list_head dfs_link;
83 #define I915_DEPENDENCY_ALLOC BIT(0)
86 void i915_sched_node_init(struct i915_sched_node *node);
88 bool __i915_sched_node_add_dependency(struct i915_sched_node *node,
89 struct i915_sched_node *signal,
90 struct i915_dependency *dep,
93 int i915_sched_node_add_dependency(struct drm_i915_private *i915,
94 struct i915_sched_node *node,
95 struct i915_sched_node *signal);
97 void i915_sched_node_fini(struct drm_i915_private *i915,
98 struct i915_sched_node *node);
100 void i915_schedule(struct i915_request *request,
101 const struct i915_sched_attr *attr);
103 void i915_schedule_bump_priority(struct i915_request *rq, unsigned int bump);
106 i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio);
108 #endif /* _I915_SCHEDULER_H_ */