Lines Matching +full:1 +full:- +full:cpu
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Global CPU deadline management
12 return (i - 1) >> 1; in parent()
17 return (i << 1) + 1; in left_child()
22 return (i << 1) + 2; in right_child()
29 int orig_cpu = cp->elements[idx].cpu; in cpudl_heapify_down()
30 u64 orig_dl = cp->elements[idx].dl; in cpudl_heapify_down()
32 if (left_child(idx) >= cp->size) in cpudl_heapify_down()
36 while (1) { in cpudl_heapify_down()
44 if ((l < cp->size) && dl_time_before(orig_dl, in cpudl_heapify_down()
45 cp->elements[l].dl)) { in cpudl_heapify_down()
47 largest_dl = cp->elements[l].dl; in cpudl_heapify_down()
49 if ((r < cp->size) && dl_time_before(largest_dl, in cpudl_heapify_down()
50 cp->elements[r].dl)) in cpudl_heapify_down()
57 cp->elements[idx].cpu = cp->elements[largest].cpu; in cpudl_heapify_down()
58 cp->elements[idx].dl = cp->elements[largest].dl; in cpudl_heapify_down()
59 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_down()
63 cp->elements[idx].cpu = orig_cpu; in cpudl_heapify_down()
64 cp->elements[idx].dl = orig_dl; in cpudl_heapify_down()
65 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_down()
72 int orig_cpu = cp->elements[idx].cpu; in cpudl_heapify_up()
73 u64 orig_dl = cp->elements[idx].dl; in cpudl_heapify_up()
80 if (dl_time_before(orig_dl, cp->elements[p].dl)) in cpudl_heapify_up()
83 cp->elements[idx].cpu = cp->elements[p].cpu; in cpudl_heapify_up()
84 cp->elements[idx].dl = cp->elements[p].dl; in cpudl_heapify_up()
85 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_up()
89 cp->elements[idx].cpu = orig_cpu; in cpudl_heapify_up()
90 cp->elements[idx].dl = orig_dl; in cpudl_heapify_up()
91 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_up()
96 if (idx > 0 && dl_time_before(cp->elements[parent(idx)].dl, in cpudl_heapify()
97 cp->elements[idx].dl)) in cpudl_heapify()
105 return cp->elements[0].cpu; in cpudl_maximum()
109 * cpudl_find - find the best (later-dl) CPU in the system
110 * @cp: the cpudl max-heap context
114 * Returns: int - CPUs were found
119 const struct sched_dl_entity *dl_se = &p->dl; in cpudl_find()
122 cpumask_and(later_mask, cp->free_cpus, &p->cpus_mask)) { in cpudl_find()
124 int cpu, max_cpu = -1; in cpudl_find() local
127 return 1; in cpudl_find()
130 for_each_cpu(cpu, later_mask) { in cpudl_find()
131 if (!dl_task_fits_capacity(p, cpu)) { in cpudl_find()
132 cpumask_clear_cpu(cpu, later_mask); in cpudl_find()
134 cap = arch_scale_cpu_capacity(cpu); in cpudl_find()
137 (cpu == task_cpu(p) && cap == max_cap)) { in cpudl_find()
139 max_cpu = cpu; in cpudl_find()
147 return 1; in cpudl_find()
151 WARN_ON(best_cpu != -1 && !cpu_present(best_cpu)); in cpudl_find()
153 if (cpumask_test_cpu(best_cpu, &p->cpus_mask) && in cpudl_find()
154 dl_time_before(dl_se->deadline, cp->elements[0].dl)) { in cpudl_find()
158 return 1; in cpudl_find()
165 * cpudl_clear - remove a CPU from the cpudl max-heap
166 * @cp: the cpudl max-heap context
167 * @cpu: the target CPU
169 * Notes: assumes cpu_rq(cpu)->lock is locked
173 void cpudl_clear(struct cpudl *cp, int cpu) in cpudl_clear() argument
178 WARN_ON(!cpu_present(cpu)); in cpudl_clear()
180 raw_spin_lock_irqsave(&cp->lock, flags); in cpudl_clear()
182 old_idx = cp->elements[cpu].idx; in cpudl_clear()
187 * called for a CPU without -dl tasks running. in cpudl_clear()
190 new_cpu = cp->elements[cp->size - 1].cpu; in cpudl_clear()
191 cp->elements[old_idx].dl = cp->elements[cp->size - 1].dl; in cpudl_clear()
192 cp->elements[old_idx].cpu = new_cpu; in cpudl_clear()
193 cp->size--; in cpudl_clear()
194 cp->elements[new_cpu].idx = old_idx; in cpudl_clear()
195 cp->elements[cpu].idx = IDX_INVALID; in cpudl_clear()
198 cpumask_set_cpu(cpu, cp->free_cpus); in cpudl_clear()
200 raw_spin_unlock_irqrestore(&cp->lock, flags); in cpudl_clear()
204 * cpudl_set - update the cpudl max-heap
205 * @cp: the cpudl max-heap context
206 * @cpu: the target CPU
207 * @dl: the new earliest deadline for this CPU
209 * Notes: assumes cpu_rq(cpu)->lock is locked
213 void cpudl_set(struct cpudl *cp, int cpu, u64 dl) in cpudl_set() argument
218 WARN_ON(!cpu_present(cpu)); in cpudl_set()
220 raw_spin_lock_irqsave(&cp->lock, flags); in cpudl_set()
222 old_idx = cp->elements[cpu].idx; in cpudl_set()
224 int new_idx = cp->size++; in cpudl_set()
226 cp->elements[new_idx].dl = dl; in cpudl_set()
227 cp->elements[new_idx].cpu = cpu; in cpudl_set()
228 cp->elements[cpu].idx = new_idx; in cpudl_set()
230 cpumask_clear_cpu(cpu, cp->free_cpus); in cpudl_set()
232 cp->elements[old_idx].dl = dl; in cpudl_set()
236 raw_spin_unlock_irqrestore(&cp->lock, flags); in cpudl_set()
240 * cpudl_set_freecpu - Set the cpudl.free_cpus
241 * @cp: the cpudl max-heap context
242 * @cpu: rd attached CPU
244 void cpudl_set_freecpu(struct cpudl *cp, int cpu) in cpudl_set_freecpu() argument
246 cpumask_set_cpu(cpu, cp->free_cpus); in cpudl_set_freecpu()
250 * cpudl_clear_freecpu - Clear the cpudl.free_cpus
251 * @cp: the cpudl max-heap context
252 * @cpu: rd attached CPU
254 void cpudl_clear_freecpu(struct cpudl *cp, int cpu) in cpudl_clear_freecpu() argument
256 cpumask_clear_cpu(cpu, cp->free_cpus); in cpudl_clear_freecpu()
260 * cpudl_init - initialize the cpudl structure
261 * @cp: the cpudl max-heap context
267 raw_spin_lock_init(&cp->lock); in cpudl_init()
268 cp->size = 0; in cpudl_init()
270 cp->elements = kcalloc(nr_cpu_ids, in cpudl_init()
273 if (!cp->elements) in cpudl_init()
274 return -ENOMEM; in cpudl_init()
276 if (!zalloc_cpumask_var(&cp->free_cpus, GFP_KERNEL)) { in cpudl_init()
277 kfree(cp->elements); in cpudl_init()
278 return -ENOMEM; in cpudl_init()
282 cp->elements[i].idx = IDX_INVALID; in cpudl_init()
288 * cpudl_cleanup - clean up the cpudl structure
289 * @cp: the cpudl max-heap context
293 free_cpumask_var(cp->free_cpus); in cpudl_cleanup()
294 kfree(cp->elements); in cpudl_cleanup()