Blame view

include/linux/padata.h 6.45 KB
16295bec6   Steffen Klassert   padata: Generic p...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  /*
   * padata.h - header for the padata parallelization interface
   *
   * Copyright (C) 2008, 2009 secunet Security Networks AG
   * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com>
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms and conditions of the GNU General Public License,
   * version 2, as published by the Free Software Foundation.
   *
   * This program is distributed in the hope it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   * more details.
   *
   * You should have received a copy of the GNU General Public License along with
   * this program; if not, write to the Free Software Foundation, Inc.,
   * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
   */
  
  #ifndef PADATA_H
  #define PADATA_H
  
  #include <linux/workqueue.h>
  #include <linux/spinlock.h>
  #include <linux/list.h>
d46a5ac7a   Steffen Klassert   padata: Use a tim...
27
  #include <linux/timer.h>
e15bacbeb   Dan Kruchinin   padata: Make two ...
28
  #include <linux/notifier.h>
5e017dc3f   Dan Kruchinin   padata: Added sys...
29
  #include <linux/kobject.h>
e15bacbeb   Dan Kruchinin   padata: Make two ...
30
31
32
  
  #define PADATA_CPU_SERIAL   0x01
  #define PADATA_CPU_PARALLEL 0x02
16295bec6   Steffen Klassert   padata: Generic p...
33

0198ffd13   Steffen Klassert   padata: Add some ...
34
35
36
37
38
39
40
41
42
43
44
  /**
   * struct padata_priv -  Embedded to the users data structure.
   *
   * @list: List entry, to attach to the padata lists.
   * @pd: Pointer to the internal control structure.
   * @cb_cpu: Callback cpu for serializatioon.
   * @seq_nr: Sequence number of the parallelized data object.
   * @info: Used to pass information from the parallel to the serial function.
   * @parallel: Parallel execution function.
   * @serial: Serial complete function.
   */
16295bec6   Steffen Klassert   padata: Generic p...
45
46
47
48
49
50
51
52
53
  struct padata_priv {
  	struct list_head	list;
  	struct parallel_data	*pd;
  	int			cb_cpu;
  	int			seq_nr;
  	int			info;
  	void                    (*parallel)(struct padata_priv *padata);
  	void                    (*serial)(struct padata_priv *padata);
  };
0198ffd13   Steffen Klassert   padata: Add some ...
54
55
56
57
58
59
  /**
   * struct padata_list
   *
   * @list: List head.
   * @lock: List lock.
   */
16295bec6   Steffen Klassert   padata: Generic p...
60
61
62
63
  struct padata_list {
  	struct list_head        list;
  	spinlock_t              lock;
  };
0198ffd13   Steffen Klassert   padata: Add some ...
64
  /**
e15bacbeb   Dan Kruchinin   padata: Make two ...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  * struct padata_serial_queue - The percpu padata serial queue
  *
  * @serial: List to wait for serialization after reordering.
  * @work: work struct for serialization.
  * @pd: Backpointer to the internal control structure.
  */
  struct padata_serial_queue {
         struct padata_list    serial;
         struct work_struct    work;
         struct parallel_data *pd;
  };
  
  /**
   * struct padata_parallel_queue - The percpu padata parallel queue
0198ffd13   Steffen Klassert   padata: Add some ...
79
80
81
82
83
84
85
   *
   * @parallel: List to wait for parallelization.
   * @reorder: List to wait for reordering after parallel processing.
   * @serial: List to wait for serialization after reordering.
   * @pwork: work struct for parallelization.
   * @swork: work struct for serialization.
   * @pd: Backpointer to the internal control structure.
e15bacbeb   Dan Kruchinin   padata: Make two ...
86
87
   * @work: work struct for parallelization.
   * @num_obj: Number of objects that are processed by this cpu.
0198ffd13   Steffen Klassert   padata: Add some ...
88
89
   * @cpu_index: Index of the cpu.
   */
e15bacbeb   Dan Kruchinin   padata: Make two ...
90
91
92
93
94
95
96
  struct padata_parallel_queue {
         struct padata_list    parallel;
         struct padata_list    reorder;
         struct parallel_data *pd;
         struct work_struct    work;
         atomic_t              num_obj;
         int                   cpu_index;
16295bec6   Steffen Klassert   padata: Generic p...
97
  };
c635696c7   Steffen Klassert   padata: Pass the ...
98
99
100
101
102
103
104
105
106
107
  /**
   * struct padata_cpumask - The cpumasks for the parallel/serial workers
   *
   * @pcpu: cpumask for the parallel workers.
   * @cbcpu: cpumask for the serial (callback) workers.
   */
  struct padata_cpumask {
  	cpumask_var_t	pcpu;
  	cpumask_var_t	cbcpu;
  };
e15bacbeb   Dan Kruchinin   padata: Make two ...
108

