blob: 8844b851191e618a95343a94129effb9ded2ef8f [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>
Steffen Klassert16295be2010-01-06 19:47:10 +110028
Steffen Klassert0198ffd2010-05-19 13:44:27 +100029/**
30 * struct padata_priv - Embedded to the users data structure.
31 *
32 * @list: List entry, to attach to the padata lists.
33 * @pd: Pointer to the internal control structure.
34 * @cb_cpu: Callback cpu for serializatioon.
35 * @seq_nr: Sequence number of the parallelized data object.
36 * @info: Used to pass information from the parallel to the serial function.
37 * @parallel: Parallel execution function.
38 * @serial: Serial complete function.
39 */
Steffen Klassert16295be2010-01-06 19:47:10 +110040struct padata_priv {
41 struct list_head list;
42 struct parallel_data *pd;
43 int cb_cpu;
44 int seq_nr;
45 int info;
46 void (*parallel)(struct padata_priv *padata);
47 void (*serial)(struct padata_priv *padata);
48};
49
Steffen Klassert0198ffd2010-05-19 13:44:27 +100050/**
51 * struct padata_list
52 *
53 * @list: List head.
54 * @lock: List lock.
55 */
Steffen Klassert16295be2010-01-06 19:47:10 +110056struct padata_list {
57 struct list_head list;
58 spinlock_t lock;
59};
60
Steffen Klassert0198ffd2010-05-19 13:44:27 +100061/**
62 * struct padata_queue - The percpu padata queues.
63 *
64 * @parallel: List to wait for parallelization.
65 * @reorder: List to wait for reordering after parallel processing.
66 * @serial: List to wait for serialization after reordering.
67 * @pwork: work struct for parallelization.
68 * @swork: work struct for serialization.
69 * @pd: Backpointer to the internal control structure.
Steffen Klassert0198ffd2010-05-19 13:44:27 +100070 * @cpu_index: Index of the cpu.
71 */
Steffen Klassert16295be2010-01-06 19:47:10 +110072struct padata_queue {
73 struct padata_list parallel;
74 struct padata_list reorder;
75 struct padata_list serial;
76 struct work_struct pwork;
77 struct work_struct swork;
78 struct parallel_data *pd;
Steffen Klassert16295be2010-01-06 19:47:10 +110079 int cpu_index;
80};
81
Steffen Klassert0198ffd2010-05-19 13:44:27 +100082/**
83 * struct parallel_data - Internal control structure, covers everything
84 * that depends on the cpumask in use.
85 *
86 * @pinst: padata instance.
87 * @queue: percpu padata queues.
88 * @seq_nr: The sequence number that will be attached to the next object.
89 * @reorder_objects: Number of objects waiting in the reorder queues.
90 * @refcnt: Number of objects holding a reference on this parallel_data.
91 * @max_seq_nr: Maximal used sequence number.
92 * @cpumask: cpumask in use.
93 * @lock: Reorder lock.
Steffen Klassert5f1a8c12010-07-07 15:32:39 +020094 * @processed: Number of already processed objects.
Steffen Klassert0198ffd2010-05-19 13:44:27 +100095 * @timer: Reorder timer.
96 */
Steffen Klassert16295be2010-01-06 19:47:10 +110097struct parallel_data {
98 struct padata_instance *pinst;
99 struct padata_queue *queue;
100 atomic_t seq_nr;
101 atomic_t reorder_objects;
102 atomic_t refcnt;
103 unsigned int max_seq_nr;
104 cpumask_var_t cpumask;
Steffen Klassert5f1a8c12010-07-07 15:32:39 +0200105 spinlock_t lock ____cacheline_aligned;
106 unsigned int processed;
Steffen Klassertd46a5ac2010-05-19 13:43:14 +1000107 struct timer_list timer;
Steffen Klassert16295be2010-01-06 19:47:10 +1100108};
109
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000110/**
111 * struct padata_instance - The overall control structure.
112 *
113 * @cpu_notifier: cpu hotplug notifier.
114 * @wq: The workqueue in use.
115 * @pd: The internal control structure.
116 * @cpumask: User supplied cpumask.
117 * @lock: padata instance lock.
118 * @flags: padata flags.
119 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100120struct padata_instance {
121 struct notifier_block cpu_notifier;
122 struct workqueue_struct *wq;
123 struct parallel_data *pd;
124 cpumask_var_t cpumask;
125 struct mutex lock;
126 u8 flags;
127#define PADATA_INIT 1
128#define PADATA_RESET 2
Steffen Klassert4c879172010-07-07 15:30:10 +0200129#define PADATA_INVALID 4
Steffen Klassert16295be2010-01-06 19:47:10 +1100130};
131
132extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
133 struct workqueue_struct *wq);
134extern void padata_free(struct padata_instance *pinst);
135extern int padata_do_parallel(struct padata_instance *pinst,
136 struct padata_priv *padata, int cb_cpu);
137extern void padata_do_serial(struct padata_priv *padata);
138extern int padata_set_cpumask(struct padata_instance *pinst,
139 cpumask_var_t cpumask);
140extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
141extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
Steffen Klassert4c879172010-07-07 15:30:10 +0200142extern int padata_start(struct padata_instance *pinst);
Steffen Klassert16295be2010-01-06 19:47:10 +1100143extern void padata_stop(struct padata_instance *pinst);
144#endif