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> |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 28 | #include <linux/notifier.h> |
Dan Kruchinin | 5e017dc | 2010-07-14 14:33:08 +0400 | [diff] [blame] | 29 | #include <linux/kobject.h> |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 30 | |
| 31 | #define PADATA_CPU_SERIAL 0x01 |
| 32 | #define PADATA_CPU_PARALLEL 0x02 |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 33 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 34 | /** |
| 35 | * struct padata_priv - Embedded to the users data structure. |
| 36 | * |
| 37 | * @list: List entry, to attach to the padata lists. |
| 38 | * @pd: Pointer to the internal control structure. |
| 39 | * @cb_cpu: Callback cpu for serializatioon. |
| 40 | * @seq_nr: Sequence number of the parallelized data object. |
| 41 | * @info: Used to pass information from the parallel to the serial function. |
| 42 | * @parallel: Parallel execution function. |
| 43 | * @serial: Serial complete function. |
| 44 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 45 | struct padata_priv { |
| 46 | struct list_head list; |
| 47 | struct parallel_data *pd; |
| 48 | int cb_cpu; |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 49 | int info; |
| 50 | void (*parallel)(struct padata_priv *padata); |
| 51 | void (*serial)(struct padata_priv *padata); |
| 52 | }; |
| 53 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 54 | /** |
| 55 | * struct padata_list |
| 56 | * |
| 57 | * @list: List head. |
| 58 | * @lock: List lock. |
| 59 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 60 | struct padata_list { |
| 61 | struct list_head list; |
| 62 | spinlock_t lock; |
| 63 | }; |
| 64 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 65 | /** |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 66 | * struct padata_serial_queue - The percpu padata serial queue |
| 67 | * |
| 68 | * @serial: List to wait for serialization after reordering. |
| 69 | * @work: work struct for serialization. |
| 70 | * @pd: Backpointer to the internal control structure. |
| 71 | */ |
| 72 | struct padata_serial_queue { |
| 73 | struct padata_list serial; |
| 74 | struct work_struct work; |
| 75 | struct parallel_data *pd; |
| 76 | }; |
| 77 | |
| 78 | /** |
| 79 | * struct padata_parallel_queue - The percpu padata parallel queue |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 80 | * |
| 81 | * @parallel: List to wait for parallelization. |
| 82 | * @reorder: List to wait for reordering after parallel processing. |
| 83 | * @serial: List to wait for serialization after reordering. |
| 84 | * @pwork: work struct for parallelization. |
| 85 | * @swork: work struct for serialization. |
| 86 | * @pd: Backpointer to the internal control structure. |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 87 | * @work: work struct for parallelization. |
| 88 | * @num_obj: Number of objects that are processed by this cpu. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 89 | * @cpu_index: Index of the cpu. |
| 90 | */ |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 91 | struct padata_parallel_queue { |
| 92 | struct padata_list parallel; |
| 93 | struct padata_list reorder; |
| 94 | struct parallel_data *pd; |
| 95 | struct work_struct work; |
| 96 | atomic_t num_obj; |
| 97 | int cpu_index; |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 98 | }; |
| 99 | |
Steffen Klassert | c635696 | 2010-07-27 07:15:50 +0200 | [diff] [blame] | 100 | /** |
| 101 | * struct padata_cpumask - The cpumasks for the parallel/serial workers |
| 102 | * |
| 103 | * @pcpu: cpumask for the parallel workers. |
| 104 | * @cbcpu: cpumask for the serial (callback) workers. |
| 105 | */ |
| 106 | struct padata_cpumask { |
| 107 | cpumask_var_t pcpu; |
| 108 | cpumask_var_t cbcpu; |
| 109 | }; |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 110 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 111 | /** |
| 112 | * struct parallel_data - Internal control structure, covers everything |
| 113 | * that depends on the cpumask in use. |
| 114 | * |
| 115 | * @pinst: padata instance. |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 116 | * @pqueue: percpu padata queues used for parallelization. |
| 117 | * @squeue: percpu padata queues used for serialuzation. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 118 | * @reorder_objects: Number of objects waiting in the reorder queues. |
| 119 | * @refcnt: Number of objects holding a reference on this parallel_data. |
| 120 | * @max_seq_nr: Maximal used sequence number. |
Steffen Klassert | c635696 | 2010-07-27 07:15:50 +0200 | [diff] [blame] | 121 | * @cpumask: The cpumasks in use for parallel and serial workers. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 122 | * @lock: Reorder lock. |
Steffen Klassert | 5f1a8c1 | 2010-07-07 15:32:39 +0200 | [diff] [blame] | 123 | * @processed: Number of already processed objects. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 124 | * @timer: Reorder timer. |
| 125 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 126 | struct parallel_data { |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 127 | struct padata_instance *pinst; |
Namhyung Kim | 57a2ce5 | 2010-09-03 19:09:46 +0800 | [diff] [blame] | 128 | struct padata_parallel_queue __percpu *pqueue; |
| 129 | struct padata_serial_queue __percpu *squeue; |
Steffen Klassert | c635696 | 2010-07-27 07:15:50 +0200 | [diff] [blame] | 130 | atomic_t reorder_objects; |
| 131 | atomic_t refcnt; |
Mathias Krause | 0b6b098 | 2013-10-25 12:14:15 +0200 | [diff] [blame^] | 132 | atomic_t seq_nr; |
Steffen Klassert | c635696 | 2010-07-27 07:15:50 +0200 | [diff] [blame] | 133 | struct padata_cpumask cpumask; |
| 134 | spinlock_t lock ____cacheline_aligned; |
| 135 | unsigned int processed; |
| 136 | struct timer_list timer; |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 137 | }; |
| 138 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 139 | /** |
| 140 | * struct padata_instance - The overall control structure. |
| 141 | * |
| 142 | * @cpu_notifier: cpu hotplug notifier. |
| 143 | * @wq: The workqueue in use. |
| 144 | * @pd: The internal control structure. |
Steffen Klassert | c635696 | 2010-07-27 07:15:50 +0200 | [diff] [blame] | 145 | * @cpumask: User supplied cpumasks for parallel and serial works. |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 146 | * @cpumask_change_notifier: Notifiers chain for user-defined notify |
| 147 | * callbacks that will be called when either @pcpu or @cbcpu |
Dan Kruchinin | 5e017dc | 2010-07-14 14:33:08 +0400 | [diff] [blame] | 148 | * or both cpumasks change. |
| 149 | * @kobj: padata instance kernel object. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 150 | * @lock: padata instance lock. |
| 151 | * @flags: padata flags. |
| 152 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 153 | struct padata_instance { |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 154 | struct notifier_block cpu_notifier; |
| 155 | struct workqueue_struct *wq; |
| 156 | struct parallel_data *pd; |
Steffen Klassert | c635696 | 2010-07-27 07:15:50 +0200 | [diff] [blame] | 157 | struct padata_cpumask cpumask; |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 158 | struct blocking_notifier_head cpumask_change_notifier; |
Dan Kruchinin | 5e017dc | 2010-07-14 14:33:08 +0400 | [diff] [blame] | 159 | struct kobject kobj; |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 160 | struct mutex lock; |
| 161 | u8 flags; |
| 162 | #define PADATA_INIT 1 |
| 163 | #define PADATA_RESET 2 |
| 164 | #define PADATA_INVALID 4 |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 165 | }; |
| 166 | |
Steffen Klassert | e6cc117 | 2010-07-27 07:14:28 +0200 | [diff] [blame] | 167 | extern struct padata_instance *padata_alloc_possible( |
| 168 | struct workqueue_struct *wq); |
| 169 | extern struct padata_instance *padata_alloc(struct workqueue_struct *wq, |
| 170 | const struct cpumask *pcpumask, |
| 171 | const struct cpumask *cbcpumask); |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 172 | extern void padata_free(struct padata_instance *pinst); |
| 173 | extern int padata_do_parallel(struct padata_instance *pinst, |
| 174 | struct padata_priv *padata, int cb_cpu); |
| 175 | extern void padata_do_serial(struct padata_priv *padata); |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 176 | extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type, |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 177 | cpumask_var_t cpumask); |
Steffen Klassert | 65ff577 | 2010-07-27 07:15:06 +0200 | [diff] [blame] | 178 | extern int padata_set_cpumasks(struct padata_instance *pinst, |
| 179 | cpumask_var_t pcpumask, |
| 180 | cpumask_var_t cbcpumask); |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 181 | extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask); |
| 182 | extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask); |
Steffen Klassert | 4c87917 | 2010-07-07 15:30:10 +0200 | [diff] [blame] | 183 | extern int padata_start(struct padata_instance *pinst); |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 184 | extern void padata_stop(struct padata_instance *pinst); |
Dan Kruchinin | e15bacb | 2010-07-14 14:31:57 +0400 | [diff] [blame] | 185 | extern int padata_register_cpumask_notifier(struct padata_instance *pinst, |
| 186 | struct notifier_block *nblock); |
| 187 | extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst, |
| 188 | struct notifier_block *nblock); |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 189 | #endif |