xref: /openbmc/linux/include/linux/padata.h (revision 0198ffd1)
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>
2816295becSSteffen Klassert 
290198ffd1SSteffen Klassert /**
300198ffd1SSteffen Klassert  * struct padata_priv -  Embedded to the users data structure.
310198ffd1SSteffen Klassert  *
320198ffd1SSteffen Klassert  * @list: List entry, to attach to the padata lists.
330198ffd1SSteffen Klassert  * @pd: Pointer to the internal control structure.
340198ffd1SSteffen Klassert  * @cb_cpu: Callback cpu for serializatioon.
350198ffd1SSteffen Klassert  * @seq_nr: Sequence number of the parallelized data object.
360198ffd1SSteffen Klassert  * @info: Used to pass information from the parallel to the serial function.
370198ffd1SSteffen Klassert  * @parallel: Parallel execution function.
380198ffd1SSteffen Klassert  * @serial: Serial complete function.
390198ffd1SSteffen Klassert  */
4016295becSSteffen Klassert struct padata_priv {
4116295becSSteffen Klassert 	struct list_head	list;
4216295becSSteffen Klassert 	struct parallel_data	*pd;
4316295becSSteffen Klassert 	int			cb_cpu;
4416295becSSteffen Klassert 	int			seq_nr;
4516295becSSteffen Klassert 	int			info;
4616295becSSteffen Klassert 	void                    (*parallel)(struct padata_priv *padata);
4716295becSSteffen Klassert 	void                    (*serial)(struct padata_priv *padata);
4816295becSSteffen Klassert };
4916295becSSteffen Klassert 
500198ffd1SSteffen Klassert /**
510198ffd1SSteffen Klassert  * struct padata_list
520198ffd1SSteffen Klassert  *
530198ffd1SSteffen Klassert  * @list: List head.
540198ffd1SSteffen Klassert  * @lock: List lock.
550198ffd1SSteffen Klassert  */
5616295becSSteffen Klassert struct padata_list {
5716295becSSteffen Klassert 	struct list_head        list;
5816295becSSteffen Klassert 	spinlock_t              lock;
5916295becSSteffen Klassert };
6016295becSSteffen Klassert 
610198ffd1SSteffen Klassert /**
620198ffd1SSteffen Klassert  * struct padata_queue - The percpu padata queues.
630198ffd1SSteffen Klassert  *
640198ffd1SSteffen Klassert  * @parallel: List to wait for parallelization.
650198ffd1SSteffen Klassert  * @reorder: List to wait for reordering after parallel processing.
660198ffd1SSteffen Klassert  * @serial: List to wait for serialization after reordering.
670198ffd1SSteffen Klassert  * @pwork: work struct for parallelization.
680198ffd1SSteffen Klassert  * @swork: work struct for serialization.
690198ffd1SSteffen Klassert  * @pd: Backpointer to the internal control structure.
700198ffd1SSteffen Klassert  * @num_obj: Number of objects that are processed by this cpu.
710198ffd1SSteffen Klassert  * @cpu_index: Index of the cpu.
720198ffd1SSteffen Klassert  */
7316295becSSteffen Klassert struct padata_queue {
7416295becSSteffen Klassert 	struct padata_list	parallel;
7516295becSSteffen Klassert 	struct padata_list	reorder;
7616295becSSteffen Klassert 	struct padata_list	serial;
7716295becSSteffen Klassert 	struct work_struct	pwork;
7816295becSSteffen Klassert 	struct work_struct	swork;
7916295becSSteffen Klassert 	struct parallel_data    *pd;
8016295becSSteffen Klassert 	atomic_t		num_obj;
8116295becSSteffen Klassert 	int			cpu_index;
8216295becSSteffen Klassert };
8316295becSSteffen Klassert 
840198ffd1SSteffen Klassert /**
850198ffd1SSteffen Klassert  * struct parallel_data - Internal control structure, covers everything
860198ffd1SSteffen Klassert  * that depends on the cpumask in use.
870198ffd1SSteffen Klassert  *
880198ffd1SSteffen Klassert  * @pinst: padata instance.
890198ffd1SSteffen Klassert  * @queue: percpu padata queues.
900198ffd1SSteffen Klassert  * @seq_nr: The sequence number that will be attached to the next object.
910198ffd1SSteffen Klassert  * @reorder_objects: Number of objects waiting in the reorder queues.
920198ffd1SSteffen Klassert  * @refcnt: Number of objects holding a reference on this parallel_data.
930198ffd1SSteffen Klassert  * @max_seq_nr:  Maximal used sequence number.
940198ffd1SSteffen Klassert  * @cpumask: cpumask in use.
950198ffd1SSteffen Klassert  * @lock: Reorder lock.
960198ffd1SSteffen Klassert  * @timer: Reorder timer.
970198ffd1SSteffen Klassert  */
9816295becSSteffen Klassert struct parallel_data {
9916295becSSteffen Klassert 	struct padata_instance	*pinst;
10016295becSSteffen Klassert 	struct padata_queue	*queue;
10116295becSSteffen Klassert 	atomic_t		seq_nr;
10216295becSSteffen Klassert 	atomic_t		reorder_objects;
10316295becSSteffen Klassert 	atomic_t                refcnt;
10416295becSSteffen Klassert 	unsigned int		max_seq_nr;
10516295becSSteffen Klassert 	cpumask_var_t		cpumask;
10616295becSSteffen Klassert 	spinlock_t              lock;
107d46a5ac7SSteffen Klassert 	struct timer_list       timer;
10816295becSSteffen Klassert };
10916295becSSteffen Klassert 
1100198ffd1SSteffen Klassert /**
1110198ffd1SSteffen Klassert  * struct padata_instance - The overall control structure.
1120198ffd1SSteffen Klassert  *
1130198ffd1SSteffen Klassert  * @cpu_notifier: cpu hotplug notifier.
1140198ffd1SSteffen Klassert  * @wq: The workqueue in use.
1150198ffd1SSteffen Klassert  * @pd: The internal control structure.
1160198ffd1SSteffen Klassert  * @cpumask: User supplied cpumask.
1170198ffd1SSteffen Klassert  * @lock: padata instance lock.
1180198ffd1SSteffen Klassert  * @flags: padata flags.
1190198ffd1SSteffen Klassert  */
12016295becSSteffen Klassert struct padata_instance {
12116295becSSteffen Klassert 	struct notifier_block   cpu_notifier;
12216295becSSteffen Klassert 	struct workqueue_struct *wq;
12316295becSSteffen Klassert 	struct parallel_data	*pd;
12416295becSSteffen Klassert 	cpumask_var_t           cpumask;
12516295becSSteffen Klassert 	struct mutex		lock;
12616295becSSteffen Klassert 	u8			flags;
12716295becSSteffen Klassert #define	PADATA_INIT		1
12816295becSSteffen Klassert #define	PADATA_RESET		2
12916295becSSteffen Klassert };
13016295becSSteffen Klassert 
13116295becSSteffen Klassert extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
13216295becSSteffen Klassert 					    struct workqueue_struct *wq);
13316295becSSteffen Klassert extern void padata_free(struct padata_instance *pinst);
13416295becSSteffen Klassert extern int padata_do_parallel(struct padata_instance *pinst,
13516295becSSteffen Klassert 			      struct padata_priv *padata, int cb_cpu);
13616295becSSteffen Klassert extern void padata_do_serial(struct padata_priv *padata);
13716295becSSteffen Klassert extern int padata_set_cpumask(struct padata_instance *pinst,
13816295becSSteffen Klassert 			      cpumask_var_t cpumask);
13916295becSSteffen Klassert extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
14016295becSSteffen Klassert extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
14116295becSSteffen Klassert extern void padata_start(struct padata_instance *pinst);
14216295becSSteffen Klassert extern void padata_stop(struct padata_instance *pinst);
14316295becSSteffen Klassert #endif
144