3 * (C) COPYRIGHT ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
21 * @file mali_kbase_js_policy_cfs.h
22 * Completely Fair Job Scheduler Policy structure definitions
25 #ifndef _KBASE_JS_POLICY_CFS_H_
26 #define _KBASE_JS_POLICY_CFS_H_
28 #define KBASE_JS_POLICY_AVAILABLE_CFS
30 /** @addtogroup base_api
32 /** @addtogroup base_kbase_api
34 /** @addtogroup kbase_js_policy
38 * Internally, this policy keeps a few internal queues for different variants
39 * of core requirements, which are used to decide how to schedule onto the
40 * different job slots.
42 * Must be a power of 2 to keep the lookup math simple
44 #define KBASEP_JS_MAX_NR_CORE_REQ_VARIANTS_LOG2 3
45 #define KBASEP_JS_MAX_NR_CORE_REQ_VARIANTS (1u << KBASEP_JS_MAX_NR_CORE_REQ_VARIANTS_LOG2)
47 /** Bits needed in the lookup to support all slots */
48 #define KBASEP_JS_VARIANT_LOOKUP_BITS_NEEDED (BASE_JM_MAX_NR_SLOTS * KBASEP_JS_MAX_NR_CORE_REQ_VARIANTS)
49 /** Number of u32s needed in the lookup array to support all slots */
50 #define KBASEP_JS_VARIANT_LOOKUP_WORDS_NEEDED ((KBASEP_JS_VARIANT_LOOKUP_BITS_NEEDED + 31) / 32)
52 #define KBASEP_JS_RUNTIME_EMPTY ((u64)-1)
54 typedef struct kbasep_js_policy_cfs {
55 /** List of all contexts in the context queue. Hold
56 * kbasep_js_device_data::queue_mutex whilst accessing. */
57 struct list_head ctx_queue_head;
59 /** List of all contexts in the realtime (priority) context queue */
60 struct list_head ctx_rt_queue_head;
62 /** List of scheduled contexts. Hold kbasep_jd_device_data::runpool_irq::lock
63 * whilst accessing, which is a spinlock */
64 struct list_head scheduled_ctxs_head;
66 /** Number of valid elements in the core_req_variants member, and the
67 * kbasep_js_policy_rr_ctx::job_list_head array */
68 u32 num_core_req_variants;
70 /** Variants of the core requirements */
71 kbasep_atom_req core_req_variants[KBASEP_JS_MAX_NR_CORE_REQ_VARIANTS];
73 /* Lookups per job slot against which core_req_variants match it */
74 u32 slot_to_variant_lookup_ss_state[KBASEP_JS_VARIANT_LOOKUP_WORDS_NEEDED];
75 u32 slot_to_variant_lookup_ss_allcore_state[KBASEP_JS_VARIANT_LOOKUP_WORDS_NEEDED];
77 /* The timer tick used for rescheduling jobs */
78 struct hrtimer scheduling_timer;
80 /* Is the timer running?
82 * The kbasep_js_device_data::runpool_mutex must be held whilst modifying this. */
83 mali_bool timer_running;
85 /* Number of us the least-run context has been running for
87 * The kbasep_js_device_data::queue_mutex must be held whilst updating this
88 * Reads are possible without this mutex, but an older value might be read
89 * if no memory barriers are issued beforehand. */
92 /* Number of us the least-run context in the context queue has been running for.
93 * -1 if context queue is empty. */
94 atomic64_t least_runtime_us;
96 /* Number of us the least-run context in the realtime (priority) context queue
97 * has been running for. -1 if realtime context queue is empty. */
98 atomic64_t rt_least_runtime_us;
99 } kbasep_js_policy_cfs;
102 * This policy contains a single linked list of all contexts.
104 typedef struct kbasep_js_policy_cfs_ctx {
105 /** Link implementing the Policy's Queue, and Currently Scheduled list */
106 struct list_head list;
108 /** Job lists for use when in the Run Pool - only using
109 * kbasep_js_policy_fcfs::num_unique_slots of them. We still need to track
110 * the jobs when we're not in the runpool, so this member is accessed from
111 * outside the policy queue (for the first job), inside the policy queue,
112 * and inside the runpool.
114 * If the context is in the runpool, then this must only be accessed with
115 * kbasep_js_device_data::runpool_irq::lock held
117 * Jobs are still added to this list even when the context is not in the
118 * runpool. In that case, the kbasep_js_kctx_info::ctx::jsctx_mutex must be
119 * held before accessing this. */
120 struct list_head job_list_head[KBASEP_JS_MAX_NR_CORE_REQ_VARIANTS];
122 /** Number of us this context has been running for
124 * The kbasep_js_device_data::runpool_irq::lock (a spinlock) must be held
125 * whilst updating this. Initializing will occur on context init and
126 * context enqueue (which can only occur in one thread at a time), but
127 * multi-thread access only occurs while the context is in the runpool.
129 * Reads are possible without this spinlock, but an older value might be read
130 * if no memory barriers are issued beforehand */
133 /* Calling process policy scheme is a realtime scheduler and will use the priority queue
134 * Non-mutable after ctx init */
135 mali_bool process_rt_policy;
136 /* Calling process NICE priority */
137 int process_priority;
138 /* Average NICE priority of all atoms in bag:
139 * Hold the kbasep_js_kctx_info::ctx::jsctx_mutex when accessing */
141 /* Total NICE priority of all atoms in bag
142 * Hold the kbasep_js_kctx_info::ctx::jsctx_mutex when accessing */
143 int bag_total_priority;
144 /* Total number of atoms in the bag
145 * Hold the kbasep_js_kctx_info::ctx::jsctx_mutex when accessing */
146 int bag_total_nr_atoms;
148 } kbasep_js_policy_cfs_ctx;
151 * In this policy, each Job is part of at most one of the per_corereq lists
153 typedef struct kbasep_js_policy_cfs_job {
154 struct list_head list; /**< Link implementing the Run Pool list/Jobs owned by the ctx */
155 u32 cached_variant_idx; /**< Cached index of the list this should be entered into on re-queue */
157 /** Number of ticks that this job has been executing for
159 * To access this, the kbasep_js_device_data::runpool_irq::lock must be held */
161 } kbasep_js_policy_cfs_job;
163 /** @} *//* end group kbase_js_policy */
164 /** @} *//* end group base_kbase_api */
165 /** @} *//* end group base_api */