blob: 293ad46ffced54746454cd8fc42abaa375f3e2b3 [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>
Dan Kruchinin5e017dc2010-07-14 14:33:08 +040029#include <linux/kobject.h>
Dan Kruchinine15bacb2010-07-14 14:31:57 +040030
31#define PADATA_CPU_SERIAL 0x01
32#define PADATA_CPU_PARALLEL 0x02
Steffen Klassert16295be2010-01-06 19:47:10 +110033
Steffen Klassert0198ffd2010-05-19 13:44:27 +100034/**
35 * struct padata_priv - Embedded to the users data structure.
36 *
37 * @list: List entry, to attach to the padata lists.
38 * @pd: Pointer to the internal control structure.
39 * @cb_cpu: Callback cpu for serializatioon.
40 * @seq_nr: Sequence number of the parallelized data object.
41 * @info: Used to pass information from the parallel to the serial function.
42 * @parallel: Parallel execution function.
43 * @serial: Serial complete function.
44 */
Steffen Klassert16295be2010-01-06 19:47:10 +110045struct padata_priv {
46 struct list_head list;
47 struct parallel_data *pd;
48 int cb_cpu;
49 int seq_nr;
50 int info;
51 void (*parallel)(struct padata_priv *padata);
52 void (*serial)(struct padata_priv *padata);
53};
54
Steffen Klassert0198ffd2010-05-19 13:44:27 +100055/**
56 * struct padata_list
57 *
58 * @list: List head.
59 * @lock: List lock.
60 */
Steffen Klassert16295be2010-01-06 19:47:10 +110061struct padata_list {
62 struct list_head list;
63 spinlock_t lock;
64};
65
Steffen Klassert0198ffd2010-05-19 13:44:27 +100066/**
Dan Kruchinine15bacb2010-07-14 14:31:57 +040067* struct padata_serial_queue - The percpu padata serial queue
68*
69* @serial: List to wait for serialization after reordering.
70* @work: work struct for serialization.
71* @pd: Backpointer to the internal control structure.
72*/
73struct padata_serial_queue {
74 struct padata_list serial;
75 struct work_struct work;
76 struct parallel_data *pd;
77};
78
79/**
80 * struct padata_parallel_queue - The percpu padata parallel queue
Steffen Klassert0198ffd2010-05-19 13:44:27 +100081 *
82 * @parallel: List to wait for parallelization.
83 * @reorder: List to wait for reordering after parallel processing.
84 * @serial: List to wait for serialization after reordering.
85 * @pwork: work struct for parallelization.
86 * @swork: work struct for serialization.
87 * @pd: Backpointer to the internal control structure.
Dan Kruchinine15bacb2010-07-14 14:31:57 +040088 * @work: work struct for parallelization.
89 * @num_obj: Number of objects that are processed by this cpu.
Steffen Klassert0198ffd2010-05-19 13:44:27 +100090 * @cpu_index: Index of the cpu.
91 */
Dan Kruchinine15bacb2010-07-14 14:31:57 +040092struct padata_parallel_queue {
93 struct padata_list parallel;
94 struct padata_list reorder;
95 struct parallel_data *pd;
96 struct work_struct work;
97 atomic_t num_obj;
98 int cpu_index;
Steffen Klassert16295be2010-01-06 19:47:10 +110099};
100
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400101
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000102/**
103 * struct parallel_data - Internal control structure, covers everything
104 * that depends on the cpumask in use.
105 *
106 * @pinst: padata instance.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400107 * @pqueue: percpu padata queues used for parallelization.
108 * @squeue: percpu padata queues used for serialuzation.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000109 * @seq_nr: The sequence number that will be attached to the next object.
110 * @reorder_objects: Number of objects waiting in the reorder queues.
111 * @refcnt: Number of objects holding a reference on this parallel_data.
112 * @max_seq_nr: Maximal used sequence number.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400113 * @cpumask: Contains two cpumasks: pcpu and cbcpu for
114 * parallel and serial workers respectively.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000115 * @lock: Reorder lock.
Steffen Klassert5f1a8c12010-07-07 15:32:39 +0200116 * @processed: Number of already processed objects.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000117 * @timer: Reorder timer.
118 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100119struct parallel_data {
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400120 struct padata_instance *pinst;
121 struct padata_parallel_queue *pqueue;
122 struct padata_serial_queue *squeue;
123 atomic_t seq_nr;
124 atomic_t reorder_objects;
125 atomic_t refcnt;
126 unsigned int max_seq_nr;
127 struct {
128 cpumask_var_t pcpu;
129 cpumask_var_t cbcpu;
130 } cpumask;
131 spinlock_t lock ____cacheline_aligned;
132 unsigned int processed;
133 struct timer_list timer;
Steffen Klassert16295be2010-01-06 19:47:10 +1100134};
135
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000136/**
137 * struct padata_instance - The overall control structure.
138 *
139 * @cpu_notifier: cpu hotplug notifier.
140 * @wq: The workqueue in use.
141 * @pd: The internal control structure.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400142 * @cpumask: User supplied cpumask. Contains two cpumasks: pcpu and
143 * cbcpu for parallel and serial works respectivly.
144 * @cpumask_change_notifier: Notifiers chain for user-defined notify
145 * callbacks that will be called when either @pcpu or @cbcpu
Dan Kruchinin5e017dc2010-07-14 14:33:08 +0400146 * or both cpumasks change.
147 * @kobj: padata instance kernel object.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000148 * @lock: padata instance lock.
149 * @flags: padata flags.
150 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100151struct padata_instance {
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400152 struct notifier_block cpu_notifier;
153 struct workqueue_struct *wq;
154 struct parallel_data *pd;
155 struct {
156 cpumask_var_t pcpu;
157 cpumask_var_t cbcpu;
158 } cpumask;
159 struct blocking_notifier_head cpumask_change_notifier;
Dan Kruchinin5e017dc2010-07-14 14:33:08 +0400160 struct kobject kobj;
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400161 struct mutex lock;
162 u8 flags;
163#define PADATA_INIT 1
164#define PADATA_RESET 2
165#define PADATA_INVALID 4
Steffen Klassert16295be2010-01-06 19:47:10 +1100166};
167
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400168extern struct padata_instance *padata_alloc(struct workqueue_struct *wq);
169extern struct padata_instance *__padata_alloc(struct workqueue_struct *wq,
170 const struct cpumask *pcpumask,
171 const struct cpumask *cbcpumask);
Steffen Klassert16295be2010-01-06 19:47:10 +1100172extern void padata_free(struct padata_instance *pinst);
173extern int padata_do_parallel(struct padata_instance *pinst,
174 struct padata_priv *padata, int cb_cpu);
175extern void padata_do_serial(struct padata_priv *padata);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400176extern int padata_get_cpumask(struct padata_instance *pinst,
177 int cpumask_type, struct cpumask *out_mask);
178extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
Steffen Klassert16295be2010-01-06 19:47:10 +1100179 cpumask_var_t cpumask);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400180extern int __padata_set_cpumasks(struct padata_instance *pinst,
181 cpumask_var_t pcpumask,
182 cpumask_var_t cbcpumask);
183extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask);
184extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask);
Steffen Klassert4c879172010-07-07 15:30:10 +0200185extern int padata_start(struct padata_instance *pinst);
Steffen Klassert16295be2010-01-06 19:47:10 +1100186extern void padata_stop(struct padata_instance *pinst);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400187extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
188 struct notifier_block *nblock);
189extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
190 struct notifier_block *nblock);
Steffen Klassert16295be2010-01-06 19:47:10 +1100191#endif