Lines Matching full:cp
26 static void cpudl_heapify_down(struct cpudl *cp, int idx) in cpudl_heapify_down() argument
30 int orig_cpu = cp->elements[idx].cpu; in cpudl_heapify_down()
31 u64 orig_dl = cp->elements[idx].dl; in cpudl_heapify_down()
33 if (left_child(idx) >= cp->size) in cpudl_heapify_down()
45 if ((l < cp->size) && dl_time_before(orig_dl, in cpudl_heapify_down()
46 cp->elements[l].dl)) { in cpudl_heapify_down()
48 largest_dl = cp->elements[l].dl; in cpudl_heapify_down()
50 if ((r < cp->size) && dl_time_before(largest_dl, in cpudl_heapify_down()
51 cp->elements[r].dl)) in cpudl_heapify_down()
58 cp->elements[idx].cpu = cp->elements[largest].cpu; in cpudl_heapify_down()
59 cp->elements[idx].dl = cp->elements[largest].dl; in cpudl_heapify_down()
60 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_down()
64 cp->elements[idx].cpu = orig_cpu; in cpudl_heapify_down()
65 cp->elements[idx].dl = orig_dl; in cpudl_heapify_down()
66 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_down()
69 static void cpudl_heapify_up(struct cpudl *cp, int idx) in cpudl_heapify_up() argument
73 int orig_cpu = cp->elements[idx].cpu; in cpudl_heapify_up()
74 u64 orig_dl = cp->elements[idx].dl; in cpudl_heapify_up()
81 if (dl_time_before(orig_dl, cp->elements[p].dl)) in cpudl_heapify_up()
84 cp->elements[idx].cpu = cp->elements[p].cpu; in cpudl_heapify_up()
85 cp->elements[idx].dl = cp->elements[p].dl; in cpudl_heapify_up()
86 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_up()
90 cp->elements[idx].cpu = orig_cpu; in cpudl_heapify_up()
91 cp->elements[idx].dl = orig_dl; in cpudl_heapify_up()
92 cp->elements[cp->elements[idx].cpu].idx = idx; in cpudl_heapify_up()
95 static void cpudl_heapify(struct cpudl *cp, int idx) in cpudl_heapify() argument
97 if (idx > 0 && dl_time_before(cp->elements[parent(idx)].dl, in cpudl_heapify()
98 cp->elements[idx].dl)) in cpudl_heapify()
99 cpudl_heapify_up(cp, idx); in cpudl_heapify()
101 cpudl_heapify_down(cp, idx); in cpudl_heapify()
104 static inline int cpudl_maximum(struct cpudl *cp) in cpudl_maximum() argument
106 return cp->elements[0].cpu; in cpudl_maximum()
111 * @cp: the cpudl max-heap context
117 int cpudl_find(struct cpudl *cp, struct task_struct *p, in cpudl_find() argument
123 cpumask_and(later_mask, cp->free_cpus, p->cpus_ptr)) { in cpudl_find()
150 int best_cpu = cpudl_maximum(cp); in cpudl_find()
155 dl_time_before(dl_se->deadline, cp->elements[0].dl)) { in cpudl_find()
167 * @cp: the cpudl max-heap context
174 void cpudl_clear(struct cpudl *cp, int cpu) in cpudl_clear() argument
181 raw_spin_lock_irqsave(&cp->lock, flags); in cpudl_clear()
183 old_idx = cp->elements[cpu].idx; in cpudl_clear()
191 new_cpu = cp->elements[cp->size - 1].cpu; in cpudl_clear()
192 cp->elements[old_idx].dl = cp->elements[cp->size - 1].dl; in cpudl_clear()
193 cp->elements[old_idx].cpu = new_cpu; in cpudl_clear()
194 cp->size--; in cpudl_clear()
195 cp->elements[new_cpu].idx = old_idx; in cpudl_clear()
196 cp->elements[cpu].idx = IDX_INVALID; in cpudl_clear()
197 cpudl_heapify(cp, old_idx); in cpudl_clear()
199 cpumask_set_cpu(cpu, cp->free_cpus); in cpudl_clear()
201 raw_spin_unlock_irqrestore(&cp->lock, flags); in cpudl_clear()
206 * @cp: the cpudl max-heap context
214 void cpudl_set(struct cpudl *cp, int cpu, u64 dl) in cpudl_set() argument
221 raw_spin_lock_irqsave(&cp->lock, flags); in cpudl_set()
223 old_idx = cp->elements[cpu].idx; in cpudl_set()
225 int new_idx = cp->size++; in cpudl_set()
227 cp->elements[new_idx].dl = dl; in cpudl_set()
228 cp->elements[new_idx].cpu = cpu; in cpudl_set()
229 cp->elements[cpu].idx = new_idx; in cpudl_set()
230 cpudl_heapify_up(cp, new_idx); in cpudl_set()
231 cpumask_clear_cpu(cpu, cp->free_cpus); in cpudl_set()
233 cp->elements[old_idx].dl = dl; in cpudl_set()
234 cpudl_heapify(cp, old_idx); in cpudl_set()
237 raw_spin_unlock_irqrestore(&cp->lock, flags); in cpudl_set()
242 * @cp: the cpudl max-heap context
245 void cpudl_set_freecpu(struct cpudl *cp, int cpu) in cpudl_set_freecpu() argument
247 cpumask_set_cpu(cpu, cp->free_cpus); in cpudl_set_freecpu()
252 * @cp: the cpudl max-heap context
255 void cpudl_clear_freecpu(struct cpudl *cp, int cpu) in cpudl_clear_freecpu() argument
257 cpumask_clear_cpu(cpu, cp->free_cpus); in cpudl_clear_freecpu()
262 * @cp: the cpudl max-heap context
264 int cpudl_init(struct cpudl *cp) in cpudl_init() argument
268 raw_spin_lock_init(&cp->lock); in cpudl_init()
269 cp->size = 0; in cpudl_init()
271 cp->elements = kcalloc(nr_cpu_ids, in cpudl_init()
274 if (!cp->elements) in cpudl_init()
277 if (!zalloc_cpumask_var(&cp->free_cpus, GFP_KERNEL)) { in cpudl_init()
278 kfree(cp->elements); in cpudl_init()
283 cp->elements[i].idx = IDX_INVALID; in cpudl_init()
290 * @cp: the cpudl max-heap context
292 void cpudl_cleanup(struct cpudl *cp) in cpudl_cleanup() argument
294 free_cpumask_var(cp->free_cpus); in cpudl_cleanup()
295 kfree(cp->elements); in cpudl_cleanup()