Lines Matching full:pd

47 static void padata_free_pd(struct parallel_data *pd);
50 static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index) in padata_index_to_cpu() argument
54 target_cpu = cpumask_first(pd->cpumask.pcpu); in padata_index_to_cpu()
56 target_cpu = cpumask_next(target_cpu, pd->cpumask.pcpu); in padata_index_to_cpu()
61 static int padata_cpu_hash(struct parallel_data *pd, unsigned int seq_nr) in padata_cpu_hash() argument
67 int cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu); in padata_cpu_hash()
69 return padata_index_to_cpu(pd, cpu_index); in padata_cpu_hash()
180 struct parallel_data *pd; in padata_do_parallel() local
185 pd = rcu_dereference_bh(ps->pd); in padata_do_parallel()
191 if (!cpumask_test_cpu(*cb_cpu, pd->cpumask.cbcpu)) { in padata_do_parallel()
192 if (cpumask_empty(pd->cpumask.cbcpu)) in padata_do_parallel()
196 cpu_index = *cb_cpu % cpumask_weight(pd->cpumask.cbcpu); in padata_do_parallel()
198 cpu = cpumask_first(pd->cpumask.cbcpu); in padata_do_parallel()
200 cpu = cpumask_next(cpu, pd->cpumask.cbcpu); in padata_do_parallel()
209 refcount_inc(&pd->refcnt); in padata_do_parallel()
210 padata->pd = pd; in padata_do_parallel()
214 padata->seq_nr = ++pd->seq_nr; in padata_do_parallel()
248 static struct padata_priv *padata_find_next(struct parallel_data *pd, in padata_find_next() argument
253 int cpu = pd->cpu; in padata_find_next()
255 reorder = per_cpu_ptr(pd->reorder_list, cpu); in padata_find_next()
269 if (padata->seq_nr != pd->processed) { in padata_find_next()
276 ++pd->processed; in padata_find_next()
277 pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu, -1, false); in padata_find_next()
284 static void padata_reorder(struct parallel_data *pd) in padata_reorder() argument
286 struct padata_instance *pinst = pd->ps->pinst; in padata_reorder()
302 if (!spin_trylock_bh(&pd->lock)) in padata_reorder()
306 padata = padata_find_next(pd, true); in padata_reorder()
317 squeue = per_cpu_ptr(pd->squeue, cb_cpu); in padata_reorder()
326 spin_unlock_bh(&pd->lock); in padata_reorder()
332 * Ensure reorder queue is read after pd->lock is dropped so we see in padata_reorder()
338 reorder = per_cpu_ptr(pd->reorder_list, pd->cpu); in padata_reorder()
339 if (!list_empty(&reorder->list) && padata_find_next(pd, false)) in padata_reorder()
340 queue_work(pinst->serial_wq, &pd->reorder_work); in padata_reorder()
345 struct parallel_data *pd; in invoke_padata_reorder() local
348 pd = container_of(work, struct parallel_data, reorder_work); in invoke_padata_reorder()
349 padata_reorder(pd); in invoke_padata_reorder()
356 struct parallel_data *pd; in padata_serial_worker() local
362 pd = squeue->pd; in padata_serial_worker()
383 if (refcount_sub_and_test(cnt, &pd->refcnt)) in padata_serial_worker()
384 padata_free_pd(pd); in padata_serial_worker()
397 struct parallel_data *pd = padata->pd; in padata_do_serial() local
398 int hashed_cpu = padata_cpu_hash(pd, padata->seq_nr); in padata_do_serial()
399 struct padata_list *reorder = per_cpu_ptr(pd->reorder_list, hashed_cpu); in padata_do_serial()
416 * with the trylock of pd->lock in padata_reorder. Pairs with smp_mb in padata_do_serial()
421 padata_reorder(pd); in padata_do_serial()
434 /* Restrict parallel_wq workers to pd->cpumask.pcpu. */ in padata_setup_cpumasks()
551 static void padata_init_squeues(struct parallel_data *pd) in padata_init_squeues() argument
556 for_each_cpu(cpu, pd->cpumask.cbcpu) { in padata_init_squeues()
557 squeue = per_cpu_ptr(pd->squeue, cpu); in padata_init_squeues()
558 squeue->pd = pd; in padata_init_squeues()
565 static void padata_init_reorder_list(struct parallel_data *pd) in padata_init_reorder_list() argument
570 for_each_cpu(cpu, pd->cpumask.pcpu) { in padata_init_reorder_list()
571 list = per_cpu_ptr(pd->reorder_list, cpu); in padata_init_reorder_list()
580 struct parallel_data *pd; in padata_alloc_pd() local
582 pd = kzalloc(sizeof(struct parallel_data), GFP_KERNEL); in padata_alloc_pd()
583 if (!pd) in padata_alloc_pd()
586 pd->reorder_list = alloc_percpu(struct padata_list); in padata_alloc_pd()
587 if (!pd->reorder_list) in padata_alloc_pd()
590 pd->squeue = alloc_percpu(struct padata_serial_queue); in padata_alloc_pd()
591 if (!pd->squeue) in padata_alloc_pd()
594 pd->ps = ps; in padata_alloc_pd()
596 if (!alloc_cpumask_var(&pd->cpumask.pcpu, GFP_KERNEL)) in padata_alloc_pd()
598 if (!alloc_cpumask_var(&pd->cpumask.cbcpu, GFP_KERNEL)) in padata_alloc_pd()
601 cpumask_and(pd->cpumask.pcpu, pinst->cpumask.pcpu, cpu_online_mask); in padata_alloc_pd()
602 cpumask_and(pd->cpumask.cbcpu, pinst->cpumask.cbcpu, cpu_online_mask); in padata_alloc_pd()
604 padata_init_reorder_list(pd); in padata_alloc_pd()
605 padata_init_squeues(pd); in padata_alloc_pd()
606 pd->seq_nr = -1; in padata_alloc_pd()
607 refcount_set(&pd->refcnt, 1); in padata_alloc_pd()
608 spin_lock_init(&pd->lock); in padata_alloc_pd()
609 pd->cpu = cpumask_first(pd->cpumask.pcpu); in padata_alloc_pd()
610 INIT_WORK(&pd->reorder_work, invoke_padata_reorder); in padata_alloc_pd()
612 return pd; in padata_alloc_pd()
615 free_cpumask_var(pd->cpumask.pcpu); in padata_alloc_pd()
617 free_percpu(pd->squeue); in padata_alloc_pd()
619 free_percpu(pd->reorder_list); in padata_alloc_pd()
621 kfree(pd); in padata_alloc_pd()
626 static void padata_free_pd(struct parallel_data *pd) in padata_free_pd() argument
628 free_cpumask_var(pd->cpumask.pcpu); in padata_free_pd()
629 free_cpumask_var(pd->cpumask.cbcpu); in padata_free_pd()
630 free_percpu(pd->reorder_list); in padata_free_pd()
631 free_percpu(pd->squeue); in padata_free_pd()
632 kfree(pd); in padata_free_pd()
659 ps->opd = rcu_dereference_protected(ps->pd, 1); in padata_replace_one()
660 rcu_assign_pointer(ps->pd, pd_new); in padata_replace_one()
1079 struct parallel_data *pd; in padata_alloc_shell() local
1089 pd = padata_alloc_pd(ps); in padata_alloc_shell()
1092 if (!pd) in padata_alloc_shell()
1096 RCU_INIT_POINTER(ps->pd, pd); in padata_alloc_shell()
1116 struct parallel_data *pd; in padata_free_shell() local
1123 pd = rcu_dereference_protected(ps->pd, 1); in padata_free_shell()
1124 if (refcount_dec_and_test(&pd->refcnt)) in padata_free_shell()
1125 padata_free_pd(pd); in padata_free_shell()