Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 1 | /* |
| 2 | * padata.h - header for the padata parallelization interface |
| 3 | * |
| 4 | * Copyright (C) 2008, 2009 secunet Security Networks AG |
| 5 | * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms and conditions of the GNU General Public License, |
| 9 | * version 2, as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #ifndef PADATA_H |
| 22 | #define PADATA_H |
| 23 | |
| 24 | #include <linux/workqueue.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/list.h> |
Steffen Klassert | d46a5ac | 2010-05-19 13:43:14 +1000 | [diff] [blame] | 27 | #include <linux/timer.h> |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 28 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 29 | /** |
| 30 | * struct padata_priv - Embedded to the users data structure. |
| 31 | * |
| 32 | * @list: List entry, to attach to the padata lists. |
| 33 | * @pd: Pointer to the internal control structure. |
| 34 | * @cb_cpu: Callback cpu for serializatioon. |
| 35 | * @seq_nr: Sequence number of the parallelized data object. |
| 36 | * @info: Used to pass information from the parallel to the serial function. |
| 37 | * @parallel: Parallel execution function. |
| 38 | * @serial: Serial complete function. |
| 39 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 40 | struct padata_priv { |
| 41 | struct list_head list; |
| 42 | struct parallel_data *pd; |
| 43 | int cb_cpu; |
| 44 | int seq_nr; |
| 45 | int info; |
| 46 | void (*parallel)(struct padata_priv *padata); |
| 47 | void (*serial)(struct padata_priv *padata); |
| 48 | }; |
| 49 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 50 | /** |
| 51 | * struct padata_list |
| 52 | * |
| 53 | * @list: List head. |
| 54 | * @lock: List lock. |
| 55 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 56 | struct padata_list { |
| 57 | struct list_head list; |
| 58 | spinlock_t lock; |
| 59 | }; |
| 60 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 61 | /** |
| 62 | * struct padata_queue - The percpu padata queues. |
| 63 | * |
| 64 | * @parallel: List to wait for parallelization. |
| 65 | * @reorder: List to wait for reordering after parallel processing. |
| 66 | * @serial: List to wait for serialization after reordering. |
| 67 | * @pwork: work struct for parallelization. |
| 68 | * @swork: work struct for serialization. |
| 69 | * @pd: Backpointer to the internal control structure. |
| 70 | * @num_obj: Number of objects that are processed by this cpu. |
| 71 | * @cpu_index: Index of the cpu. |
| 72 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 73 | struct padata_queue { |
| 74 | struct padata_list parallel; |
| 75 | struct padata_list reorder; |
| 76 | struct padata_list serial; |
| 77 | struct work_struct pwork; |
| 78 | struct work_struct swork; |
| 79 | struct parallel_data *pd; |
| 80 | atomic_t num_obj; |
| 81 | int cpu_index; |
| 82 | }; |
| 83 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 84 | /** |
| 85 | * struct parallel_data - Internal control structure, covers everything |
| 86 | * that depends on the cpumask in use. |
| 87 | * |
| 88 | * @pinst: padata instance. |
| 89 | * @queue: percpu padata queues. |
| 90 | * @seq_nr: The sequence number that will be attached to the next object. |
| 91 | * @reorder_objects: Number of objects waiting in the reorder queues. |
| 92 | * @refcnt: Number of objects holding a reference on this parallel_data. |
| 93 | * @max_seq_nr: Maximal used sequence number. |
| 94 | * @cpumask: cpumask in use. |
| 95 | * @lock: Reorder lock. |
| 96 | * @timer: Reorder timer. |
| 97 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 98 | struct parallel_data { |
| 99 | struct padata_instance *pinst; |
| 100 | struct padata_queue *queue; |
| 101 | atomic_t seq_nr; |
| 102 | atomic_t reorder_objects; |
| 103 | atomic_t refcnt; |
| 104 | unsigned int max_seq_nr; |
| 105 | cpumask_var_t cpumask; |
| 106 | spinlock_t lock; |
Steffen Klassert | d46a5ac | 2010-05-19 13:43:14 +1000 | [diff] [blame] | 107 | struct timer_list timer; |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 108 | }; |
| 109 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 110 | /** |
| 111 | * struct padata_instance - The overall control structure. |
| 112 | * |
| 113 | * @cpu_notifier: cpu hotplug notifier. |
| 114 | * @wq: The workqueue in use. |
| 115 | * @pd: The internal control structure. |
| 116 | * @cpumask: User supplied cpumask. |
| 117 | * @lock: padata instance lock. |
| 118 | * @flags: padata flags. |
| 119 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 120 | struct padata_instance { |
| 121 | struct notifier_block cpu_notifier; |
| 122 | struct workqueue_struct *wq; |
| 123 | struct parallel_data *pd; |
| 124 | cpumask_var_t cpumask; |
| 125 | struct mutex lock; |
| 126 | u8 flags; |
| 127 | #define PADATA_INIT 1 |
| 128 | #define PADATA_RESET 2 |
| 129 | }; |
| 130 | |
| 131 | extern struct padata_instance *padata_alloc(const struct cpumask *cpumask, |
| 132 | struct workqueue_struct *wq); |
| 133 | extern void padata_free(struct padata_instance *pinst); |
| 134 | extern int padata_do_parallel(struct padata_instance *pinst, |
| 135 | struct padata_priv *padata, int cb_cpu); |
| 136 | extern void padata_do_serial(struct padata_priv *padata); |
| 137 | extern int padata_set_cpumask(struct padata_instance *pinst, |
| 138 | cpumask_var_t cpumask); |
| 139 | extern int padata_add_cpu(struct padata_instance *pinst, int cpu); |
| 140 | extern int padata_remove_cpu(struct padata_instance *pinst, int cpu); |
| 141 | extern void padata_start(struct padata_instance *pinst); |
| 142 | extern void padata_stop(struct padata_instance *pinst); |
| 143 | #endif |