13a891a62SChris Wilson /*
23a891a62SChris Wilson  * SPDX-License-Identifier: MIT
33a891a62SChris Wilson  *
43a891a62SChris Wilson  * Copyright © 2018 Intel Corporation
53a891a62SChris Wilson  */
63a891a62SChris Wilson 
73a891a62SChris Wilson #ifndef _I915_SCHEDULER_TYPES_H_
83a891a62SChris Wilson #define _I915_SCHEDULER_TYPES_H_
93a891a62SChris Wilson 
103a891a62SChris Wilson #include <linux/list.h>
113a891a62SChris Wilson #include <linux/rbtree.h>
123a891a62SChris Wilson 
133a891a62SChris Wilson #include <uapi/drm/i915_drm.h>
143a891a62SChris Wilson 
153a891a62SChris Wilson struct drm_i915_private;
163a891a62SChris Wilson struct i915_request;
173a891a62SChris Wilson struct intel_engine_cs;
183a891a62SChris Wilson 
193a891a62SChris Wilson enum {
203a891a62SChris Wilson 	I915_PRIORITY_MIN = I915_CONTEXT_MIN_USER_PRIORITY - 1,
213a891a62SChris Wilson 	I915_PRIORITY_NORMAL = I915_CONTEXT_DEFAULT_PRIORITY,
223a891a62SChris Wilson 	I915_PRIORITY_MAX = I915_CONTEXT_MAX_USER_PRIORITY + 1,
233a891a62SChris Wilson 
243a891a62SChris Wilson 	I915_PRIORITY_INVALID = INT_MIN
253a891a62SChris Wilson };
263a891a62SChris Wilson 
273a891a62SChris Wilson #define I915_USER_PRIORITY_SHIFT 3
283a891a62SChris Wilson #define I915_USER_PRIORITY(x) ((x) << I915_USER_PRIORITY_SHIFT)
293a891a62SChris Wilson 
303a891a62SChris Wilson #define I915_PRIORITY_COUNT BIT(I915_USER_PRIORITY_SHIFT)
313a891a62SChris Wilson #define I915_PRIORITY_MASK (I915_PRIORITY_COUNT - 1)
323a891a62SChris Wilson 
333a891a62SChris Wilson #define I915_PRIORITY_WAIT		((u8)BIT(0))
343a891a62SChris Wilson #define I915_PRIORITY_NEWCLIENT		((u8)BIT(1))
353a891a62SChris Wilson #define I915_PRIORITY_NOSEMAPHORE	((u8)BIT(2))
363a891a62SChris Wilson 
373a891a62SChris Wilson #define __NO_PREEMPTION (I915_PRIORITY_WAIT)
383a891a62SChris Wilson 
393a891a62SChris Wilson struct i915_sched_attr {
403a891a62SChris Wilson 	/**
413a891a62SChris Wilson 	 * @priority: execution and service priority
423a891a62SChris Wilson 	 *
433a891a62SChris Wilson 	 * All clients are equal, but some are more equal than others!
443a891a62SChris Wilson 	 *
453a891a62SChris Wilson 	 * Requests from a context with a greater (more positive) value of
463a891a62SChris Wilson 	 * @priority will be executed before those with a lower @priority
473a891a62SChris Wilson 	 * value, forming a simple QoS.
483a891a62SChris Wilson 	 *
493a891a62SChris Wilson 	 * The &drm_i915_private.kernel_context is assigned the lowest priority.
503a891a62SChris Wilson 	 */
513a891a62SChris Wilson 	int priority;
523a891a62SChris Wilson };
533a891a62SChris Wilson 
543a891a62SChris Wilson /*
553a891a62SChris Wilson  * "People assume that time is a strict progression of cause to effect, but
563a891a62SChris Wilson  * actually, from a nonlinear, non-subjective viewpoint, it's more like a big
573a891a62SChris Wilson  * ball of wibbly-wobbly, timey-wimey ... stuff." -The Doctor, 2015
583a891a62SChris Wilson  *
593a891a62SChris Wilson  * Requests exist in a complex web of interdependencies. Each request
603a891a62SChris Wilson  * has to wait for some other request to complete before it is ready to be run
613a891a62SChris Wilson  * (e.g. we have to wait until the pixels have been rendering into a texture
623a891a62SChris Wilson  * before we can copy from it). We track the readiness of a request in terms
633a891a62SChris Wilson  * of fences, but we also need to keep the dependency tree for the lifetime
643a891a62SChris Wilson  * of the request (beyond the life of an individual fence). We use the tree
653a891a62SChris Wilson  * at various points to reorder the requests whilst keeping the requests
663a891a62SChris Wilson  * in order with respect to their various dependencies.
673a891a62SChris Wilson  *
683a891a62SChris Wilson  * There is no active component to the "scheduler". As we know the dependency
693a891a62SChris Wilson  * DAG of each request, we are able to insert it into a sorted queue when it
703a891a62SChris Wilson  * is ready, and are able to reorder its portion of the graph to accommodate
713a891a62SChris Wilson  * dynamic priority changes.
723a891a62SChris Wilson  */
733a891a62SChris Wilson struct i915_sched_node {
743a891a62SChris Wilson 	struct list_head signalers_list; /* those before us, we depend upon */
753a891a62SChris Wilson 	struct list_head waiters_list; /* those after us, they depend upon us */
763a891a62SChris Wilson 	struct list_head link;
773a891a62SChris Wilson 	struct i915_sched_attr attr;
783a891a62SChris Wilson 	unsigned int flags;
793a891a62SChris Wilson #define I915_SCHED_HAS_SEMAPHORE	BIT(0)
803a891a62SChris Wilson };
813a891a62SChris Wilson 
823a891a62SChris Wilson struct i915_dependency {
833a891a62SChris Wilson 	struct i915_sched_node *signaler;
843a891a62SChris Wilson 	struct list_head signal_link;
853a891a62SChris Wilson 	struct list_head wait_link;
863a891a62SChris Wilson 	struct list_head dfs_link;
873a891a62SChris Wilson 	unsigned long flags;
883a891a62SChris Wilson #define I915_DEPENDENCY_ALLOC BIT(0)
893a891a62SChris Wilson };
903a891a62SChris Wilson 
913a891a62SChris Wilson struct i915_priolist {
923a891a62SChris Wilson 	struct list_head requests[I915_PRIORITY_COUNT];
933a891a62SChris Wilson 	struct rb_node node;
943a891a62SChris Wilson 	unsigned long used;
953a891a62SChris Wilson 	int priority;
963a891a62SChris Wilson };
973a891a62SChris Wilson 
983a891a62SChris Wilson #endif /* _I915_SCHEDULER_TYPES_H_ */
99