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> 295e017dc3SDan Kruchinin #include <linux/kobject.h> 30e15bacbeSDan Kruchinin 31e15bacbeSDan Kruchinin #define PADATA_CPU_SERIAL 0x01 32e15bacbeSDan Kruchinin #define PADATA_CPU_PARALLEL 0x02 3316295becSSteffen Klassert 340198ffd1SSteffen Klassert /** 350198ffd1SSteffen Klassert * struct padata_priv - Embedded to the users data structure. 360198ffd1SSteffen Klassert * 370198ffd1SSteffen Klassert * @list: List entry, to attach to the padata lists. 380198ffd1SSteffen Klassert * @pd: Pointer to the internal control structure. 390198ffd1SSteffen Klassert * @cb_cpu: Callback cpu for serializatioon. 400198ffd1SSteffen Klassert * @seq_nr: Sequence number of the parallelized data object. 410198ffd1SSteffen Klassert * @info: Used to pass information from the parallel to the serial function. 420198ffd1SSteffen Klassert * @parallel: Parallel execution function. 430198ffd1SSteffen Klassert * @serial: Serial complete function. 440198ffd1SSteffen Klassert */ 4516295becSSteffen Klassert struct padata_priv { 4616295becSSteffen Klassert struct list_head list; 4716295becSSteffen Klassert struct parallel_data *pd; 4816295becSSteffen Klassert int cb_cpu; 4916295becSSteffen Klassert int seq_nr; 5016295becSSteffen Klassert int info; 5116295becSSteffen Klassert void (*parallel)(struct padata_priv *padata); 5216295becSSteffen Klassert void (*serial)(struct padata_priv *padata); 5316295becSSteffen Klassert }; 5416295becSSteffen Klassert 550198ffd1SSteffen Klassert /** 560198ffd1SSteffen Klassert * struct padata_list 570198ffd1SSteffen Klassert * 580198ffd1SSteffen Klassert * @list: List head. 590198ffd1SSteffen Klassert * @lock: List lock. 600198ffd1SSteffen Klassert */ 6116295becSSteffen Klassert struct padata_list { 6216295becSSteffen Klassert struct list_head list; 6316295becSSteffen Klassert spinlock_t lock; 6416295becSSteffen Klassert }; 6516295becSSteffen Klassert 660198ffd1SSteffen Klassert /** 67e15bacbeSDan Kruchinin * struct padata_serial_queue - The percpu padata serial queue 68e15bacbeSDan Kruchinin * 69e15bacbeSDan Kruchinin * @serial: List to wait for serialization after reordering. 70e15bacbeSDan Kruchinin * @work: work struct for serialization. 71e15bacbeSDan Kruchinin * @pd: Backpointer to the internal control structure. 72e15bacbeSDan Kruchinin */ 73e15bacbeSDan Kruchinin struct padata_serial_queue { 74e15bacbeSDan Kruchinin struct padata_list serial; 75e15bacbeSDan Kruchinin struct work_struct work; 76e15bacbeSDan Kruchinin struct parallel_data *pd; 77e15bacbeSDan Kruchinin }; 78e15bacbeSDan Kruchinin 79e15bacbeSDan Kruchinin /** 80e15bacbeSDan Kruchinin * struct padata_parallel_queue - The percpu padata parallel queue 810198ffd1SSteffen Klassert * 820198ffd1SSteffen Klassert * @parallel: List to wait for parallelization. 830198ffd1SSteffen Klassert * @reorder: List to wait for reordering after parallel processing. 840198ffd1SSteffen Klassert * @serial: List to wait for serialization after reordering. 850198ffd1SSteffen Klassert * @pwork: work struct for parallelization. 860198ffd1SSteffen Klassert * @swork: work struct for serialization. 870198ffd1SSteffen Klassert * @pd: Backpointer to the internal control structure. 88e15bacbeSDan Kruchinin * @work: work struct for parallelization. 89e15bacbeSDan Kruchinin * @num_obj: Number of objects that are processed by this cpu. 900198ffd1SSteffen Klassert * @cpu_index: Index of the cpu. 910198ffd1SSteffen Klassert */ 92e15bacbeSDan Kruchinin struct padata_parallel_queue { 9316295becSSteffen Klassert struct padata_list parallel; 9416295becSSteffen Klassert struct padata_list reorder; 9516295becSSteffen Klassert struct parallel_data *pd; 96e15bacbeSDan Kruchinin struct work_struct work; 97e15bacbeSDan Kruchinin atomic_t num_obj; 9816295becSSteffen Klassert int cpu_index; 9916295becSSteffen Klassert }; 10016295becSSteffen Klassert 101c635696cSSteffen Klassert /** 102c635696cSSteffen Klassert * struct padata_cpumask - The cpumasks for the parallel/serial workers 103c635696cSSteffen Klassert * 104c635696cSSteffen Klassert * @pcpu: cpumask for the parallel workers. 105c635696cSSteffen Klassert * @cbcpu: cpumask for the serial (callback) workers. 106c635696cSSteffen Klassert */ 107c635696cSSteffen Klassert struct padata_cpumask { 108c635696cSSteffen Klassert cpumask_var_t pcpu; 109c635696cSSteffen Klassert cpumask_var_t cbcpu; 110c635696cSSteffen Klassert }; 111e15bacbeSDan Kruchinin 1120198ffd1SSteffen Klassert /** 1130198ffd1SSteffen Klassert * struct parallel_data - Internal control structure, covers everything 1140198ffd1SSteffen Klassert * that depends on the cpumask in use. 1150198ffd1SSteffen Klassert * 1160198ffd1SSteffen Klassert * @pinst: padata instance. 117e15bacbeSDan Kruchinin * @pqueue: percpu padata queues used for parallelization. 118e15bacbeSDan Kruchinin * @squeue: percpu padata queues used for serialuzation. 1190198ffd1SSteffen Klassert * @seq_nr: The sequence number that will be attached to the next object. 1200198ffd1SSteffen Klassert * @reorder_objects: Number of objects waiting in the reorder queues. 1210198ffd1SSteffen Klassert * @refcnt: Number of objects holding a reference on this parallel_data. 1220198ffd1SSteffen Klassert * @max_seq_nr: Maximal used sequence number. 123c635696cSSteffen Klassert * @cpumask: The cpumasks in use for parallel and serial workers. 1240198ffd1SSteffen Klassert * @lock: Reorder lock. 1255f1a8c1bSSteffen Klassert * @processed: Number of already processed objects. 1260198ffd1SSteffen Klassert * @timer: Reorder timer. 1270198ffd1SSteffen Klassert */ 12816295becSSteffen Klassert struct parallel_data { 12916295becSSteffen Klassert struct padata_instance *pinst; 13057a2ce5fSNamhyung Kim struct padata_parallel_queue __percpu *pqueue; 13157a2ce5fSNamhyung Kim struct padata_serial_queue __percpu *squeue; 13216295becSSteffen Klassert atomic_t seq_nr; 13316295becSSteffen Klassert atomic_t reorder_objects; 13416295becSSteffen Klassert atomic_t refcnt; 13516295becSSteffen Klassert unsigned int max_seq_nr; 136c635696cSSteffen Klassert struct padata_cpumask cpumask; 1375f1a8c1bSSteffen Klassert spinlock_t lock ____cacheline_aligned; 1385f1a8c1bSSteffen Klassert unsigned int processed; 139d46a5ac7SSteffen Klassert struct timer_list timer; 14016295becSSteffen Klassert }; 14116295becSSteffen Klassert 1420198ffd1SSteffen Klassert /** 1430198ffd1SSteffen Klassert * struct padata_instance - The overall control structure. 1440198ffd1SSteffen Klassert * 1450198ffd1SSteffen Klassert * @cpu_notifier: cpu hotplug notifier. 1460198ffd1SSteffen Klassert * @wq: The workqueue in use. 1470198ffd1SSteffen Klassert * @pd: The internal control structure. 148c635696cSSteffen Klassert * @cpumask: User supplied cpumasks for parallel and serial works. 149e15bacbeSDan Kruchinin * @cpumask_change_notifier: Notifiers chain for user-defined notify 150e15bacbeSDan Kruchinin * callbacks that will be called when either @pcpu or @cbcpu 151e15bacbeSDan Kruchinin * or both cpumasks change. 1525e017dc3SDan Kruchinin * @kobj: padata instance kernel object. 1530198ffd1SSteffen Klassert * @lock: padata instance lock. 1540198ffd1SSteffen Klassert * @flags: padata flags. 1550198ffd1SSteffen Klassert */ 15616295becSSteffen Klassert struct padata_instance { 15716295becSSteffen Klassert struct notifier_block cpu_notifier; 15816295becSSteffen Klassert struct workqueue_struct *wq; 15916295becSSteffen Klassert struct parallel_data *pd; 160c635696cSSteffen Klassert struct padata_cpumask cpumask; 161e15bacbeSDan Kruchinin struct blocking_notifier_head cpumask_change_notifier; 1625e017dc3SDan Kruchinin struct kobject kobj; 16316295becSSteffen Klassert struct mutex lock; 16416295becSSteffen Klassert u8 flags; 16516295becSSteffen Klassert #define PADATA_INIT 1 16616295becSSteffen Klassert #define PADATA_RESET 2 1674c879170SSteffen Klassert #define PADATA_INVALID 4 16816295becSSteffen Klassert }; 16916295becSSteffen Klassert 170e6cc1170SSteffen Klassert extern struct padata_instance *padata_alloc_possible( 171e6cc1170SSteffen Klassert struct workqueue_struct *wq); 172e6cc1170SSteffen Klassert extern struct padata_instance *padata_alloc(struct workqueue_struct *wq, 173e15bacbeSDan Kruchinin const struct cpumask *pcpumask, 174e15bacbeSDan Kruchinin const struct cpumask *cbcpumask); 17516295becSSteffen Klassert extern void padata_free(struct padata_instance *pinst); 17616295becSSteffen Klassert extern int padata_do_parallel(struct padata_instance *pinst, 17716295becSSteffen Klassert struct padata_priv *padata, int cb_cpu); 17816295becSSteffen Klassert extern void padata_do_serial(struct padata_priv *padata); 179e15bacbeSDan Kruchinin extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type, 18016295becSSteffen Klassert cpumask_var_t cpumask); 18165ff577eSSteffen Klassert extern int padata_set_cpumasks(struct padata_instance *pinst, 182e15bacbeSDan Kruchinin cpumask_var_t pcpumask, 183e15bacbeSDan Kruchinin cpumask_var_t cbcpumask); 184e15bacbeSDan Kruchinin extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask); 185e15bacbeSDan Kruchinin extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask); 1864c879170SSteffen Klassert extern int padata_start(struct padata_instance *pinst); 18716295becSSteffen Klassert extern void padata_stop(struct padata_instance *pinst); 188e15bacbeSDan Kruchinin extern int padata_register_cpumask_notifier(struct padata_instance *pinst, 189e15bacbeSDan Kruchinin struct notifier_block *nblock); 190e15bacbeSDan Kruchinin extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst, 191e15bacbeSDan Kruchinin struct notifier_block *nblock); 19216295becSSteffen Klassert #endif 193