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. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 70 | * @cpu_index: Index of the cpu. |
| 71 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 72 | struct padata_queue { |
| 73 | struct padata_list parallel; |
| 74 | struct padata_list reorder; |
| 75 | struct padata_list serial; |
| 76 | struct work_struct pwork; |
| 77 | struct work_struct swork; |
| 78 | struct parallel_data *pd; |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 79 | int cpu_index; |
| 80 | }; |
| 81 | |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 82 | /** |
| 83 | * struct parallel_data - Internal control structure, covers everything |
| 84 | * that depends on the cpumask in use. |
| 85 | * |
| 86 | * @pinst: padata instance. |
| 87 | * @queue: percpu padata queues. |
| 88 | * @seq_nr: The sequence number that will be attached to the next object. |
| 89 | * @reorder_objects: Number of objects waiting in the reorder queues. |
| 90 | * @refcnt: Number of objects holding a reference on this parallel_data. |
| 91 | * @max_seq_nr: Maximal used sequence number. |
| 92 | * @cpumask: cpumask in use. |
| 93 | * @lock: Reorder lock. |
Steffen Klassert | 5f1a8c1 | 2010-07-07 15:32:39 +0200 | [diff] [blame^] | 94 | * @processed: Number of already processed objects. |
Steffen Klassert | 0198ffd | 2010-05-19 13:44:27 +1000 | [diff] [blame] | 95 | * @timer: Reorder timer. |
| 96 | */ |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 97 | struct parallel_data { |
| 98 | struct padata_instance *pinst; |
| 99 | struct padata_queue *queue; |
| 100 | atomic_t seq_nr; |
| 101 | atomic_t reorder_objects; |
| 102 | atomic_t refcnt; |
| 103 | unsigned int max_seq_nr; |
| 104 | cpumask_var_t cpumask; |
Steffen Klassert | 5f1a8c1 | 2010-07-07 15:32:39 +0200 | [diff] [blame^] | 105 | spinlock_t lock ____cacheline_aligned; |
| 106 | unsigned int processed; |
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 |
Steffen Klassert | 4c87917 | 2010-07-07 15:30:10 +0200 | [diff] [blame] | 129 | #define PADATA_INVALID 4 |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | extern struct padata_instance *padata_alloc(const struct cpumask *cpumask, |
| 133 | struct workqueue_struct *wq); |
| 134 | extern void padata_free(struct padata_instance *pinst); |
| 135 | extern int padata_do_parallel(struct padata_instance *pinst, |
| 136 | struct padata_priv *padata, int cb_cpu); |
| 137 | extern void padata_do_serial(struct padata_priv *padata); |
| 138 | extern int padata_set_cpumask(struct padata_instance *pinst, |
| 139 | cpumask_var_t cpumask); |
| 140 | extern int padata_add_cpu(struct padata_instance *pinst, int cpu); |
| 141 | extern int padata_remove_cpu(struct padata_instance *pinst, int cpu); |
Steffen Klassert | 4c87917 | 2010-07-07 15:30:10 +0200 | [diff] [blame] | 142 | extern int padata_start(struct padata_instance *pinst); |
Steffen Klassert | 16295be | 2010-01-06 19:47:10 +1100 | [diff] [blame] | 143 | extern void padata_stop(struct padata_instance *pinst); |
| 144 | #endif |