23 #include <linux/export.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
34 #define MAX_OBJ_NUM 1000
40 target_cpu = cpumask_first(pd->
cpumask.pcpu);
42 target_cpu = cpumask_next(target_cpu, pd->
cpumask.pcpu);
61 return padata_index_to_cpu(pd, cpu_index);
64 static void padata_parallel_worker(
struct work_struct *parallel_work)
78 list_replace_init(&pqueue->
parallel.list, &local_list);
81 while (!list_empty(&local_list)) {
87 list_del_init(&padata->
list);
137 target_cpu = padata_cpu_hash(pd);
147 rcu_read_unlock_bh();
173 unsigned int next_nr, next_index;
178 num_cpus = cpumask_weight(pd->
cpumask.pcpu);
185 next_index = next_nr % num_cpus;
186 cpu = padata_index_to_cpu(pd, next_index);
191 reorder = &next_queue->
reorder;
193 if (!list_empty(&reorder->
list)) {
197 spin_lock(&reorder->
lock);
198 list_del_init(&padata->
list);
200 spin_unlock(&reorder->
lock);
235 if (!spin_trylock_bh(&pd->lock))
239 padata = padata_get_next(pd);
255 if (PTR_ERR(padata) == -
ENODATA) {
257 spin_unlock_bh(&pd->lock);
264 spin_lock(&squeue->
serial.lock);
266 spin_unlock(&squeue->
serial.lock);
271 spin_unlock_bh(&pd->lock);
287 static void padata_reorder_timer(
unsigned long arg)
294 static void padata_serial_worker(
struct work_struct *serial_work)
304 spin_lock(&squeue->
serial.lock);
305 list_replace_init(&squeue->
serial.list, &local_list);
306 spin_unlock(&squeue->
serial.lock);
308 while (!list_empty(&local_list)) {
314 list_del_init(&padata->
list);
341 spin_lock(&pqueue->
reorder.lock);
344 spin_unlock(&pqueue->
reorder.lock);
353 const struct cpumask *pcpumask,
354 const struct cpumask *cbcpumask)
359 cpumask_and(pd->
cpumask.pcpu, pcpumask, cpu_online_mask);
361 free_cpumask_var(pd->
cpumask.cbcpu);
365 cpumask_and(pd->
cpumask.cbcpu, cbcpumask, cpu_online_mask);
369 static void __padata_list_init(
struct padata_list *pd_list)
371 INIT_LIST_HEAD(&pd_list->
list);
384 __padata_list_init(&squeue->
serial);
402 __padata_list_init(&pqueue->
reorder);
403 __padata_list_init(&pqueue->
parallel);
411 const struct cpumask *pcpumask,
412 const struct cpumask *cbcpumask)
426 goto err_free_pqueue;
427 if (padata_setup_cpumasks(pd, pcpumask, cbcpumask) < 0)
428 goto err_free_squeue;
430 padata_init_pqueues(pd);
431 padata_init_squeues(pd);
453 free_cpumask_var(pd->
cpumask.pcpu);
454 free_cpumask_var(pd->
cpumask.cbcpu);
500 padata_flush_queues(pinst->
pd);
509 int notification_mask = 0;
522 padata_flush_queues(pd_old);
523 padata_free_pd(pd_old);
525 if (notification_mask)
569 if (!cpumask_intersects(cpumask, cpu_online_mask)) {
585 valid = padata_validate_cpumask(pinst, pcpumask);
587 __padata_stop(pinst);
591 valid = padata_validate_cpumask(pinst, cbcpumask);
593 __padata_stop(pinst);
596 pd = padata_alloc_pd(pinst, pcpumask, cbcpumask);
600 cpumask_copy(pinst->
cpumask.pcpu, pcpumask);
601 cpumask_copy(pinst->
cpumask.cbcpu, cbcpumask);
603 padata_replace(pinst, pd);
606 __padata_start(pinst);
628 err = __padata_set_cpumasks(pinst, pcpumask, cbcpumask);
650 struct cpumask *serial_mask, *parallel_mask;
656 switch (cpumask_type) {
658 serial_mask = pinst->
cpumask.cbcpu;
662 parallel_mask = pinst->
cpumask.pcpu;
669 err = __padata_set_cpumasks(pinst, parallel_mask, serial_mask);
684 pd = padata_alloc_pd(pinst, pinst->
cpumask.pcpu,
689 padata_replace(pinst, pd);
691 if (padata_validate_cpumask(pinst, pinst->
cpumask.pcpu) &&
692 padata_validate_cpumask(pinst, pinst->
cpumask.cbcpu))
693 __padata_start(pinst);
722 cpumask_set_cpu(cpu, pinst->
cpumask.cbcpu);
724 cpumask_set_cpu(cpu, pinst->
cpumask.pcpu);
726 err = __padata_add_cpu(pinst, cpu);
741 if (!padata_validate_cpumask(pinst, pinst->
cpumask.pcpu) ||
742 !padata_validate_cpumask(pinst, pinst->
cpumask.cbcpu))
743 __padata_stop(pinst);
745 pd = padata_alloc_pd(pinst, pinst->
cpumask.pcpu,
750 padata_replace(pinst, pd);
752 cpumask_clear_cpu(cpu, pd->
cpumask.cbcpu);
753 cpumask_clear_cpu(cpu, pd->
cpumask.pcpu);
781 cpumask_clear_cpu(cpu, pinst->
cpumask.cbcpu);
783 cpumask_clear_cpu(cpu, pinst->
cpumask.pcpu);
785 err = __padata_remove_cpu(pinst, cpu);
808 __padata_start(pinst);
824 __padata_stop(pinst);
829 #ifdef CONFIG_HOTPLUG_CPU
831 static inline int pinst_has_cpu(
struct padata_instance *pinst,
int cpu)
839 unsigned long action,
void *hcpu)
843 int cpu = (
unsigned long)hcpu;
850 if (!pinst_has_cpu(pinst, cpu))
853 err = __padata_add_cpu(pinst, cpu);
856 return notifier_from_errno(err);
861 if (!pinst_has_cpu(pinst, cpu))
864 err = __padata_remove_cpu(pinst, cpu);
867 return notifier_from_errno(err);
872 if (!pinst_has_cpu(pinst, cpu))
875 __padata_remove_cpu(pinst, cpu);
880 if (!pinst_has_cpu(pinst, cpu))
883 __padata_add_cpu(pinst, cpu);
893 #ifdef CONFIG_HOTPLUG_CPU
898 padata_free_pd(pinst->
pd);
899 free_cpumask_var(pinst->
cpumask.pcpu);
900 free_cpumask_var(pinst->
cpumask.cbcpu);
904 #define kobj2pinst(_kobj) \
905 container_of(_kobj, struct padata_instance, kobj)
906 #define attr2pentry(_attr) \
907 container_of(_attr, struct padata_sysfs_entry, attr)
909 static void padata_sysfs_release(
struct kobject *
kobj)
912 __padata_free(pinst);
930 cpumask = pinst->
cpumask.cbcpu;
939 len +=
sprintf(buf + len,
"\n");
953 if (!alloc_cpumask_var(&new_cpumask,
GFP_KERNEL))
956 ret = bitmap_parse(buf, count,
cpumask_bits(new_cpumask),
961 mask_type = !
strcmp(attr->
name,
"serial_cpumask") ?
968 free_cpumask_var(new_cpumask);
972 #define PADATA_ATTR_RW(_name, _show_name, _store_name) \
973 static struct padata_sysfs_entry _name##_attr = \
974 __ATTR(_name, 0644, _show_name, _store_name)
975 #define PADATA_ATTR_RO(_name, _show_name) \
976 static struct padata_sysfs_entry _name##_attr = \
977 __ATTR(_name, 0400, _show_name, NULL)
987 static struct attribute *padata_default_attrs[] = {
988 &serial_cpumask_attr.attr,
989 ¶llel_cpumask_attr.attr,
1003 ret = pentry->
show(pinst, attr, buf);
1009 const char *buf,
size_t count)
1018 ret = pentry->
store(pinst, attr, buf, count);
1023 static const struct sysfs_ops padata_sysfs_ops = {
1024 .show = padata_sysfs_show,
1025 .store = padata_sysfs_store,
1028 static struct kobj_type padata_attr_type = {
1029 .sysfs_ops = &padata_sysfs_ops,
1030 .default_attrs = padata_default_attrs,
1031 .release = padata_sysfs_release,
1056 const struct cpumask *pcpumask,
1057 const struct cpumask *cbcpumask)
1070 free_cpumask_var(pinst->
cpumask.pcpu);
1073 if (!padata_validate_cpumask(pinst, pcpumask) ||
1074 !padata_validate_cpumask(pinst, cbcpumask))
1075 goto err_free_masks;
1077 pd = padata_alloc_pd(pinst, pcpumask, cbcpumask);
1079 goto err_free_masks;
1085 cpumask_copy(pinst->
cpumask.pcpu, pcpumask);
1086 cpumask_copy(pinst->
cpumask.cbcpu, cbcpumask);
1090 #ifdef CONFIG_HOTPLUG_CPU
1091 pinst->
cpu_notifier.notifier_call = padata_cpu_callback;
1105 free_cpumask_var(pinst->
cpumask.pcpu);
1106 free_cpumask_var(pinst->
cpumask.cbcpu);