116295becSSteffen Klassert /* 216295becSSteffen Klassert * padata.h - header for the padata parallelization interface 316295becSSteffen Klassert * 416295becSSteffen Klassert * Copyright (C) 2008, 2009 secunet Security Networks AG 516295becSSteffen Klassert * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com> 616295becSSteffen Klassert * 716295becSSteffen Klassert * This program is free software; you can redistribute it and/or modify it 816295becSSteffen Klassert * under the terms and conditions of the GNU General Public License, 916295becSSteffen Klassert * version 2, as published by the Free Software Foundation. 1016295becSSteffen Klassert * 1116295becSSteffen Klassert * This program is distributed in the hope it will be useful, but WITHOUT 1216295becSSteffen Klassert * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1316295becSSteffen Klassert * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1416295becSSteffen Klassert * more details. 1516295becSSteffen Klassert * 1616295becSSteffen Klassert * You should have received a copy of the GNU General Public License along with 1716295becSSteffen Klassert * this program; if not, write to the Free Software Foundation, Inc., 1816295becSSteffen Klassert * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 1916295becSSteffen Klassert */ 2016295becSSteffen Klassert 2116295becSSteffen Klassert #ifndef PADATA_H 2216295becSSteffen Klassert #define PADATA_H 2316295becSSteffen Klassert 2416295becSSteffen Klassert #include <linux/workqueue.h> 2516295becSSteffen Klassert #include <linux/spinlock.h> 2616295becSSteffen Klassert #include <linux/list.h> 27d46a5ac7SSteffen Klassert #include <linux/timer.h> 28e15bacbeSDan Kruchinin #include <linux/notifier.h> 29e15bacbeSDan Kruchinin 30e15bacbeSDan Kruchinin #define PADATA_CPU_SERIAL 0x01 31e15bacbeSDan Kruchinin #define PADATA_CPU_PARALLEL 0x02 3216295becSSteffen Klassert 330198ffd1SSteffen Klassert /** 340198ffd1SSteffen Klassert * struct padata_priv - Embedded to the users data structure. 350198ffd1SSteffen Klassert * 360198ffd1SSteffen Klassert * @list: List entry, to attach to the padata lists. 370198ffd1SSteffen Klassert * @pd: Pointer to the internal control structure. 380198ffd1SSteffen Klassert * @cb_cpu: Callback cpu for serializatioon. 390198ffd1SSteffen Klassert * @seq_nr: Sequence number of the parallelized data object. 400198ffd1SSteffen Klassert * @info: Used to pass information from the parallel to the serial function. 410198ffd1SSteffen Klassert * @parallel: Parallel execution function. 420198ffd1SSteffen Klassert * @serial: Serial complete function. 430198ffd1SSteffen Klassert */ 4416295becSSteffen Klassert struct padata_priv { 4516295becSSteffen Klassert struct list_head list; 4616295becSSteffen Klassert struct parallel_data *pd; 4716295becSSteffen Klassert int cb_cpu; 4816295becSSteffen Klassert int seq_nr; 4916295becSSteffen Klassert int info; 5016295becSSteffen Klassert void (*parallel)(struct padata_priv *padata); 5116295becSSteffen Klassert void (*serial)(struct padata_priv *padata); 5216295becSSteffen Klassert }; 5316295becSSteffen Klassert 540198ffd1SSteffen Klassert /** 550198ffd1SSteffen Klassert * struct padata_list 560198ffd1SSteffen Klassert * 570198ffd1SSteffen Klassert * @list: List head. 580198ffd1SSteffen Klassert * @lock: List lock. 590198ffd1SSteffen Klassert */ 6016295becSSteffen Klassert struct padata_list { 6116295becSSteffen Klassert struct list_head list; 6216295becSSteffen Klassert spinlock_t lock; 6316295becSSteffen Klassert }; 6416295becSSteffen Klassert 650198ffd1SSteffen Klassert /** 66e15bacbeSDan Kruchinin * struct padata_serial_queue - The percpu padata serial queue 67e15bacbeSDan Kruchinin * 68e15bacbeSDan Kruchinin * @serial: List to wait for serialization after reordering. 69e15bacbeSDan Kruchinin * @work: work struct for serialization. 70e15bacbeSDan Kruchinin * @pd: Backpointer to the internal control structure. 71e15bacbeSDan Kruchinin */ 72e15bacbeSDan Kruchinin struct padata_serial_queue { 73e15bacbeSDan Kruchinin struct padata_list serial; 74e15bacbeSDan Kruchinin struct work_struct work; 75e15bacbeSDan Kruchinin struct parallel_data *pd; 76e15bacbeSDan Kruchinin }; 77e15bacbeSDan Kruchinin 78e15bacbeSDan Kruchinin /** 79e15bacbeSDan Kruchinin * struct padata_parallel_queue - The percpu padata parallel queue 800198ffd1SSteffen Klassert * 810198ffd1SSteffen Klassert * @parallel: List to wait for parallelization. 820198ffd1SSteffen Klassert * @reorder: List to wait for reordering after parallel processing. 830198ffd1SSteffen Klassert * @serial: List to wait for serialization after reordering. 840198ffd1SSteffen Klassert * @pwork: work struct for parallelization. 850198ffd1SSteffen Klassert * @swork: work struct for serialization. 860198ffd1SSteffen Klassert * @pd: Backpointer to the internal control structure. 87e15bacbeSDan Kruchinin * @work: work struct for parallelization. 88e15bacbeSDan Kruchinin * @num_obj: Number of objects that are processed by this cpu. 890198ffd1SSteffen Klassert * @cpu_index: Index of the cpu. 900198ffd1SSteffen Klassert */ 91e15bacbeSDan Kruchinin struct padata_parallel_queue { 9216295becSSteffen Klassert struct padata_list parallel; 9316295becSSteffen Klassert struct padata_list reorder; 9416295becSSteffen Klassert struct parallel_data *pd; 95e15bacbeSDan Kruchinin struct work_struct work; 96e15bacbeSDan Kruchinin atomic_t num_obj; 9716295becSSteffen Klassert int cpu_index; 9816295becSSteffen Klassert }; 9916295becSSteffen Klassert 100e15bacbeSDan Kruchinin 1010198ffd1SSteffen Klassert /** 1020198ffd1SSteffen Klassert * struct parallel_data - Internal control structure, covers everything 1030198ffd1SSteffen Klassert * that depends on the cpumask in use. 1040198ffd1SSteffen Klassert * 1050198ffd1SSteffen Klassert * @pinst: padata instance. 106e15bacbeSDan Kruchinin * @pqueue: percpu padata queues used for parallelization. 107e15bacbeSDan Kruchinin * @squeue: percpu padata queues used for serialuzation. 1080198ffd1SSteffen Klassert * @seq_nr: The sequence number that will be attached to the next object. 1090198ffd1SSteffen Klassert * @reorder_objects: Number of objects waiting in the reorder queues. 1100198ffd1SSteffen Klassert * @refcnt: Number of objects holding a reference on this parallel_data. 1110198ffd1SSteffen Klassert * @max_seq_nr: Maximal used sequence number. 112e15bacbeSDan Kruchinin * @cpumask: Contains two cpumasks: pcpu and cbcpu for 113e15bacbeSDan Kruchinin * parallel and serial workers respectively. 1140198ffd1SSteffen Klassert * @lock: Reorder lock. 1155f1a8c1bSSteffen Klassert * @processed: Number of already processed objects. 1160198ffd1SSteffen Klassert * @timer: Reorder timer. 1170198ffd1SSteffen Klassert */ 11816295becSSteffen Klassert struct parallel_data { 11916295becSSteffen Klassert struct padata_instance *pinst; 120e15bacbeSDan Kruchinin struct padata_parallel_queue *pqueue; 121e15bacbeSDan Kruchinin struct padata_serial_queue *squeue; 12216295becSSteffen Klassert atomic_t seq_nr; 12316295becSSteffen Klassert atomic_t reorder_objects; 12416295becSSteffen Klassert atomic_t refcnt; 12516295becSSteffen Klassert unsigned int max_seq_nr; 126e15bacbeSDan Kruchinin struct { 127e15bacbeSDan Kruchinin cpumask_var_t pcpu; 128e15bacbeSDan Kruchinin cpumask_var_t cbcpu; 129e15bacbeSDan Kruchinin } cpumask; 1305f1a8c1bSSteffen Klassert spinlock_t lock ____cacheline_aligned; 1315f1a8c1bSSteffen Klassert unsigned int processed; 132d46a5ac7SSteffen Klassert struct timer_list timer; 13316295becSSteffen Klassert }; 13416295becSSteffen Klassert 1350198ffd1SSteffen Klassert /** 1360198ffd1SSteffen Klassert * struct padata_instance - The overall control structure. 1370198ffd1SSteffen Klassert * 1380198ffd1SSteffen Klassert * @cpu_notifier: cpu hotplug notifier. 1390198ffd1SSteffen Klassert * @wq: The workqueue in use. 1400198ffd1SSteffen Klassert * @pd: The internal control structure. 141e15bacbeSDan Kruchinin * @cpumask: User supplied cpumask. Contains two cpumasks: pcpu and 142e15bacbeSDan Kruchinin * cbcpu for parallel and serial works respectivly. 143e15bacbeSDan Kruchinin * @cpumask_change_notifier: Notifiers chain for user-defined notify 144e15bacbeSDan Kruchinin * callbacks that will be called when either @pcpu or @cbcpu 145e15bacbeSDan Kruchinin * or both cpumasks change. 1460198ffd1SSteffen Klassert * @lock: padata instance lock. 1470198ffd1SSteffen Klassert * @flags: padata flags. 1480198ffd1SSteffen Klassert */ 14916295becSSteffen Klassert struct padata_instance { 15016295becSSteffen Klassert struct notifier_block cpu_notifier; 15116295becSSteffen Klassert struct workqueue_struct *wq; 15216295becSSteffen Klassert struct parallel_data *pd; 153e15bacbeSDan Kruchinin struct { 154e15bacbeSDan Kruchinin cpumask_var_t pcpu; 155e15bacbeSDan Kruchinin cpumask_var_t cbcpu; 156e15bacbeSDan Kruchinin } cpumask; 157e15bacbeSDan Kruchinin struct blocking_notifier_head cpumask_change_notifier; 15816295becSSteffen Klassert struct mutex lock; 15916295becSSteffen Klassert u8 flags; 16016295becSSteffen Klassert #define PADATA_INIT 1 16116295becSSteffen Klassert #define PADATA_RESET 2 1624c879170SSteffen Klassert #define PADATA_INVALID 4 16316295becSSteffen Klassert }; 16416295becSSteffen Klassert 165e15bacbeSDan Kruchinin extern struct padata_instance *padata_alloc(struct workqueue_struct *wq); 166e15bacbeSDan Kruchinin extern struct padata_instance *__padata_alloc(struct workqueue_struct *wq, 167e15bacbeSDan Kruchinin const struct cpumask *pcpumask, 168e15bacbeSDan Kruchinin const struct cpumask *cbcpumask); 16916295becSSteffen Klassert extern void padata_free(struct padata_instance *pinst); 17016295becSSteffen Klassert extern int padata_do_parallel(struct padata_instance *pinst, 17116295becSSteffen Klassert struct padata_priv *padata, int cb_cpu); 17216295becSSteffen Klassert extern void padata_do_serial(struct padata_priv *padata); 173e15bacbeSDan Kruchinin extern int padata_get_cpumask(struct padata_instance *pinst, 174e15bacbeSDan Kruchinin int cpumask_type, struct cpumask *out_mask); 175e15bacbeSDan Kruchinin extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type, 17616295becSSteffen Klassert cpumask_var_t cpumask); 177e15bacbeSDan Kruchinin extern int __padata_set_cpumasks(struct padata_instance *pinst, 178e15bacbeSDan Kruchinin cpumask_var_t pcpumask, 179e15bacbeSDan Kruchinin cpumask_var_t cbcpumask); 180e15bacbeSDan Kruchinin extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask); 181e15bacbeSDan Kruchinin extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask); 1824c879170SSteffen Klassert extern int padata_start(struct padata_instance *pinst); 18316295becSSteffen Klassert extern void padata_stop(struct padata_instance *pinst); 184e15bacbeSDan Kruchinin extern int padata_register_cpumask_notifier(struct padata_instance *pinst, 185e15bacbeSDan Kruchinin struct notifier_block *nblock); 186e15bacbeSDan Kruchinin extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst, 187e15bacbeSDan Kruchinin struct notifier_block *nblock); 18816295becSSteffen Klassert #endif 189