1a61127c2SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 216295becSSteffen Klassert /* 316295becSSteffen Klassert * padata.h - header for the padata parallelization interface 416295becSSteffen Klassert * 516295becSSteffen Klassert * Copyright (C) 2008, 2009 secunet Security Networks AG 616295becSSteffen Klassert * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com> 716295becSSteffen Klassert */ 816295becSSteffen Klassert 916295becSSteffen Klassert #ifndef PADATA_H 1016295becSSteffen Klassert #define PADATA_H 1116295becSSteffen Klassert 1216295becSSteffen Klassert #include <linux/workqueue.h> 1316295becSSteffen Klassert #include <linux/spinlock.h> 1416295becSSteffen Klassert #include <linux/list.h> 15d46a5ac7SSteffen Klassert #include <linux/timer.h> 16e15bacbeSDan Kruchinin #include <linux/notifier.h> 175e017dc3SDan Kruchinin #include <linux/kobject.h> 18e15bacbeSDan Kruchinin 19e15bacbeSDan Kruchinin #define PADATA_CPU_SERIAL 0x01 20e15bacbeSDan Kruchinin #define PADATA_CPU_PARALLEL 0x02 2116295becSSteffen Klassert 220198ffd1SSteffen Klassert /** 230198ffd1SSteffen Klassert * struct padata_priv - Embedded to the users data structure. 240198ffd1SSteffen Klassert * 250198ffd1SSteffen Klassert * @list: List entry, to attach to the padata lists. 260198ffd1SSteffen Klassert * @pd: Pointer to the internal control structure. 270198ffd1SSteffen Klassert * @cb_cpu: Callback cpu for serializatioon. 28350ef88eSMathias Krause * @cpu: Cpu for parallelization. 290198ffd1SSteffen Klassert * @seq_nr: Sequence number of the parallelized data object. 300198ffd1SSteffen Klassert * @info: Used to pass information from the parallel to the serial function. 310198ffd1SSteffen Klassert * @parallel: Parallel execution function. 320198ffd1SSteffen Klassert * @serial: Serial complete function. 330198ffd1SSteffen Klassert */ 3416295becSSteffen Klassert struct padata_priv { 3516295becSSteffen Klassert struct list_head list; 3616295becSSteffen Klassert struct parallel_data *pd; 3716295becSSteffen Klassert int cb_cpu; 38350ef88eSMathias Krause int cpu; 3916295becSSteffen Klassert int info; 4016295becSSteffen Klassert void (*parallel)(struct padata_priv *padata); 4116295becSSteffen Klassert void (*serial)(struct padata_priv *padata); 4216295becSSteffen Klassert }; 4316295becSSteffen Klassert 440198ffd1SSteffen Klassert /** 450198ffd1SSteffen Klassert * struct padata_list 460198ffd1SSteffen Klassert * 470198ffd1SSteffen Klassert * @list: List head. 480198ffd1SSteffen Klassert * @lock: List lock. 490198ffd1SSteffen Klassert */ 5016295becSSteffen Klassert struct padata_list { 5116295becSSteffen Klassert struct list_head list; 5216295becSSteffen Klassert spinlock_t lock; 5316295becSSteffen Klassert }; 5416295becSSteffen Klassert 550198ffd1SSteffen Klassert /** 56e15bacbeSDan Kruchinin * struct padata_serial_queue - The percpu padata serial queue 57e15bacbeSDan Kruchinin * 58e15bacbeSDan Kruchinin * @serial: List to wait for serialization after reordering. 59e15bacbeSDan Kruchinin * @work: work struct for serialization. 60e15bacbeSDan Kruchinin * @pd: Backpointer to the internal control structure. 61e15bacbeSDan Kruchinin */ 62e15bacbeSDan Kruchinin struct padata_serial_queue { 63e15bacbeSDan Kruchinin struct padata_list serial; 64e15bacbeSDan Kruchinin struct work_struct work; 65e15bacbeSDan Kruchinin struct parallel_data *pd; 66e15bacbeSDan Kruchinin }; 67e15bacbeSDan Kruchinin 68e15bacbeSDan Kruchinin /** 69e15bacbeSDan Kruchinin * struct padata_parallel_queue - The percpu padata parallel queue 700198ffd1SSteffen Klassert * 710198ffd1SSteffen Klassert * @parallel: List to wait for parallelization. 720198ffd1SSteffen Klassert * @reorder: List to wait for reordering after parallel processing. 730198ffd1SSteffen Klassert * @serial: List to wait for serialization after reordering. 740198ffd1SSteffen Klassert * @pwork: work struct for parallelization. 750198ffd1SSteffen Klassert * @swork: work struct for serialization. 760198ffd1SSteffen Klassert * @pd: Backpointer to the internal control structure. 77e15bacbeSDan Kruchinin * @work: work struct for parallelization. 78cf5868c8SMathias Krause * @reorder_work: work struct for reordering. 79e15bacbeSDan Kruchinin * @num_obj: Number of objects that are processed by this cpu. 800198ffd1SSteffen Klassert * @cpu_index: Index of the cpu. 810198ffd1SSteffen Klassert */ 82e15bacbeSDan Kruchinin struct padata_parallel_queue { 8316295becSSteffen Klassert struct padata_list parallel; 8416295becSSteffen Klassert struct padata_list reorder; 8516295becSSteffen Klassert struct parallel_data *pd; 86e15bacbeSDan Kruchinin struct work_struct work; 87cf5868c8SMathias Krause struct work_struct reorder_work; 88e15bacbeSDan Kruchinin atomic_t num_obj; 8916295becSSteffen Klassert int cpu_index; 9016295becSSteffen Klassert }; 9116295becSSteffen Klassert 92c635696cSSteffen Klassert /** 93c635696cSSteffen Klassert * struct padata_cpumask - The cpumasks for the parallel/serial workers 94c635696cSSteffen Klassert * 95c635696cSSteffen Klassert * @pcpu: cpumask for the parallel workers. 96c635696cSSteffen Klassert * @cbcpu: cpumask for the serial (callback) workers. 97c635696cSSteffen Klassert */ 98c635696cSSteffen Klassert struct padata_cpumask { 99c635696cSSteffen Klassert cpumask_var_t pcpu; 100c635696cSSteffen Klassert cpumask_var_t cbcpu; 101c635696cSSteffen Klassert }; 102e15bacbeSDan Kruchinin 1030198ffd1SSteffen Klassert /** 1040198ffd1SSteffen Klassert * struct parallel_data - Internal control structure, covers everything 1050198ffd1SSteffen Klassert * that depends on the cpumask in use. 1060198ffd1SSteffen Klassert * 1070198ffd1SSteffen Klassert * @pinst: padata instance. 108e15bacbeSDan Kruchinin * @pqueue: percpu padata queues used for parallelization. 109e15bacbeSDan Kruchinin * @squeue: percpu padata queues used for serialuzation. 1100198ffd1SSteffen Klassert * @reorder_objects: Number of objects waiting in the reorder queues. 1110198ffd1SSteffen Klassert * @refcnt: Number of objects holding a reference on this parallel_data. 1120198ffd1SSteffen Klassert * @max_seq_nr: Maximal used sequence number. 113c635696cSSteffen Klassert * @cpumask: The cpumasks in use for parallel and serial workers. 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; 12057a2ce5fSNamhyung Kim struct padata_parallel_queue __percpu *pqueue; 12157a2ce5fSNamhyung Kim struct padata_serial_queue __percpu *squeue; 12216295becSSteffen Klassert atomic_t reorder_objects; 12316295becSSteffen Klassert atomic_t refcnt; 1240b6b098eSMathias Krause atomic_t seq_nr; 125c635696cSSteffen Klassert struct padata_cpumask cpumask; 1265f1a8c1bSSteffen Klassert spinlock_t lock ____cacheline_aligned; 1275f1a8c1bSSteffen Klassert unsigned int processed; 128d46a5ac7SSteffen Klassert struct timer_list timer; 12916295becSSteffen Klassert }; 13016295becSSteffen Klassert 1310198ffd1SSteffen Klassert /** 1320198ffd1SSteffen Klassert * struct padata_instance - The overall control structure. 1330198ffd1SSteffen Klassert * 1340198ffd1SSteffen Klassert * @cpu_notifier: cpu hotplug notifier. 1350198ffd1SSteffen Klassert * @wq: The workqueue in use. 1360198ffd1SSteffen Klassert * @pd: The internal control structure. 137c635696cSSteffen Klassert * @cpumask: User supplied cpumasks for parallel and serial works. 138e15bacbeSDan Kruchinin * @cpumask_change_notifier: Notifiers chain for user-defined notify 139e15bacbeSDan Kruchinin * callbacks that will be called when either @pcpu or @cbcpu 140e15bacbeSDan Kruchinin * or both cpumasks change. 1415e017dc3SDan Kruchinin * @kobj: padata instance kernel object. 1420198ffd1SSteffen Klassert * @lock: padata instance lock. 1430198ffd1SSteffen Klassert * @flags: padata flags. 1440198ffd1SSteffen Klassert */ 14516295becSSteffen Klassert struct padata_instance { 14630e92153SSebastian Andrzej Siewior struct hlist_node node; 14716295becSSteffen Klassert struct workqueue_struct *wq; 14816295becSSteffen Klassert struct parallel_data *pd; 149c635696cSSteffen Klassert struct padata_cpumask cpumask; 150e15bacbeSDan Kruchinin struct blocking_notifier_head cpumask_change_notifier; 1515e017dc3SDan Kruchinin struct kobject kobj; 15216295becSSteffen Klassert struct mutex lock; 15316295becSSteffen Klassert u8 flags; 15416295becSSteffen Klassert #define PADATA_INIT 1 15516295becSSteffen Klassert #define PADATA_RESET 2 1564c879170SSteffen Klassert #define PADATA_INVALID 4 15716295becSSteffen Klassert }; 15816295becSSteffen Klassert 159e6cc1170SSteffen Klassert extern struct padata_instance *padata_alloc_possible( 160e6cc1170SSteffen Klassert struct workqueue_struct *wq); 16116295becSSteffen Klassert extern void padata_free(struct padata_instance *pinst); 16216295becSSteffen Klassert extern int padata_do_parallel(struct padata_instance *pinst, 16316295becSSteffen Klassert struct padata_priv *padata, int cb_cpu); 16416295becSSteffen Klassert extern void padata_do_serial(struct padata_priv *padata); 165e15bacbeSDan Kruchinin extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type, 16616295becSSteffen Klassert cpumask_var_t cpumask); 1674c879170SSteffen Klassert extern int padata_start(struct padata_instance *pinst); 16816295becSSteffen Klassert extern void padata_stop(struct padata_instance *pinst); 169e15bacbeSDan Kruchinin extern int padata_register_cpumask_notifier(struct padata_instance *pinst, 170e15bacbeSDan Kruchinin struct notifier_block *nblock); 171e15bacbeSDan Kruchinin extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst, 172e15bacbeSDan Kruchinin struct notifier_block *nblock); 17316295becSSteffen Klassert #endif 174