xref: /linux/drivers/gpu/drm/i915/i915_scheduler.h (revision b0f84a84fff180718995b1269da2988e5b28be42)
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 #include <linux/list.h>
12 #include <linux/kernel.h>
13 
14 #include "i915_scheduler_types.h"
15 
16 #define priolist_for_each_request(it, plist, idx) \
17 	for (idx = 0; idx < ARRAY_SIZE((plist)->requests); idx++) \
18 		list_for_each_entry(it, &(plist)->requests[idx], sched.link)
19 
20 #define priolist_for_each_request_consume(it, n, plist, idx) \
21 	for (; \
22 	     (plist)->used ? (idx = __ffs((plist)->used)), 1 : 0; \
23 	     (plist)->used &= ~BIT(idx)) \
24 		list_for_each_entry_safe(it, n, \
25 					 &(plist)->requests[idx], \
26 					 sched.link)
27 
28 void i915_sched_node_init(struct i915_sched_node *node);
29 
30 bool __i915_sched_node_add_dependency(struct i915_sched_node *node,
31 				      struct i915_sched_node *signal,
32 				      struct i915_dependency *dep,
33 				      unsigned long flags);
34 
35 int i915_sched_node_add_dependency(struct i915_sched_node *node,
36 				   struct i915_sched_node *signal);
37 
38 void i915_sched_node_fini(struct i915_sched_node *node);
39 
40 void i915_schedule(struct i915_request *request,
41 		   const struct i915_sched_attr *attr);
42 
43 void i915_schedule_bump_priority(struct i915_request *rq, unsigned int bump);
44 
45 struct list_head *
46 i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio);
47 
48 void __i915_priolist_free(struct i915_priolist *p);
49 static inline void i915_priolist_free(struct i915_priolist *p)
50 {
51 	if (p->priority != I915_PRIORITY_NORMAL)
52 		__i915_priolist_free(p);
53 }
54 
55 static inline bool i915_scheduler_need_preempt(int prio, int active)
56 {
57 	/*
58 	 * Allow preemption of low -> normal -> high, but we do
59 	 * not allow low priority tasks to preempt other low priority
60 	 * tasks under the impression that latency for low priority
61 	 * tasks does not matter (as much as background throughput),
62 	 * so kiss.
63 	 *
64 	 * More naturally we would write
65 	 *	prio >= max(0, last);
66 	 * except that we wish to prevent triggering preemption at the same
67 	 * priority level: the task that is running should remain running
68 	 * to preserve FIFO ordering of dependencies.
69 	 */
70 	return prio > max(I915_PRIORITY_NORMAL - 1, active);
71 }
72 
73 #endif /* _I915_SCHEDULER_H_ */
74