blob: 621e7736690c83814b3bdbfb5884cdc8d0372ea3 [file] [log] [blame]
Steffen Klassert16295be2010-01-06 19:47:10 +11001/*
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 Klassertd46a5ac2010-05-19 13:43:14 +100027#include <linux/timer.h>
Dan Kruchinine15bacb2010-07-14 14:31:57 +040028#include <linux/notifier.h>
29
30#define PADATA_CPU_SERIAL 0x01
31#define PADATA_CPU_PARALLEL 0x02
Steffen Klassert16295be2010-01-06 19:47:10 +110032
Steffen Klassert0198ffd2010-05-19 13:44:27 +100033/**
34 * struct padata_priv - Embedded to the users data structure.
35 *
36 * @list: List entry, to attach to the padata lists.
37 * @pd: Pointer to the internal control structure.
38 * @cb_cpu: Callback cpu for serializatioon.
39 * @seq_nr: Sequence number of the parallelized data object.
40 * @info: Used to pass information from the parallel to the serial function.
41 * @parallel: Parallel execution function.
42 * @serial: Serial complete function.
43 */
Steffen Klassert16295be2010-01-06 19:47:10 +110044struct padata_priv {
45 struct list_head list;
46 struct parallel_data *pd;
47 int cb_cpu;
48 int seq_nr;
49 int info;
50 void (*parallel)(struct padata_priv *padata);
51 void (*serial)(struct padata_priv *padata);
52};
53
Steffen Klassert0198ffd2010-05-19 13:44:27 +100054/**
55 * struct padata_list
56 *
57 * @list: List head.
58 * @lock: List lock.
59 */
Steffen Klassert16295be2010-01-06 19:47:10 +110060struct padata_list {
61 struct list_head list;
62 spinlock_t lock;
63};
64
Steffen Klassert0198ffd2010-05-19 13:44:27 +100065/**
Dan Kruchinine15bacb2010-07-14 14:31:57 +040066* struct padata_serial_queue - The percpu padata serial queue
67*
68* @serial: List to wait for serialization after reordering.
69* @work: work struct for serialization.
70* @pd: Backpointer to the internal control structure.
71*/
72struct padata_serial_queue {
73 struct padata_list serial;
74 struct work_struct work;
75 struct parallel_data *pd;
76};
77
78/**
79 * struct padata_parallel_queue - The percpu padata parallel queue
Steffen Klassert0198ffd2010-05-19 13:44:27 +100080 *
81 * @parallel: List to wait for parallelization.
82 * @reorder: List to wait for reordering after parallel processing.
83 * @serial: List to wait for serialization after reordering.
84 * @pwork: work struct for parallelization.
85 * @swork: work struct for serialization.
86 * @pd: Backpointer to the internal control structure.
Dan Kruchinine15bacb2010-07-14 14:31:57 +040087 * @work: work struct for parallelization.
88 * @num_obj: Number of objects that are processed by this cpu.
Steffen Klassert0198ffd2010-05-19 13:44:27 +100089 * @cpu_index: Index of the cpu.
90 */
Dan Kruchinine15bacb2010-07-14 14:31:57 +040091struct padata_parallel_queue {
92 struct padata_list parallel;
93 struct padata_list reorder;
94 struct parallel_data *pd;
95 struct work_struct work;
96 atomic_t num_obj;
97 int cpu_index;
Steffen Klassert16295be2010-01-06 19:47:10 +110098};
99
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400100
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000101/**
102 * struct parallel_data - Internal control structure, covers everything
103 * that depends on the cpumask in use.
104 *
105 * @pinst: padata instance.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400106 * @pqueue: percpu padata queues used for parallelization.
107 * @squeue: percpu padata queues used for serialuzation.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000108 * @seq_nr: The sequence number that will be attached to the next object.
109 * @reorder_objects: Number of objects waiting in the reorder queues.
110 * @refcnt: Number of objects holding a reference on this parallel_data.
111 * @max_seq_nr: Maximal used sequence number.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400112 * @cpumask: Contains two cpumasks: pcpu and cbcpu for
113 * parallel and serial workers respectively.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000114 * @lock: Reorder lock.
Steffen Klassert5f1a8c12010-07-07 15:32:39 +0200115 * @processed: Number of already processed objects.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000116 * @timer: Reorder timer.
117 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100118struct parallel_data {
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400119 struct padata_instance *pinst;
120 struct padata_parallel_queue *pqueue;
121 struct padata_serial_queue *squeue;
122 atomic_t seq_nr;
123 atomic_t reorder_objects;
124 atomic_t refcnt;
125 unsigned int max_seq_nr;
126 struct {
127 cpumask_var_t pcpu;
128 cpumask_var_t cbcpu;
129 } cpumask;
130 spinlock_t lock ____cacheline_aligned;
131 unsigned int processed;
132 struct timer_list timer;
Steffen Klassert16295be2010-01-06 19:47:10 +1100133};
134
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000135/**
136 * struct padata_instance - The overall control structure.
137 *
138 * @cpu_notifier: cpu hotplug notifier.
139 * @wq: The workqueue in use.
140 * @pd: The internal control structure.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400141 * @cpumask: User supplied cpumask. Contains two cpumasks: pcpu and
142 * cbcpu for parallel and serial works respectivly.
143 * @cpumask_change_notifier: Notifiers chain for user-defined notify
144 * callbacks that will be called when either @pcpu or @cbcpu
145 * or both cpumasks change.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000146 * @lock: padata instance lock.
147 * @flags: padata flags.
148 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100149struct padata_instance {
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400150 struct notifier_block cpu_notifier;
151 struct workqueue_struct *wq;
152 struct parallel_data *pd;
153 struct {
154 cpumask_var_t pcpu;
155 cpumask_var_t cbcpu;
156 } cpumask;
157 struct blocking_notifier_head cpumask_change_notifier;
158 struct mutex lock;
159 u8 flags;
160#define PADATA_INIT 1
161#define PADATA_RESET 2
162#define PADATA_INVALID 4
Steffen Klassert16295be2010-01-06 19:47:10 +1100163};
164
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400165extern struct padata_instance *padata_alloc(struct workqueue_struct *wq);
166extern struct padata_instance *__padata_alloc(struct workqueue_struct *wq,
167 const struct cpumask *pcpumask,
168 const struct cpumask *cbcpumask);
Steffen Klassert16295be2010-01-06 19:47:10 +1100169extern void padata_free(struct padata_instance *pinst);
170extern int padata_do_parallel(struct padata_instance *pinst,
171 struct padata_priv *padata, int cb_cpu);
172extern void padata_do_serial(struct padata_priv *padata);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400173extern int padata_get_cpumask(struct padata_instance *pinst,
174 int cpumask_type, struct cpumask *out_mask);
175extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
Steffen Klassert16295be2010-01-06 19:47:10 +1100176 cpumask_var_t cpumask);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400177extern int __padata_set_cpumasks(struct padata_instance *pinst,
178 cpumask_var_t pcpumask,
179 cpumask_var_t cbcpumask);
180extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask);
181extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask);
Steffen Klassert4c879172010-07-07 15:30:10 +0200182extern int padata_start(struct padata_instance *pinst);
Steffen Klassert16295be2010-01-06 19:47:10 +1100183extern void padata_stop(struct padata_instance *pinst);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400184extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
185 struct notifier_block *nblock);
186extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
187 struct notifier_block *nblock);
Steffen Klassert16295be2010-01-06 19:47:10 +1100188#endif