0198ffd13   Steffen Klassert   padata: Add some ...
109
110
111
112
113
  /**
   * struct parallel_data - Internal control structure, covers everything
   * that depends on the cpumask in use.
   *
   * @pinst: padata instance.
e15bacbeb   Dan Kruchinin   padata: Make two ...
114
115
   * @pqueue: percpu padata queues used for parallelization.
   * @squeue: percpu padata queues used for serialuzation.
0198ffd13   Steffen Klassert   padata: Add some ...
116
117
118
119
   * @seq_nr: The sequence number that will be attached to the next object.
   * @reorder_objects: Number of objects waiting in the reorder queues.
   * @refcnt: Number of objects holding a reference on this parallel_data.
   * @max_seq_nr:  Maximal used sequence number.
c635696c7   Steffen Klassert   padata: Pass the ...
120
   * @cpumask: The cpumasks in use for parallel and serial workers.
0198ffd13   Steffen Klassert   padata: Add some ...
121
   * @lock: Reorder lock.
5f1a8c1bc   Steffen Klassert   padata: simplify ...
122
   * @processed: Number of already processed objects.
0198ffd13   Steffen Klassert   padata: Add some ...
123
124
   * @timer: Reorder timer.
   */
16295bec6   Steffen Klassert   padata: Generic p...
125
  struct parallel_data {
e15bacbeb   Dan Kruchinin   padata: Make two ...
126
  	struct padata_instance		*pinst;
57a2ce5f5   Namhyung Kim   padata: add missi...
127
128
  	struct padata_parallel_queue	__percpu *pqueue;
  	struct padata_serial_queue	__percpu *squeue;
c635696c7   Steffen Klassert   padata: Pass the ...
129
130
131
132
133
134
135
136
  	atomic_t			seq_nr;
  	atomic_t			reorder_objects;
  	atomic_t			refcnt;
  	unsigned int			max_seq_nr;
  	struct padata_cpumask		cpumask;
  	spinlock_t                      lock ____cacheline_aligned;
  	unsigned int			processed;
  	struct timer_list		timer;
16295bec6   Steffen Klassert   padata: Generic p...
137
  };
0198ffd13   Steffen Klassert   padata: Add some ...
138
139
140
141
142
143
  /**
   * struct padata_instance - The overall control structure.
   *
   * @cpu_notifier: cpu hotplug notifier.
   * @wq: The workqueue in use.
   * @pd: The internal control structure.
c635696c7   Steffen Klassert   padata: Pass the ...
144
   * @cpumask: User supplied cpumasks for parallel and serial works.
e15bacbeb   Dan Kruchinin   padata: Make two ...
145
146
   * @cpumask_change_notifier: Notifiers chain for user-defined notify
   *            callbacks that will be called when either @pcpu or @cbcpu
5e017dc3f   Dan Kruchinin   padata: Added sys...
147
148
   *            or both cpumasks change.
   * @kobj: padata instance kernel object.
0198ffd13   Steffen Klassert   padata: Add some ...
149
150
151
   * @lock: padata instance lock.
   * @flags: padata flags.
   */
16295bec6   Steffen Klassert   padata: Generic p...
152
  struct padata_instance {
e15bacbeb   Dan Kruchinin   padata: Make two ...
153
154
155
  	struct notifier_block		 cpu_notifier;
  	struct workqueue_struct		*wq;
  	struct parallel_data		*pd;
c635696c7   Steffen Klassert   padata: Pass the ...
156
  	struct padata_cpumask		cpumask;
e15bacbeb   Dan Kruchinin   padata: Make two ...
157
  	struct blocking_notifier_head	 cpumask_change_notifier;
5e017dc3f   Dan Kruchinin   padata: Added sys...
158
  	struct kobject                   kobj;
e15bacbeb   Dan Kruchinin   padata: Make two ...
159
160
161
162
163
  	struct mutex			 lock;
  	u8				 flags;
  #define	PADATA_INIT	1
  #define	PADATA_RESET	2
  #define	PADATA_INVALID	4
16295bec6   Steffen Klassert   padata: Generic p...
164
  };
e6cc11707   Steffen Klassert   padata: Rename pa...
165
166
167
168
169
  extern struct padata_instance *padata_alloc_possible(
  					struct workqueue_struct *wq);
  extern struct padata_instance *padata_alloc(struct workqueue_struct *wq,
  					    const struct cpumask *pcpumask,
  					    const struct cpumask *cbcpumask);
16295bec6   Steffen Klassert   padata: Generic p...
170
171
172
173
  extern void padata_free(struct padata_instance *pinst);
  extern int padata_do_parallel(struct padata_instance *pinst,
  			      struct padata_priv *padata, int cb_cpu);
  extern void padata_do_serial(struct padata_priv *padata);
e15bacbeb   Dan Kruchinin   padata: Make two ...
174
  extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
16295bec6   Steffen Klassert   padata: Generic p...
175
  			      cpumask_var_t cpumask);
65ff577e6   Steffen Klassert   padata: Rearrange...
176
177
178
  extern int padata_set_cpumasks(struct padata_instance *pinst,
  			       cpumask_var_t pcpumask,
  			       cpumask_var_t cbcpumask);
e15bacbeb   Dan Kruchinin   padata: Make two ...
179
180
  extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask);
  extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask);
4c8791702   Steffen Klassert   padata: Check for...
181
  extern int padata_start(struct padata_instance *pinst);
16295bec6   Steffen Klassert   padata: Generic p...
182
  extern void padata_stop(struct padata_instance *pinst);
e15bacbeb   Dan Kruchinin   padata: Make two ...
183
184
185
186
  extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
  					    struct notifier_block *nblock);
  extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
  					      struct notifier_block *nblock);
16295bec6   Steffen Klassert   padata: Generic p...
187
  #endif